Unknown Reason for JWT Tokens invalidation

2019-08-13 16:51发布

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.

enter image description here

enter image description here

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条回答
2楼-- · 2019-08-13 17:32

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.

查看更多
登录 后发表回答