SANCTUM过期后仍在获取数据



嗨,我编辑config/sancum.php,添加一个值1分钟,以测试过期后是否会出现错误。当我在3分钟后从我的SPA应用程序发送请求时,我能够获得详细信息。我预计它会抛出一个错误或一些状态代码422,或者laravel抛出的任何状态代码。

"过期"=>1

<?php
return [
/*
|--------------------------------------------------------------------------
| Stateful Domains
|--------------------------------------------------------------------------
|
| Requests from the following domains / hosts will receive stateful API
| authentication cookies. Typically, these should include your local
| and production domains which access your API via a frontend SPA.
|
*/
'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', 'localhost,127.0.0.1,127.0.0.1:8000,::1')),
/*
|--------------------------------------------------------------------------
| 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' => 1,
/*
|--------------------------------------------------------------------------
| Sanctum Middleware
|--------------------------------------------------------------------------
|
| When authenticating your first-party SPA with Sanctum you may need to
| customize some of the middleware Sanctum uses while processing the
| request. You may change the middleware listed below as required.
|
*/
'middleware' => [
'verify_csrf_token' => AppHttpMiddlewareVerifyCsrfToken::class,
'encrypt_cookies' => AppHttpMiddlewareEncryptCookies::class,
],
];

我是在配置中还是在其他地方遗漏了什么?

提前谢谢。

清理缓存配置并再次测试

php artisan config:cache

然后

php artisan cache:clear

我认为它可以解决你的问题。

对于您的问题,您可以尝试更改到期的值

'expiration' => 120

或者制作

'expiration' => null

如果此值为null,则个人访问令牌不会过期。

最新更新