Jwt-auth: hi,How do I check that token is expired?please.

Created on 25 Dec 2017  路  6Comments  路  Source: tymondesigns/jwt-auth

Hi,please,How do I check that token is expired?

All 6 comments

There is no direct method to do that. You should first try to make an authentication and if token is expired, then you can catch it by TokenExpiredException.
Note that if refresh_ttl ends, it will also caught by TokenExpiredException

try{
    $user = JWTAuth::parseToken()->authenticate();
} catch (TokenExpiredException $e){
    return response()->json(['Page must be refreshed']);
} 

You can call JWTAuth::parseToken()->check() (for v0.5.) which will return a boolean or auth()->check() for v1.0.

@tymondesigns hello guys. it is just for validator not for expired.how can i know it was expired exactly.

Hi , Simply JWT is base64 coded HEADER.PAYLOAD.VERIFY_SIGNATURE
we need exactly PAYLOAD
it will look something like

{
  "sub": "1234567890",
  "name": "John Doe",
  "exp":"1516235022",
  "iat": 1516239022
}

covert it to json and then compare 馃憤

$dataRaw = explode(".",$token);
         $dataRaw =  base64_decode ($dataRaw[1]);
         $now = time();
         $dataRaw = json_decode($dataRaw);
         if($dataRaw->exp < $now-60){
           return "No_Need";
         }

This is somethign that should be in the library. I mean, come on.

I figured it out! @boorcode:

\JWTAuth::parseToken()->getClaim('exp');

It will throw TokenExpiredException if the token is expired.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lloy0076 picture lloy0076  路  3Comments

gandra picture gandra  路  3Comments

therealmjk picture therealmjk  路  3Comments

gamelife1314 picture gamelife1314  路  3Comments

hfalucas picture hfalucas  路  3Comments