Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable better extensibility of this library #924

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions src/Grant/AuthCodeGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
{
}
}
5 changes: 2 additions & 3 deletions src/ResponseTypes/BearerTokenResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down