Jwt-auth: get payload of expired token

Created on 8 Oct 2018  路  4Comments  路  Source: tymondesigns/jwt-auth

version: 1.0

I need a way to get the value of the payload of an expired token. Is there a way to get some public values?

(I want to check the value of 'keep login' in the expired token for the cookie lifetime setting.)

Most helpful comment

This is how I get the payload from an expired token in version 0.5.12, via reconstruction of a token:

$token = new \Tymon\JWTAuth\Token($request->bearerToken());
$payload = \JWTAuth::manager()->getJWTProvider()->decode($token);

All 4 comments

You can try this:

            try {
                $payload = \JWTAuth::parseToken()->getPayload();
            } catch (TokenExpiredException $e ) {
                if (env('JWT_FORCE_GET_PAYLOAD', false)) {
                    $payload = \JWTAuth::manager()->getJWTProvider()->decode(\JWTAuth::getToken()->get());
                } else {
                    throw new TokenExpiredException('Token has expired');
                }
            }

It worked for me in the version 1.0.0-rc.2

This is how I get the payload from an expired token in version 0.5.12, via reconstruction of a token:

$token = new \Tymon\JWTAuth\Token($request->bearerToken());
$payload = \JWTAuth::manager()->getJWTProvider()->decode($token);

I try it but a get the erro
Tymon/JWTAuth/Exceptions/TokenInvalidException with message 'Could not decode token: The JWT string must have two dots'

But my token have 2 dots

Same problem as @mandala21

Was this page helpful?
0 / 5 - 0 ratings