Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kenprogrammer's avatar

Sanctum Token Expiry

I've updated this value 'expiration' => 36000, in sanctum.php so that tokens can expire after the specified period but when I check the personal_access_tokens table after a successful login the expires_at column is still NULL.

Am I missing something?

0 likes
2 replies
vincent15000's avatar
Level 63

By default the createToken method sets the expires_at column to null if you don't specify any value.

Here is the method from the HasApiTokens trait from Sanctum.

public function createToken(string $name, array $abilities = ['*'], DateTimeInterface $expiresAt = null)
{
    $token = $this->tokens()->create([
        'name' => $name,
        'token' => hash('sha256', $plainTextToken = Str::random(40)),
        'abilities' => $abilities,
        'expires_at' => $expiresAt,
    ]);

    return new NewAccessToken($token, $token->getKey().'|'.$plainTextToken);
}

Furthermore you can see that the expiration key in the configuration file doesn't impact the first-party sessions.

This won't tweak the lifetime of first-party sessions.

/*
|--------------------------------------------------------------------------
| Expiration Minutes
|--------------------------------------------------------------------------
|
| This value controls the number of minutes until an issued token will be
| considered expired. If this value is null, personal access tokens do
| not expire. This won't tweak the lifetime of first-party sessions.
|
*/

'expiration' => null,
1 like

Please or to participate in this conversation.