How to decode JWT using JWT-auth in laravel

南笙酒味 提交于 2019-12-21 17:56:36

问题


hello mt issue is that I need to verify JWT token coming from android and decode it to fetch the information in the payload but i cant seem to find a decode method in the JWT-Auth 0.5*, is there another way to decode the payload to get the data?


回答1:


 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);

    }


来源:https://stackoverflow.com/questions/48309645/how-to-decode-jwt-using-jwt-auth-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!