Jwt-auth: How do I get the token expiration time?

Created on 30 May 2016  路  5Comments  路  Source: tymondesigns/jwt-auth

Is it possible?

Most helpful comment

@HtmHell

$payload = JWTAuth::parseToken()->getPayload();
$expires_at = date('d M Y h:i', $payload->get('exp')); 

All 5 comments

You can get the "payload" of a token by _decoding_ it:

$payload = JWTAuth::decode($token);

The expiration time is stored in the payload's exp "claim" (which is just a key=>value pair). This can be retrieved in multiple ways:

$expiration = $payload->getExp();
$expiration = $payload->get('exp');
$expiration = $payload['exp'];

In the default setup, the exp will simply be a UTC timestamp.

@HtmHell

$payload = JWTAuth::parseToken()->getPayload();
$expires_at = date('d M Y h:i', $payload->get('exp')); 

Thanks alot!

you're welcome @HtmHell :)

Just wondering if there is any way of doing it on client side? I am currently sending and 2 extra fields to browser. expiration time for token, and expiration time for refresh.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lbottoni picture lbottoni  路  3Comments

lloy0076 picture lloy0076  路  3Comments

harveyslash picture harveyslash  路  3Comments

phamduong picture phamduong  路  3Comments

hfalucas picture hfalucas  路  3Comments