令牌过期不起作用 - Sanctum,Laravel
Token expiration doesn't working - Sanctum, Laravel
我做了什么:
我通过在 sanctum.php 文件中将 null
更改为 1
分钟 expiration
来向具有登录系统的应用程序添加令牌过期:
/*
|--------------------------------------------------------------------------
| 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.`enter code here`
|
*/
'expiration' => 1,
问题:
它不起作用,该应用程序仍然始终接受授权请求。什么都没有改变。
代码:
- 创建令牌(登录):
$tokenResult = $user -> createToken('authToken') -> plainTextToken;
return response() -> json([
'status_code' => 200,
'access_token' => $tokenResult,
'token_type' => 'Bearer',
]);
- 验证令牌:
Route::group(['middleware' => 'auth:sanctum'], function () {
[Routes]
});
- 删除令牌(注销):
Auth::user()->tokens()->delete();
return response()->json([
'status_code' => 200,
]);
您可能需要清除配置缓存。尝试在您的终端运行 php artisan config:clear
我做了什么:
我通过在 sanctum.php 文件中将 null
更改为 1
分钟 expiration
来向具有登录系统的应用程序添加令牌过期:
/*
|--------------------------------------------------------------------------
| 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.`enter code here`
|
*/
'expiration' => 1,
问题:
它不起作用,该应用程序仍然始终接受授权请求。什么都没有改变。
代码:
- 创建令牌(登录):
$tokenResult = $user -> createToken('authToken') -> plainTextToken;
return response() -> json([
'status_code' => 200,
'access_token' => $tokenResult,
'token_type' => 'Bearer',
]);
- 验证令牌:
Route::group(['middleware' => 'auth:sanctum'], function () {
[Routes]
});
- 删除令牌(注销):
Auth::user()->tokens()->delete();
return response()->json([
'status_code' => 200,
]);
您可能需要清除配置缓存。尝试在您的终端运行 php artisan config:clear