From 413d7dd2ea62e22be688789032680d198e6bcd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Bu=C3=9Fmann?= Date: Wed, 15 Jul 2020 01:39:36 +0200 Subject: [PATCH] Fixed #12 - Bug when $_GET['user'] or $_POST['user'] is empty --- src/Provider/Apple.php | 2 +- test/src/Provider/AppleTest.php | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) 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 */