如何在Laravel中使用JWT-auth解码JWT [英] How to decode JWT using JWT-auth in laravel
本文介绍了如何在Laravel中使用JWT-auth解码JWT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我的问题是我需要验证来自android的JWT令牌并对其进行解码以获取有效负载中的信息,但我似乎在JWT-Auth 0.5 *中找不到解码方法,是否还有另一个有效载荷解码以获取数据的方法?
Hello my issue is that I need to verify a JWT token coming from android and decode it to fetch the information in the payload but I can't seem to find a decode method in the JWT-Auth 0.5*, is there another way to decode the payload to get the data?
推荐答案
use Tymon\JWTAuth\Facades\JWTAuth; //use this library
尝试
$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);
}
这篇关于如何在Laravel中使用JWT-auth解码JWT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文