TymonのJWTAuthを使用して、Laravel 5.5でトークンベースの認証を実装しようとしています。ライブラリのGitHub Documentationに続き、次の認証フローを使用しています。ここに私のログインルートの認証部分は、次のとおりです。Laravel Tymon JWT Auth:認証前に有効な有効なトークンを確認しますか?
try {
// attempt to verify the credentials and create a token for the user
if (!$token = JWTAuth::attempt($credentials)) {
return response()->json(['success' => false, 'error' => 'Invalid Credentials. Please make sure you entered the right information and you have verified your email address.'], 401);
}
}
catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['success' => false, 'error' => 'could_not_create_token'], 500);
}
// all good so return the token
return response()->json(['success' => true, 'data'=> [ 'token' => $token ]]);
そして、ここではルートです:
Route::group([
'middleware' => ['jwt.auth', 'jwt.refresh'],
],
function() {
// Routes requiring authentication
Route::get('/logout', 'Auth\[email protected]');
Route::get('/protected', function() {
return 'This is a protected page. You must be logged in to see it.';
});
});
だから、私はjwt.authとjwt.refreshミドルウェアを使用しています見ることができます。今や、すべてが一見期待どおりに機能しており、トークンを使用してユーザーを認証できます。各トークンは1回の使用期間があり、各要求(リフレッシュフロー)後に別の有効なトークンが提供されます。
しかし私の問題は、まだ使用されていないユーザーの有効なトークンを持っていて、ヘッダーから削除して有効な資格情報で/ loginルートにヒットした場合です。もう1つ有効なトークン。だから私は/ loginルートは以前に発行されたトークンを無効にしていないので、ユーザーを認証するために使用できる2つの有効なトークンがあります。
誰かが未解決の有効なトークンを持っているかどうかを確認する方法を知っているので、ユーザーが別の場所からログインすると無効にすることができますか?