diff --git a/src/AuthorizationValidators/BearerTokenValidator.php b/src/AuthorizationValidators/BearerTokenValidator.php index 0442dd48e..a28b9e729 100644 --- a/src/AuthorizationValidators/BearerTokenValidator.php +++ b/src/AuthorizationValidators/BearerTokenValidator.php @@ -83,6 +83,14 @@ private function initJwtConfiguration(): void ); } + /** + * Configure the validated authorization request instance. + */ + protected function withValidatedRequest(ServerRequestInterface $request, UnencryptedToken $token): ServerRequestInterface + { + return $request; + } + /** * {@inheritdoc} */ @@ -126,10 +134,10 @@ public function validateAuthorization(ServerRequestInterface $request): ServerRe } // Return the request with additional attributes - return $request + return $this->withValidatedRequest($request ->withAttribute('oauth_access_token_id', $claims->get('jti')) ->withAttribute('oauth_client_id', $claims->get('aud')[0]) ->withAttribute('oauth_user_id', $claims->get('sub')) - ->withAttribute('oauth_scopes', $claims->get('scopes')); + ->withAttribute('oauth_scopes', $claims->get('scopes')), $token); } } diff --git a/src/Entities/Traits/AccessTokenTrait.php b/src/Entities/Traits/AccessTokenTrait.php index 6b1387b5f..6dab9b33e 100644 --- a/src/Entities/Traits/AccessTokenTrait.php +++ b/src/Entities/Traits/AccessTokenTrait.php @@ -13,6 +13,7 @@ namespace League\OAuth2\Server\Entities\Traits; use DateTimeImmutable; +use Lcobucci\JWT\Builder; use Lcobucci\JWT\Configuration; use Lcobucci\JWT\Signer\Key\InMemory; use Lcobucci\JWT\Signer\Rsa\Sha256; @@ -54,6 +55,14 @@ public function initJwtConfiguration(): void ); } + /** + * Configure the JWT builder instance. + */ + protected function withJwtBuilder(Builder $builder): Builder + { + return $builder; + } + /** * Generate a JWT from the access token */ @@ -61,14 +70,14 @@ private function convertToJWT(): Token { $this->initJwtConfiguration(); - return $this->jwtConfiguration->builder() + return $this->withJwtBuilder($this->jwtConfiguration->builder() ->permittedFor($this->getClient()->getIdentifier()) ->identifiedBy($this->getIdentifier()) ->issuedAt(new DateTimeImmutable()) ->canOnlyBeUsedAfter(new DateTimeImmutable()) ->expiresAt($this->getExpiryDateTime()) ->relatedTo($this->getSubjectIdentifier()) - ->withClaim('scopes', $this->getScopes()) + ->withClaim('scopes', $this->getScopes())) ->getToken($this->jwtConfiguration->signer(), $this->jwtConfiguration->signingKey()); }