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

通过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'));
    }

 

posted @ 2017-08-19 15:20  林豆包的长颈鹿  阅读(4378)  评论(0编辑  收藏  举报