diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index a3ab8a32..daeb7849 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -201,12 +201,21 @@ class AuthCodeGrant extends AbstractAuthorizeGrant } /** - * Fetch the client_id parameter from the query string. - * - * @return string|null - * @throws OAuthServerException + * {@inheritdoc} */ - protected function getClientIdFromRequest($request) + public function canRespondToAuthorizationRequest(ServerRequestInterface $request) + { + return ( + array_key_exists('response_type', $request->getQueryParams()) + && $request->getQueryParams()['response_type'] === 'code' + && isset($request->getQueryParams()['client_id']) + ); + } + + /** + * {@inheritdoc} + */ + public function validateAuthorizationRequest(ServerRequestInterface $request) { $clientId = $this->getQueryStringParameter( 'client_id', @@ -218,28 +227,6 @@ class AuthCodeGrant extends AbstractAuthorizeGrant throw OAuthServerException::invalidRequest('client_id'); } - return $clientId; - } - - /** - * {@inheritdoc} - */ - public function canRespondToAuthorizationRequest(ServerRequestInterface $request) - { - return ( - array_key_exists('response_type', $request->getQueryParams()) - && $request->getQueryParams()['response_type'] === 'code' - && $this->getClientIdFromRequest($request) !== null - ); - } - - /** - * {@inheritdoc} - */ - public function validateAuthorizationRequest(ServerRequestInterface $request) - { - $clientId = $this->getClientIdFromRequest($request); - $client = $this->clientRepository->getClientEntity( $clientId, $this->getIdentifier(), @@ -253,6 +240,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant } $redirectUri = $this->getQueryStringParameter('redirect_uri', $request); + if ($redirectUri !== null) { if ( is_string($client->getRedirectUri()) @@ -298,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', 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); } /**