Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 17 additions & 7 deletions src/AuthorizationValidators/BearerTokenValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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());
Expand All @@ -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'));
}
}