diff --git a/src/Provider/Apple.php b/src/Provider/Apple.php index 02b2254..99663bd 100644 --- a/src/Provider/Apple.php +++ b/src/Provider/Apple.php @@ -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) ?: []; } /** diff --git a/test/src/Provider/AppleTest.php b/test/src/Provider/AppleTest.php index 1f25f61..5d6732d 100644 --- a/test/src/Provider/AppleTest.php +++ b/test/src/Provider/AppleTest.php @@ -171,7 +171,7 @@ public function testGetAccessToken() ]); } - public function testFechtingOwnerDetails() + public function testFetchingOwnerDetails() { $class = new \ReflectionClass($this->provider); $method = $class->getMethod('fetchResourceOwnerDetails'); @@ -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 */