From 5be70177bb05cadc6414ecfad15a29acc7800b78 Mon Sep 17 00:00:00 2001 From: Christiaan Goossens Date: Fri, 13 Jul 2018 11:57:14 +0200 Subject: [PATCH 1/5] Add method for adding extra authcode params --- src/Grant/AuthCodeGrant.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index cfa8309bd..01124a2e8 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -172,6 +172,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 +341,8 @@ public function completeAuthorizationRequest(AuthorizationRequest $authorization 'code_challenge_method' => $authorizationRequest->getCodeChallengeMethod(), ]; + $payload = array_merge($this->getExtraAuthCodeParams($authorizationRequest), $payload); + $response = new RedirectResponse(); $response->setRedirectUri( $this->makeRedirectUri( @@ -367,4 +372,26 @@ 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 + * + * @return array + */ + protected function getExtraAuthCodeParams(AuthorizationRequest $authorizationRequest) + { + return []; + } + + /** + * Handle the extra params specified in getExtraAuthCodeParams + * + * @param object $authCodePayload + */ + protected function handleExtraAuthCodeParams(object $authCodePayload) + { + } } From 828816c7a31181ee8ad07fab20ecb33de72f84aa Mon Sep 17 00:00:00 2001 From: Christiaan Goossens Date: Fri, 13 Jul 2018 12:09:15 +0200 Subject: [PATCH 2/5] Fixed documentation for BearerTokenResponse line 66 --- src/ResponseTypes/BearerTokenResponse.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 * From a77c7860b160fd66769b9b5be00795ce0b6e8998 Mon Sep 17 00:00:00 2001 From: Christiaan Goossens Date: Fri, 13 Jul 2018 12:36:45 +0200 Subject: [PATCH 3/5] Fix typo --- src/Grant/AuthCodeGrant.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index 01124a2e8..577e2ac30 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -391,7 +391,7 @@ protected function getExtraAuthCodeParams(AuthorizationRequest $authorizationReq * * @param object $authCodePayload */ - protected function handleExtraAuthCodeParams(object $authCodePayload) + protected function handleExtraAuthCodeParams($authCodePayload) { } } From 7937e9cc26706aadb2fef9ff028f84f94309fd1f Mon Sep 17 00:00:00 2001 From: Christiaan Goossens Date: Fri, 13 Jul 2018 14:02:23 +0200 Subject: [PATCH 4/5] Also pass authCode --- src/Grant/AuthCodeGrant.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index 577e2ac30..bb2e3da47 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -12,6 +12,7 @@ use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; use League\OAuth2\Server\Entities\UserEntityInterface; +use League\OAuth2\Server\Entities\AuthCodeEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; @@ -341,7 +342,7 @@ public function completeAuthorizationRequest(AuthorizationRequest $authorization 'code_challenge_method' => $authorizationRequest->getCodeChallengeMethod(), ]; - $payload = array_merge($this->getExtraAuthCodeParams($authorizationRequest), $payload); + $payload = array_merge($this->getExtraAuthCodeParams($authorizationRequest, $authCode), $payload); $response = new RedirectResponse(); $response->setRedirectUri( @@ -378,10 +379,11 @@ public function completeAuthorizationRequest(AuthorizationRequest $authorization * for when you are issuing the token at the token endpoint * * @param AuthorizationRequest $authorizationRequest + * @param AuthCodeEntityInterface $authCode * * @return array */ - protected function getExtraAuthCodeParams(AuthorizationRequest $authorizationRequest) + protected function getExtraAuthCodeParams(AuthorizationRequest $authorizationRequest, AuthCodeEntityInterface $authCode) { return []; } From d3a9478da6424dd503f16f957050539f4691eb9c Mon Sep 17 00:00:00 2001 From: Christiaan Goossens Date: Fri, 13 Jul 2018 14:54:59 +0200 Subject: [PATCH 5/5] Fix code style --- src/Grant/AuthCodeGrant.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index bb2e3da47..b0d855f52 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -9,10 +9,10 @@ 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; -use League\OAuth2\Server\Entities\AuthCodeEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface; use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; @@ -378,7 +378,7 @@ 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 AuthorizationRequest $authorizationRequest * @param AuthCodeEntityInterface $authCode * * @return array