Hi,please,How do I check that token is expired?
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.