Unknown Reason for JWT Tokens invalidation

元气小坏坏 提交于 2019-12-11 12:54:41

问题


I'm facing very weird problem with my laravel-Angular application. I'm using Tymon JWT to refresh token on my every request. I'm using Satellizer library to handle these JWT-Tokens, however, Satellizer doesn't seem to have a response interceptor to capture the new token. Hence I wrote my own Interceptor to do so.

.factory('ResponseHttpInterceptor', function ($window) {
    return {
        response: function (response) {
            if (response.headers('Authorization') != null) {
                $window.localStorage.removeItem('satellizer_token');
                $window.localStorage.setItem('satellizer_token', response.headers('Authorization').replace('Bearer ', ''));
            }
            return response;
        }
    }
})

This code basically captures the new token and replaces the existing token in local storage with the new token.

My test flow is:

Login -> Make who Am I call -> Logout

Upon Logout I receive an error Invalid token (this doesn't happen always. Sometimes the flow succeeds and sometimes it fails). This flow works perfect via REST Client postman. So I don't think there is any problem in my API's

Attaching image showing the new token being passed, after it is refreshed after my whoami call.

Upon logout I'm clearing the local storage. Can Anyone tell me what could be the reason for this?

EDIT

Route::group(['prefix' => 'api/v1_0'], function () {
   Route::post('login', 'Auth\AuthControllerGeneral@postLogin');
   Route::get('logout', ['middleware' => 'jwt.auth', 'uses' =>    'Auth\AuthControllerGeneral@getLogout']);

   Route::group(['middleware' => ['jwt.refresh', 'jwt.auth']], function() {
       Route::get('whoami', 'Auth\AuthControllerGeneral@loggedInUserInfo');
   });
});

回答1:


Check you htaccess you should have below code there

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

And AuthContrller is same as https://github.com/sahat/satellizer/blob/master/examples/server/php/app/Http/Controllers/AuthController.php

And Some people forget to check Authenticate middleware. Check this also

https://github.com/sahat/satellizer/blob/master/examples/server/php/app/Http/Middleware/Authenticate.php

I suggest first try with default route as in demo https://github.com/sahat/satellizer/blob/master/examples/server/php/app/Http/routes.php

And still you not get the solution then try with sample client end folder. https://github.com/sahat/satellizer/tree/master/examples/client

Which you can put in your laravel public folder just to test.

I found everything working fine in satellizer but some people fails in configuring this.



来源:https://stackoverflow.com/questions/34835506/unknown-reason-for-jwt-tokens-invalidation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!