Saturday, 15 May 2010

javascript - laravel / angularjs JWT token refresh -


I am applying JW authentication in an angular / laurel application and I have a problem refreshing the token.

The relevant code here:

PHP: Lavender-JVT listener, which for tymon.jwt.expired 'listen' to the event: / ** * has been removed when the token expires * @param \ exception $ e * @return \ Illuminate \ http \ jsonResponse * / Public Function Expiry ( $ E) {$ token = \ JWTAuth :: parseToken (); Config :: Package ('Timon / JWT-ATH', 'JWT'); $ Ttl = Config :: get ('jwt :: refresh_ttl'); $ Iat = Carbon :: createFromTimestamp ($ Token-> GetPayload () -> Get ('IT')); $ Now = Carbon :: Now (); // If the renewal TTL has expired, then return to 401, otherwise give // ​​a new token in front of the application ($ iat- & gt; diffInMinutes ($$) & gt; = $ ttl) {without Set ($ iat, $ now), $ Ttl); Return response_failure (Lang :: get ('errors.api.auth.expired'), Config :: get ('status.error.unuthorized')); } Unset ($ iat, $ now, $ ttl); }

PHP: after 'filter':

  / * | ---------- ---------------------------------------- ---------- -------------- | JWT-EOUTH Token-Refreshing Filters | ---------------------------------------------------- ------------------------ | | Refresh talk filter is a reaction. Back to the top | Updated authentication token | * / Root :: filter ('refresh token', function ($ route, $ request, $ response) {$ token = JWTAuth :: parseToken ()} {$ token-> toUser ();} Attempt to capture (TokenXide Execution $ E) {Config :: Package ('Timon / JWT-ATH', 'JWT'); $ ttl = Config :: Mill ('jwt :: refresh_ttl'); $ iat = \ carbon \ carbon: : CreateFromTimestamp ($ Token- ($ Iat-> diffInMinutes ($ Now) & lt; $ ttl) {$ response- & gt; Header-> Set ('Authority', 'Bearer'. $ Tokens- & Gt; Refresh ());}}}); PHP: Certified Route Filter:   
  R T: Group (['first' = 'gt;' jwt-Auth ',' after '=>,' refresh '], function () {...});  

JS: Interceptor updating LocalStorage

  'Use strict'; Angular.module ('app'). Factor ('Response Interceptor' , ['Session service', 'jwthlper', '$ location', '$ q', function (session service, jwtHelper, $ location, $ cue) {return: feedback}; // 300 code response The http code is called {var token = response.headers ('authorization'); If ('undefined'! == type token & amp; amp; amp; & amp; amp; null; == token) {session session .settoken (token split ('') [1]);} return response;}}] ));  

It works well except for a problem (workflow):

  • The token has expired but still to be renewed
  • P> The problem is that if any request is sent during the delay "renewal" , all requests to the server Requests are rejected because token am The NY (Blacklist).

    Am I doing the wrong thing? Can anyone tell me in the right direction?

    What I want to achieve is to set Token's TTL in about 5 minutes, and allows the user to renew the token while navigating.

This is actually a bug in the library, and is now accurate for more information


No comments:

Post a Comment