【发布时间】:2016-10-14 08:51:25
【问题描述】:
我在 Laravel 中有一个后端,并在 Ionic 中制作了一个应用程序。我在前端使用satellizer,在laravel 端使用this package 进行JWT 身份验证。由于在用户注销之前我需要为用户提供令牌,因此我需要一种以某种方式刷新其令牌的方法。我不知道该怎么做,最好让所有路由都请求身份验证令牌并发送 401 响应(如果不存在),然后进行令牌刷新,或者在前端用计时器刷新令牌以及如何实际做到这一点?
这是我的路线文件:
Route::group(['jwt.auth', ['except' => ['authenticate']], 'prefix' => 'api', 'namespace' => 'Api'], function() {
Route::post('authenticate', 'AuthenticateController@authenticate');
Route::get('user', 'AuthenticateController@getAuthenticatedUser');
Route::get('comment', 'AuthenticateController@comment');
Route::get('articles/latest', 'ArticlesController@latest');
Route::get('articles/by-score', 'ArticlesController@byScore');
Route::get('article/{id}', 'ArticlesController@show');
Route::get('comments', 'CommentsController@index');
Route::get('comments/{id}', 'CommentsController@show');
Route::post('comments/create', 'CommentsController@store');
Route::put('comments/update', 'CommentsController@update');
Route::delete('comments/delete', 'CommentsController@destroy');
Route::post('article/upvote', 'VotesController@upvote');
Route::delete('article/upvote/delete', 'VotesController@destroyUpVote');
Route::post('article/challenge/vote', 'VotesController@challengeVote');
Route::delete('article/challenge/vote/delete', 'VotesController@destroyChallengeVote');
});
【问题讨论】: