diff --git a/Model/AbstractRefreshToken.php b/Model/AbstractRefreshToken.php index ee3d5a8f..5cfa3d4d 100644 --- a/Model/AbstractRefreshToken.php +++ b/Model/AbstractRefreshToken.php @@ -41,7 +41,13 @@ abstract class AbstractRefreshToken implements RefreshTokenInterface public static function createForUserWithTtl(string $refreshToken, UserInterface $user, int $ttl): RefreshTokenInterface { $valid = new \DateTime(); - $valid->modify('+'.$ttl.' seconds'); + + // Explicitly check for a negative number based on a behavior change in PHP 8.2, see https://github.com/php/php-src/issues/9950 + if ($ttl > 0) { + $valid->modify('+'.$ttl.' seconds'); + } elseif ($ttl < 0) { + $valid->modify($ttl.' seconds'); + } $model = new static(); $model->setRefreshToken($refreshToken); diff --git a/Security/Http/Authenticator/RefreshTokenAuthenticator.php b/Security/Http/Authenticator/RefreshTokenAuthenticator.php index bf6e0a0b..babd06b5 100644 --- a/Security/Http/Authenticator/RefreshTokenAuthenticator.php +++ b/Security/Http/Authenticator/RefreshTokenAuthenticator.php @@ -116,7 +116,14 @@ public function authenticate(Request $request): Passport if ($this->options['ttl_update']) { $expirationDate = new \DateTime(); - $expirationDate->modify(sprintf('+%d seconds', $this->options['ttl'])); + + // Explicitly check for a negative number based on a behavior change in PHP 8.2, see https://github.com/php/php-src/issues/9950 + if ($this->options['ttl'] > 0) { + $expirationDate->modify(sprintf('+%d seconds', $this->options['ttl'])); + } elseif ($this->options['ttl'] < 0) { + $expirationDate->modify(sprintf('%d seconds', $this->options['ttl'])); + } + $refreshToken->setValid($expirationDate); $this->refreshTokenManager->save($refreshToken);