Skip to content

Commit

Permalink
Fixed #12 - Bug when $_GET['user'] or $_POST['user'] is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbussmann committed Jul 14, 2020
1 parent daa9d05 commit 413d7dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Provider/Apple.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function getAuthorizationParameters(array $options)
protected function fetchResourceOwnerDetails(AccessToken $token)
{
return json_decode(array_key_exists('user', $_GET) ? $_GET['user']
: (array_key_exists('user', $_POST) ? $_POST['user'] : '[]'), true);
: (array_key_exists('user', $_POST) ? $_POST['user'] : '[]'), true) ?: [];
}

/**
Expand Down
17 changes: 16 additions & 1 deletion test/src/Provider/AppleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function testGetAccessToken()
]);
}

public function testFechtingOwnerDetails()
public function testFetchingOwnerDetails()
{
$class = new \ReflectionClass($this->provider);
$method = $class->getMethod('fetchResourceOwnerDetails');
Expand All @@ -186,6 +186,21 @@ public function testFechtingOwnerDetails()
$this->assertEquals($arr, $data);
}

/**
* @see https://github.com/patrickbussmann/oauth2-apple/issues/12
*/
public function testFetchingOwnerDetailsIssue12()
{
$class = new \ReflectionClass($this->provider);
$method = $class->getMethod('fetchResourceOwnerDetails');
$method->setAccessible(true);

$_POST['user'] = '';
$data = $method->invokeArgs($this->provider, [new AccessToken(['access_token' => 'hello'])]);

$this->assertEquals([], $data);
}

/**
* @expectedException Exception
*/
Expand Down

0 comments on commit 413d7dd

Please sign in to comment.