Laravel JWT通过token查找对应的用户

时间:2017-08-19 16:40:17   收藏:0   阅读:683

通过jwt-auth提供的:  

use Tymon\JWTAuth\Exceptions\JWTException;
 public function getAuthenticatedUser()
    {
        try {

            if (! $user = JWTAuth::parseToken()->authenticate()) {
                return response()->json([user_not_found], 404);
            }

        } catch (TokenExpiredException $e) {

            return response()->json([token_expired], $e->getStatusCode());

        } catch (TokenInvalidException $e) {

            return response()->json([token_invalid], $e->getStatusCode());

        } catch (JWTException $e) {

            return response()->json([token_absent], $e->getStatusCode());

        }

        // the token is valid and we have found the user via the sub claim
        return response()->json(compact(user));
    }

 

原文:http://www.cnblogs.com/lindoubao/p/7396706.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!