【发布时间】:2017-10-22 23:54:06
【问题描述】:
我正在使用 JWT 令牌,它在前一段时间运行良好。但是现在,每当我使用令牌时,我都会在第一次尝试中得到我想要的结果,然后我第二次检查它(2 分钟后),我得到了无效的令牌: 这是我的验证码:
$credentials = $request->only('email', 'password');
try {
// verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong
return response()->json(['error' => 'could_not_create_token'], 500);
}
// if no errors are encountered we can return a JWT
return response()->json(compact('token'));
这是我的 web.php 文件
Route::group(['prefix' => 'api/v1','middleware' => ['cors']], function(){
Route::resource('authenticate', 'AuthenticateController');
Route::post('authenticate', 'AuthenticateController@authenticate');
Route::group(['middleware' => ['jwt.auth', 'jwt.refresh']], function() {
Route::resource('books', 'BooksController', ['except'=>'store', 'update']);
});
});
【问题讨论】:
-
您是否正在存储
tokencreated ?在您的本地存储或 cookie 中 -
我不这么认为,我该如何检查?
-
您是否更改了
config/jwt.php中的令牌生命周期? -
你是说ttl?默认值为60
-
@DrStein 是的。 ttl 是生命周期。默认 60 分钟。