|
27 | 27 | use SimpleSAML\Module\oidc\Entities\UserEntity; |
28 | 28 | use SimpleSAML\Module\oidc\Factories\Entities\AccessTokenEntityFactory; |
29 | 29 | use SimpleSAML\Module\oidc\Factories\Entities\AuthCodeEntityFactory; |
30 | | -use SimpleSAML\Module\oidc\Factories\Entities\RefreshTokenEntityFactory; |
31 | 30 | use SimpleSAML\Module\oidc\Repositories\Interfaces\AccessTokenRepositoryInterface; |
32 | 31 | use SimpleSAML\Module\oidc\Repositories\Interfaces\AuthCodeRepositoryInterface; |
33 | 32 | use SimpleSAML\Module\oidc\Repositories\Interfaces\RefreshTokenRepositoryInterface; |
|
58 | 57 | use SimpleSAML\Module\oidc\Server\ResponseTypes\Interfaces\AuthTimeResponseTypeInterface; |
59 | 58 | use SimpleSAML\Module\oidc\Server\ResponseTypes\Interfaces\NonceResponseTypeInterface; |
60 | 59 | use SimpleSAML\Module\oidc\Server\ResponseTypes\Interfaces\SessionIdResponseTypeInterface; |
61 | | -use SimpleSAML\Module\oidc\Services\LoggerService; |
| 60 | +use SimpleSAML\Module\oidc\Server\TokenIssuers\RefreshTokenIssuer; |
62 | 61 | use SimpleSAML\Module\oidc\Utils\Arr; |
63 | 62 | use SimpleSAML\Module\oidc\Utils\RequestParamsResolver; |
64 | 63 | use SimpleSAML\Module\oidc\Utils\ScopeHelper; |
@@ -165,8 +164,7 @@ public function __construct( |
165 | 164 | protected RequestParamsResolver $requestParamsResolver, |
166 | 165 | AccessTokenEntityFactory $accessTokenEntityFactory, |
167 | 166 | protected AuthCodeEntityFactory $authCodeEntityFactory, |
168 | | - protected RefreshTokenEntityFactory $refreshTokenEntityFactory, |
169 | | - protected LoggerService $logger, |
| 167 | + protected RefreshTokenIssuer $refreshTokenIssuer, |
170 | 168 | ) { |
171 | 169 | parent::__construct($authCodeRepository, $refreshTokenRepository, $authCodeTTL); |
172 | 170 |
|
@@ -752,37 +750,15 @@ protected function issueRefreshToken( |
752 | 750 | OAuth2AccessTokenEntityInterface $accessToken, |
753 | 751 | string $authCodeId = null, |
754 | 752 | ): ?RefreshTokenEntityInterface { |
755 | | - if (! is_a($this->refreshTokenRepository, RefreshTokenRepositoryInterface::class)) { |
756 | | - throw OidcServerException::serverError('Unexpected refresh token repository entity type.'); |
757 | | - } |
758 | 753 | if (! is_a($accessToken, AccessTokenEntityInterface::class)) { |
759 | 754 | throw OidcServerException::serverError('Unexpected access token entity type.'); |
760 | 755 | } |
761 | 756 |
|
762 | | - $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS; |
763 | | - |
764 | | - while ($maxGenerationAttempts-- > 0) { |
765 | | - try { |
766 | | - $refreshToken = $this->refreshTokenEntityFactory->fromData( |
767 | | - $this->generateUniqueIdentifier(), |
768 | | - (new DateTimeImmutable())->add($this->refreshTokenTTL), |
769 | | - $accessToken, |
770 | | - $authCodeId, |
771 | | - ); |
772 | | - $this->refreshTokenRepository->persistNewRefreshToken($refreshToken); |
773 | | - return $refreshToken; |
774 | | - } catch (UniqueTokenIdentifierConstraintViolationException $e) { |
775 | | - if ($maxGenerationAttempts === 0) { |
776 | | - throw $e; |
777 | | - } |
778 | | - } |
779 | | - } |
780 | | - |
781 | | - $this->logger->error('Unable to issue refresh token.', [ |
782 | | - 'accessTokenId' => $accessToken->getIdentifier(), |
783 | | - 'authCodeId' => $authCodeId, |
784 | | - ]); |
785 | | - |
786 | | - return null; |
| 757 | + return $this->refreshTokenIssuer->issue( |
| 758 | + $accessToken, |
| 759 | + $this->refreshTokenTTL, |
| 760 | + $authCodeId, |
| 761 | + self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS, |
| 762 | + ); |
787 | 763 | } |
788 | 764 | } |
0 commit comments