|
21 | 21 | use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface; |
22 | 22 | use LogicException; |
23 | 23 | use Psr\Http\Message\ServerRequestInterface; |
| 24 | +use SimpleSAML\Module\oidc\Entities\Interfaces\AccessTokenEntityInterface; |
24 | 25 | use SimpleSAML\Module\oidc\Entities\Interfaces\AuthCodeEntityInterface; |
25 | 26 | use SimpleSAML\Module\oidc\Entities\Interfaces\RefreshTokenEntityInterface; |
26 | 27 | use SimpleSAML\Module\oidc\Entities\UserEntity; |
|
56 | 57 | use SimpleSAML\Module\oidc\Server\ResponseTypes\Interfaces\AuthTimeResponseTypeInterface; |
57 | 58 | use SimpleSAML\Module\oidc\Server\ResponseTypes\Interfaces\NonceResponseTypeInterface; |
58 | 59 | use SimpleSAML\Module\oidc\Server\ResponseTypes\Interfaces\SessionIdResponseTypeInterface; |
| 60 | +use SimpleSAML\Module\oidc\Server\TokenIssuers\RefreshTokenIssuer; |
59 | 61 | use SimpleSAML\Module\oidc\Utils\Arr; |
60 | 62 | use SimpleSAML\Module\oidc\Utils\RequestParamsResolver; |
61 | 63 | use SimpleSAML\Module\oidc\Utils\ScopeHelper; |
@@ -162,6 +164,7 @@ public function __construct( |
162 | 164 | protected RequestParamsResolver $requestParamsResolver, |
163 | 165 | AccessTokenEntityFactory $accessTokenEntityFactory, |
164 | 166 | protected AuthCodeEntityFactory $authCodeEntityFactory, |
| 167 | + protected RefreshTokenIssuer $refreshTokenIssuer, |
165 | 168 | ) { |
166 | 169 | parent::__construct($authCodeRepository, $refreshTokenRepository, $authCodeTTL); |
167 | 170 |
|
@@ -747,34 +750,15 @@ protected function issueRefreshToken( |
747 | 750 | OAuth2AccessTokenEntityInterface $accessToken, |
748 | 751 | string $authCodeId = null, |
749 | 752 | ): ?RefreshTokenEntityInterface { |
750 | | - if (! is_a($this->refreshTokenRepository, RefreshTokenRepositoryInterface::class)) { |
751 | | - throw OidcServerException::serverError('Unexpected refresh token repository entity type.'); |
752 | | - } |
753 | | - |
754 | | - $refreshToken = $this->refreshTokenRepository->getNewRefreshToken(); |
755 | | - |
756 | | - if ($refreshToken === null) { |
757 | | - return null; |
758 | | - } |
759 | | - |
760 | | - $refreshToken->setExpiryDateTime((new DateTimeImmutable())->add($this->refreshTokenTTL)); |
761 | | - $refreshToken->setAccessToken($accessToken); |
762 | | - $refreshToken->setAuthCodeId($authCodeId); |
763 | | - |
764 | | - $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS; |
765 | | - |
766 | | - while ($maxGenerationAttempts-- > 0) { |
767 | | - $refreshToken->setIdentifier($this->generateUniqueIdentifier()); |
768 | | - try { |
769 | | - $this->refreshTokenRepository->persistNewRefreshToken($refreshToken); |
770 | | - break; |
771 | | - } catch (UniqueTokenIdentifierConstraintViolationException $e) { |
772 | | - if ($maxGenerationAttempts === 0) { |
773 | | - throw $e; |
774 | | - } |
775 | | - } |
| 753 | + if (! is_a($accessToken, AccessTokenEntityInterface::class)) { |
| 754 | + throw OidcServerException::serverError('Unexpected access token entity type.'); |
776 | 755 | } |
777 | 756 |
|
778 | | - return $refreshToken; |
| 757 | + return $this->refreshTokenIssuer->issue( |
| 758 | + $accessToken, |
| 759 | + $this->refreshTokenTTL, |
| 760 | + $authCodeId, |
| 761 | + self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS, |
| 762 | + ); |
779 | 763 | } |
780 | 764 | } |
0 commit comments