diff --git a/classes/Repository/AbstractTokenRepository.php b/classes/Repository/AbstractTokenRepository.php index 2d87e4ca3..5889e1753 100644 --- a/classes/Repository/AbstractTokenRepository.php +++ b/classes/Repository/AbstractTokenRepository.php @@ -51,6 +51,11 @@ abstract class AbstractTokenRepository */ protected $tokenType; + /** + * @var array + */ + protected $refreshTokenErrors = []; + /** * AbstractTokenRepository constructor. * @@ -106,18 +111,26 @@ abstract public function updateCredentials($idToken, $refreshToken); */ public function getOrRefreshToken($forceRefresh = false) { + $refreshToken = $this->getRefreshToken(); + + if (!is_string($refreshToken) || '' === $refreshToken) { + return $this->getToken(); + } + + if ($this->getRefreshTokenErrors($refreshToken)) { + return $this->getToken(); + } + if (true === $forceRefresh || $this->isTokenExpired()) { - $refreshToken = $this->getRefreshToken(); - if (is_string($refreshToken) && '' != $refreshToken) { - try { - $token = $this->refreshToken($refreshToken, $newRefreshToken); - $this->updateCredentials( - (string) $token, - $newRefreshToken - ); - } catch (RefreshTokenException $e) { - Logger::getInstance()->debug($e); - } + try { + $token = $this->refreshToken($refreshToken, $newRefreshToken); + $this->updateCredentials( + (string) $token, + $newRefreshToken + ); + } catch (RefreshTokenException $e) { + $this->setRefreshTokenErrors($refreshToken); + Logger::getInstance()->debug($e); } } @@ -246,4 +259,24 @@ protected function onMaxRefreshTokenAttempts() $service->resetLinkAccount(); $this->configuration->updateShopUnlinkedAuto(true); } + + /** + * @param string $refreshToken + * + * @return bool + */ + protected function getRefreshTokenErrors($refreshToken) + { + return isset($this->refreshTokenErrors[$refreshToken]) && $this->refreshTokenErrors[$refreshToken]; + } + + /** + * @param string $refreshToken + * + * @return void + */ + protected function setRefreshTokenErrors($refreshToken) + { + $this->refreshTokenErrors[$refreshToken] = true; + } }