From c8b44ff5c74dd1c6a3c4f8ddab6e84f7484beed4 Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Fri, 20 Apr 2018 18:22:07 +0100 Subject: [PATCH 1/3] Revert fix for client ID exception --- src/Grant/AuthCodeGrant.php | 32 +++++++++---------------------- tests/Grant/AuthCodeGrantTest.php | 2 +- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index a3ab8a32..20d5041b 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -200,27 +200,6 @@ class AuthCodeGrant extends AbstractAuthorizeGrant return 'authorization_code'; } - /** - * Fetch the client_id parameter from the query string. - * - * @return string|null - * @throws OAuthServerException - */ - protected function getClientIdFromRequest($request) - { - $clientId = $this->getQueryStringParameter( - 'client_id', - $request, - $this->getServerParameter('PHP_AUTH_USER', $request) - ); - - if (is_null($clientId)) { - throw OAuthServerException::invalidRequest('client_id'); - } - - return $clientId; - } - /** * {@inheritdoc} */ @@ -229,7 +208,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant return ( array_key_exists('response_type', $request->getQueryParams()) && $request->getQueryParams()['response_type'] === 'code' - && $this->getClientIdFromRequest($request) !== null + && isset($request->getQueryParams()['client_id']) ); } @@ -238,7 +217,14 @@ class AuthCodeGrant extends AbstractAuthorizeGrant */ public function validateAuthorizationRequest(ServerRequestInterface $request) { - $clientId = $this->getClientIdFromRequest($request); + $clientId = $this->getQueryStringParameter( + 'client_id', + $request, + $this->getServerParameter('PHP_AUTH_USER', $request) + ); + if (is_null($clientId)) { + throw OAuthServerException::invalidRequest('client_id'); + } $client = $this->clientRepository->getClientEntity( $clientId, diff --git a/tests/Grant/AuthCodeGrantTest.php b/tests/Grant/AuthCodeGrantTest.php index e23bb06b..6a319234 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -335,7 +335,7 @@ class AuthCodeGrantTest extends TestCase ] ); - $grant->canRespondToAuthorizationRequest($request); + $grant->validateAuthorizationRequest($request); } /** From 9febc32e14b9ad868de5c30de7a03ed0368f3d55 Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Fri, 20 Apr 2018 18:27:47 +0100 Subject: [PATCH 2/3] Add spacing around logical blocks --- src/Grant/AuthCodeGrant.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index 20d5041b..2f33a97c 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -222,6 +222,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant $request, $this->getServerParameter('PHP_AUTH_USER', $request) ); + if (is_null($clientId)) { throw OAuthServerException::invalidRequest('client_id'); } @@ -239,6 +240,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant } $redirectUri = $this->getQueryStringParameter('redirect_uri', $request); + if ($redirectUri !== null) { if ( is_string($client->getRedirectUri()) @@ -284,6 +286,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant } $codeChallengeMethod = $this->getQueryStringParameter('code_challenge_method', $request, 'plain'); + if (in_array($codeChallengeMethod, ['plain', 'S256'], true) === false) { throw OAuthServerException::invalidRequest( 'code_challenge_method', From 6991777ff3ba4e4a0e6c1f5fe2f18277700dbcdd Mon Sep 17 00:00:00 2001 From: Andrew Millington Date: Fri, 20 Apr 2018 18:33:46 +0100 Subject: [PATCH 3/3] Fix blank line spacing issue --- src/Grant/AuthCodeGrant.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index 2f33a97c..daeb7849 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -286,7 +286,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant } $codeChallengeMethod = $this->getQueryStringParameter('code_challenge_method', $request, 'plain'); - + if (in_array($codeChallengeMethod, ['plain', 'S256'], true) === false) { throw OAuthServerException::invalidRequest( 'code_challenge_method',