简体   繁体   中英

How to decode JWT using JWT-auth in laravel

您好,我的问题是我需要验证来自 android 的 JWT 令牌并对其进行解码以获取有效负载中的信息,但我似乎无法在 JWT-Auth 0.5* 中找到解码方法,是否还有另一种解码方法获取数据的有效载荷?

 use Tymon\JWTAuth\Facades\JWTAuth; //use this library

try this

 $token = JWTAuth::getToken();
 $apy = JWTAuth::getPayload($token)->toArray();

also you can get other info like this

   try {
        // attempt to verify the credentials and create a token for the user
        $token = JWTAuth::getToken();
        $apy = JWTAuth::getPayload($token)->toArray();
    } catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {

        return response()->json(['token_expired'], 500);

    } catch (\Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {

        return response()->json(['token_invalid'], 500);

    } catch (\Tymon\JWTAuth\Exceptions\JWTException $e) {

        return response()->json(['token_absent' => $e->getMessage()], 500);

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM