diff --git a/src/AuthorizationValidators/AuthorizationValidatorInterface.php b/src/AuthorizationValidators/AuthorizationValidatorInterface.php index 7e49f8477..e4e441930 100644 --- a/src/AuthorizationValidators/AuthorizationValidatorInterface.php +++ b/src/AuthorizationValidators/AuthorizationValidatorInterface.php @@ -13,12 +13,19 @@ interface AuthorizationValidatorInterface { + /** + * Determine the access token in the authorization header and return Token object with configured claims + * + * @param ServerRequestInterface $request + * @return \Lcobucci\JWT\Token + */ + public function validateAuthorizationHeader(ServerRequestInterface $request); + /** * Determine the access token in the authorization header and append OAUth properties to the request * as attributes. * * @param ServerRequestInterface $request - * * @return ServerRequestInterface */ public function validateAuthorization(ServerRequestInterface $request); diff --git a/src/AuthorizationValidators/BearerTokenValidator.php b/src/AuthorizationValidators/BearerTokenValidator.php index 6f299ce46..0f540b0fa 100644 --- a/src/AuthorizationValidators/BearerTokenValidator.php +++ b/src/AuthorizationValidators/BearerTokenValidator.php @@ -53,7 +53,7 @@ public function setPublicKey(CryptKey $key) /** * {@inheritdoc} */ - public function validateAuthorization(ServerRequestInterface $request) + public function validateAuthorizationHeader(ServerRequestInterface $request) { if ($request->hasHeader('authorization') === false) { throw OAuthServerException::accessDenied('Missing "Authorization" header'); @@ -82,12 +82,8 @@ public function validateAuthorization(ServerRequestInterface $request) throw OAuthServerException::accessDenied('Access token has been revoked'); } - // Return the request with additional attributes - return $request - ->withAttribute('oauth_access_token_id', $token->getClaim('jti')) - ->withAttribute('oauth_client_id', $token->getClaim('aud')) - ->withAttribute('oauth_user_id', $token->getClaim('sub')) - ->withAttribute('oauth_scopes', $token->getClaim('scopes')); + // Return the token + return $token; } catch (\InvalidArgumentException $exception) { // JWT couldn't be parsed so return the request as is throw OAuthServerException::accessDenied($exception->getMessage()); @@ -96,4 +92,18 @@ public function validateAuthorization(ServerRequestInterface $request) throw OAuthServerException::accessDenied('Error while decoding to JSON'); } } + + /** + * {@inheritdoc} + */ + public function validateAuthorization(ServerRequestInterface $request) + { + $token = $this->validateAuthorizationHeader($request); + + return $request + ->withAttribute('oauth_access_token_id', $token->getClaim('jti')) + ->withAttribute('oauth_client_id', $token->getClaim('aud')) + ->withAttribute('oauth_user_id', $token->getClaim('sub')) + ->withAttribute('oauth_scopes', $token->getClaim('scopes')); + } }