|
26 | 26 | use SimpleSAML\Module\oidc\Entities\UserEntity; |
27 | 27 | use SimpleSAML\Module\oidc\Factories\Entities\AccessTokenEntityFactory; |
28 | 28 | use SimpleSAML\Module\oidc\Factories\Entities\AuthCodeEntityFactory; |
| 29 | +use SimpleSAML\Module\oidc\Factories\Entities\RefreshTokenEntityFactory; |
29 | 30 | use SimpleSAML\Module\oidc\Repositories\Interfaces\AccessTokenRepositoryInterface; |
30 | 31 | use SimpleSAML\Module\oidc\Repositories\Interfaces\AuthCodeRepositoryInterface; |
31 | 32 | use SimpleSAML\Module\oidc\Repositories\Interfaces\RefreshTokenRepositoryInterface; |
|
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\Services\LoggerService; |
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,8 @@ public function __construct( |
162 | 164 | protected RequestParamsResolver $requestParamsResolver, |
163 | 165 | AccessTokenEntityFactory $accessTokenEntityFactory, |
164 | 166 | protected AuthCodeEntityFactory $authCodeEntityFactory, |
| 167 | + protected RefreshTokenEntityFactory $refreshTokenEntityFactory, |
| 168 | + protected LoggerService $logger, |
165 | 169 | ) { |
166 | 170 | parent::__construct($authCodeRepository, $refreshTokenRepository, $authCodeTTL); |
167 | 171 |
|
@@ -751,30 +755,30 @@ protected function issueRefreshToken( |
751 | 755 | throw OidcServerException::serverError('Unexpected refresh token repository entity type.'); |
752 | 756 | } |
753 | 757 |
|
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 | 758 | $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS; |
765 | 759 |
|
766 | 760 | while ($maxGenerationAttempts-- > 0) { |
767 | | - $refreshToken->setIdentifier($this->generateUniqueIdentifier()); |
768 | 761 | try { |
| 762 | + $refreshToken = $this->refreshTokenEntityFactory->fromData( |
| 763 | + $this->generateUniqueIdentifier(), |
| 764 | + (new DateTimeImmutable())->add($this->refreshTokenTTL), |
| 765 | + $accessToken, |
| 766 | + $authCodeId, |
| 767 | + ); |
769 | 768 | $this->refreshTokenRepository->persistNewRefreshToken($refreshToken); |
770 | | - break; |
| 769 | + return $refreshToken; |
771 | 770 | } catch (UniqueTokenIdentifierConstraintViolationException $e) { |
772 | 771 | if ($maxGenerationAttempts === 0) { |
773 | 772 | throw $e; |
774 | 773 | } |
775 | 774 | } |
776 | 775 | } |
777 | 776 |
|
778 | | - return $refreshToken; |
| 777 | + $this->logger->error('Unable to issue refresh token.', [ |
| 778 | + 'accessTokenId' => $accessToken->getIdentifier(), |
| 779 | + 'authCodeId' => $authCodeId, |
| 780 | + ]); |
| 781 | + |
| 782 | + return null; |
779 | 783 | } |
780 | 784 | } |
0 commit comments