diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index d1669b2f..c7c7e8c9 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -196,6 +196,27 @@ class AuthCodeGrant extends AbstractAuthorizeGrant return 'authorization_code'; } + /** + * Fetch the client_id parameter from the query string. + * + * @return string + * @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} */ @@ -204,7 +225,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant return ( array_key_exists('response_type', $request->getQueryParams()) && $request->getQueryParams()['response_type'] === 'code' - && isset($request->getQueryParams()['client_id']) + && null !== $this->getClientIdFromRequest($request) ); } @@ -213,14 +234,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant */ public function validateAuthorizationRequest(ServerRequestInterface $request) { - $clientId = $this->getQueryStringParameter( - 'client_id', - $request, - $this->getServerParameter('PHP_AUTH_USER', $request) - ); - if (is_null($clientId)) { - throw OAuthServerException::invalidRequest('client_id'); - } + $clientId = $this->getClientIdFromRequest($request); $client = $this->clientRepository->getClientEntity( $clientId, diff --git a/tests/Grant/AuthCodeGrantTest.php b/tests/Grant/AuthCodeGrantTest.php index 6a319234..e23bb06b 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -335,7 +335,7 @@ class AuthCodeGrantTest extends TestCase ] ); - $grant->validateAuthorizationRequest($request); + $grant->canRespondToAuthorizationRequest($request); } /**