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

Add previous authorized token information to getNewToken() #1109

Open
wants to merge 1 commit into
base: 9.0.0-WIP
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
2 changes: 1 addition & 1 deletion examples/src/Repositories/AccessTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function isAccessTokenRevoked($tokenId)
/**
* {@inheritdoc}
*/
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null, $authorizedAuthCodeIdentifier = null, $authorizedAccessTokenIdentifier = null)
{
$accessToken = new AccessTokenEntity();
$accessToken->setClient($clientEntity);
Expand Down
8 changes: 6 additions & 2 deletions src/Grant/AbstractGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ protected function getServerParameter($parameter, ServerRequestInterface $reques
* @param ClientEntityInterface $client
* @param string|null $userIdentifier
* @param ScopeEntityInterface[] $scopes
* @param string|null $authorizedAuthCodeIdentifier
* @param string|null $authorizedAccessTokenIdentifier
*
* @throws OAuthServerException
* @throws UniqueTokenIdentifierConstraintViolationException
Expand All @@ -428,11 +430,13 @@ protected function issueAccessToken(
DateInterval $accessTokenTTL,
ClientEntityInterface $client,
$userIdentifier,
array $scopes = []
array $scopes = [],
$authorizedAuthCodeIdentifier = null,
$authorizedAccessTokenIdentifier = null
) {
$maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS;

$accessToken = $this->accessTokenRepository->getNewToken($client, $scopes, $userIdentifier);
$accessToken = $this->accessTokenRepository->getNewToken($client, $scopes, $userIdentifier, $authorizedAuthCodeIdentifier, $authorizedAccessTokenIdentifier);
$accessToken->setExpiryDateTime((new DateTimeImmutable())->add($accessTokenTTL));
$accessToken->setPrivateKey($this->privateKey);

Expand Down
2 changes: 1 addition & 1 deletion src/Grant/AuthCodeGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function respondToAccessTokenRequest(
}

// Issue and persist new access token
$accessToken = $this->issueAccessToken($accessTokenTTL, $client, $authCodePayload->user_id, $scopes);
$accessToken = $this->issueAccessToken($accessTokenTTL, $client, $authCodePayload->user_id, $scopes, $authCodePayload->auth_code_id);
$this->getEmitter()->emit(new RequestEvent(RequestEvent::ACCESS_TOKEN_ISSUED, $request));
$responseType->setAccessToken($accessToken);

Expand Down
9 changes: 8 additions & 1 deletion src/Grant/RefreshTokenGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ public function respondToAccessTokenRequest(
$this->refreshTokenRepository->revokeRefreshToken($oldRefreshToken['refresh_token_id']);

// Issue and persist new access token
$accessToken = $this->issueAccessToken($accessTokenTTL, $client, $oldRefreshToken['user_id'], $scopes);
$accessToken = $this->issueAccessToken(
$accessTokenTTL,
$client,
$oldRefreshToken['user_id'],
$scopes,
null,
$oldRefreshToken['access_token_id']
);
$this->getEmitter()->emit(new RequestEvent(RequestEvent::ACCESS_TOKEN_ISSUED, $request));
$responseType->setAccessToken($accessToken);

Expand Down
6 changes: 4 additions & 2 deletions src/Repositories/AccessTokenRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ interface AccessTokenRepositoryInterface extends RepositoryInterface
*
* @param ClientEntityInterface $clientEntity
* @param ScopeEntityInterface[] $scopes
* @param mixed $userIdentifier
* @param string|null $userIdentifier
* @param string|null $authorizedAuthCodeIdentifier
* @param string|null $authorizedAccessTokenIdentifier
*
* @return AccessTokenEntityInterface
*/
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null);
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null, $authorizedAuthCodeIdentifier = null, $authorizedAccessTokenIdentifier = null);

/**
* Persists a new access token to permanent storage.
Expand Down