@JussiMannisto Read once again my post : I have set 'expiration' => 3600, in the sanctum.php configuration file and when I create a new token, the expired_at field remains null in the database, whereas it should contain a date with the value now()->addHour().
@vincent15000 No it shouldn't. That's just something you made up.
How about you read what the configuration comment says:
This value controls the number of minutes until an issued token will be considered expired. This will override any values set in the token's "expires_at" attribute, but first-party sessions are not affected.
The config value doesn't get written to the expires_at column. Tokens will expire if they're older than sanctum.expiration regardless of what their expires_at value says. The expires_at value only comes into play if it's shorter than sanctum.expiration.
You didn't read the docs or look at the source code, made up how things should work, and then complained when I explained how Sanctum actually uses the config value.
I know this thread is from a year ago but still there is something not logical
@jussimannisto you mention "The config value doesn't get written to the expires_at column. Tokens will expire if they're older than sanctum.expiration regardless of what their expires_at value says. The expires_at value only comes into play if it's shorter than sanctum.expiration."
if the sanctum.expiration is null -> meaning there is no expiration time (what I understand) and when you create a token that needs to expire after 1 hour the expires_at value is shorter then the config. The token just created and is still valid is not accepted as a valid token, changing it has no impact.
Only removing the expires_at value makes the token valid.
I'm not sure I follow your point. The token is valid until one of these is hit:
The globally configured sanctum.expiration time since the token was created.
The token's own expires_at time.
Whichever is shorter defines the token's validity time. If they're both null, the token never expires.
The token just created and is still valid is not accepted as a valid token, changing it has no impact. Only removing the expires_at value makes the token valid.
If sanctum.expiration is null and you set the token's expires_at somewhere in the future, the token is valid until expires_at is hit. But note that expires_at is a timestamp while sanctum.expiration is given in minutes.
If the sanctum expiration (global) setting is 30 days, then no token can be older than 30 days, however if you set a token to expire in 1 hour then that single token has a 1 hour lifetime and will be considered invalid much quicker than the standard time.