diff --git a/src/DataFixtures/APITokenFixtures.php b/src/DataFixtures/APITokenFixtures.php index 4bcf3a60..fbb4bdd2 100644 --- a/src/DataFixtures/APITokenFixtures.php +++ b/src/DataFixtures/APITokenFixtures.php @@ -75,7 +75,7 @@ class APITokenFixtures extends Fixture implements DependentFixtureInterface $expired_token->setUser($admin_user); $expired_token->setLevel(ApiTokenLevel::FULL); $expired_token->setName('expired'); - $expired_token->setValidUntil(new \DateTimeImmutable('-1 day')); + $expired_token->setValidUntil(new \DateTime('-1 day')); $this->setTokenSecret($expired_token, self::TOKEN_EXPIRED); $manager->persist($expired_token); diff --git a/src/Entity/OAuthToken.php b/src/Entity/OAuthToken.php index 84b3279c..2ecf9342 100644 --- a/src/Entity/OAuthToken.php +++ b/src/Entity/OAuthToken.php @@ -41,9 +41,9 @@ class OAuthToken extends AbstractNamedDBElement implements AccessTokenInterface #[ORM\Column(type: 'text', nullable: true)] private ?string $token = null; - /** @var \DateTimeInterface The date when the token expires */ + /** @var \DateTimeImmutable|null The date when the token expires */ #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)] - private ?\DateTimeInterface $expires_at = null; + private ?\DateTimeImmutable $expires_at = null; /** @var string|null The refresh token for the OAuth2 auth */ #[ORM\Column(type: 'text', nullable: true)] @@ -54,7 +54,7 @@ class OAuthToken extends AbstractNamedDBElement implements AccessTokenInterface */ private const DEFAULT_EXPIRATION_TIME = 3600; - public function __construct(string $name, ?string $refresh_token, ?string $token = null, \DateTimeInterface $expires_at = null) + public function __construct(string $name, ?string $refresh_token, ?string $token = null, \DateTimeImmutable $expires_at = null) { //If token is given, you also have to give the expires_at date if ($token !== null && $expires_at === null) { @@ -82,7 +82,7 @@ class OAuthToken extends AbstractNamedDBElement implements AccessTokenInterface ); } - private static function unixTimestampToDatetime(int $timestamp): \DateTimeInterface + private static function unixTimestampToDatetime(int $timestamp): \DateTimeImmutable { return \DateTimeImmutable::createFromFormat('U', (string)$timestamp); } diff --git a/src/Entity/UserSystem/ApiToken.php b/src/Entity/UserSystem/ApiToken.php index cd73de90..751c08c1 100644 --- a/src/Entity/UserSystem/ApiToken.php +++ b/src/Entity/UserSystem/ApiToken.php @@ -78,7 +78,7 @@ class ApiToken implements TimeStampableInterface #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] #[Groups('token:read')] #[Year2038BugWorkaround] - private ?\DateTimeInterface $valid_until; + private ?\DateTime $valid_until; #[ORM\Column(length: 68, unique: true)] private string $token; @@ -89,7 +89,7 @@ class ApiToken implements TimeStampableInterface #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] #[Groups('token:read')] - private ?\DateTimeInterface $last_time_used = null; + private ?\DateTime $last_time_used = null; public function __construct(ApiTokenType $tokenType = ApiTokenType::PERSONAL_ACCESS_TOKEN) { @@ -130,7 +130,7 @@ class ApiToken implements TimeStampableInterface return $this->valid_until === null || $this->valid_until > new \DateTime(); } - public function setValidUntil(?\DateTimeInterface $valid_until): ApiToken + public function setValidUntil(?\DateTime $valid_until): ApiToken { $this->valid_until = $valid_until; return $this; @@ -168,10 +168,10 @@ class ApiToken implements TimeStampableInterface /** * Sets the last time the token was used to authenticate. - * @param \DateTimeInterface|null $last_time_used + * @param \DateTime|null $last_time_used * @return ApiToken */ - public function setLastTimeUsed(?\DateTimeInterface $last_time_used): ApiToken + public function setLastTimeUsed(?\DateTime $last_time_used): ApiToken { $this->last_time_used = $last_time_used; return $this; diff --git a/src/Security/ApiTokenAuthenticator.php b/src/Security/ApiTokenAuthenticator.php index 23ab68b9..5d121556 100644 --- a/src/Security/ApiTokenAuthenticator.php +++ b/src/Security/ApiTokenAuthenticator.php @@ -75,7 +75,7 @@ class ApiTokenAuthenticator implements AuthenticatorInterface $old_time = $token->getLastTimeUsed(); //Set the last used date of the token - $token->setLastTimeUsed(new \DateTimeImmutable()); + $token->setLastTimeUsed(new \DateTime()); //Only flush the token if the last used date change is more than 10 minutes //For performance reasons we don't want to flush the token every time it is used, but only if it is used more than 10 minutes after the last time it was used //If a flush is later in the code we don't want to flush the token again