diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index cfa8309bd..b0d855f52 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -9,6 +9,7 @@ namespace League\OAuth2\Server\Grant; +use League\OAuth2\Server\Entities\AuthCodeEntityInterface; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; use League\OAuth2\Server\Entities\UserEntityInterface; @@ -172,6 +173,9 @@ public function respondToAccessTokenRequest( } } + // Handle extra authorization code parameters + $this->handleExtraAuthCodeParams($authCodePayload); + // Issue and persist access + refresh tokens $accessToken = $this->issueAccessToken($accessTokenTTL, $client, $authCodePayload->user_id, $scopes); $refreshToken = $this->issueRefreshToken($accessToken); @@ -338,6 +342,8 @@ public function completeAuthorizationRequest(AuthorizationRequest $authorization 'code_challenge_method' => $authorizationRequest->getCodeChallengeMethod(), ]; + $payload = array_merge($this->getExtraAuthCodeParams($authorizationRequest, $authCode), $payload); + $response = new RedirectResponse(); $response->setRedirectUri( $this->makeRedirectUri( @@ -367,4 +373,27 @@ public function completeAuthorizationRequest(AuthorizationRequest $authorization ) ); } + + /** + * Add custom fields to your authorization code to save some data from the previous (authorize) state + * for when you are issuing the token at the token endpoint + * + * @param AuthorizationRequest $authorizationRequest + * @param AuthCodeEntityInterface $authCode + * + * @return array + */ + protected function getExtraAuthCodeParams(AuthorizationRequest $authorizationRequest, AuthCodeEntityInterface $authCode) + { + return []; + } + + /** + * Handle the extra params specified in getExtraAuthCodeParams + * + * @param object $authCodePayload + */ + protected function handleExtraAuthCodeParams($authCodePayload) + { + } } diff --git a/src/ResponseTypes/BearerTokenResponse.php b/src/ResponseTypes/BearerTokenResponse.php index a57573a05..e73b7c27a 100644 --- a/src/ResponseTypes/BearerTokenResponse.php +++ b/src/ResponseTypes/BearerTokenResponse.php @@ -63,9 +63,8 @@ public function generateHttpResponse(ResponseInterface $response) } /** - * Add custom fields to your Bearer Token response here, then override - * AuthorizationServer::getResponseType() to pull in your version of - * this class rather than the default. + * Add custom fields to your Bearer Token response here, then pass an instance + * of your version of this class into the last parameter of the AuthorizationServer. * * @param AccessTokenEntityInterface $accessToken *