public function profile(JWTAuth $auth) { $user = $auth->parseToken()->toUser(); $transformer = $user->isOwner() ? new OwnerTransformer() : new EmployeeTransformer(); return $this->response->withItem($user->userable, $transformer); }
/** * {@inheritdoc} */ public function parseToken($method = 'bearer', $header = 'authorization', $query = 'jwt-token') { return parent::parseToken($method, $header, $query); }
/** * @param Request $request * @return false|\Tymon\JWTAuth\Contracts\JWTSubject * @throws JWTException */ public function me(Request $request) { if (Auth::check()) { return Auth::user(); } return $this->jwt->parseToken()->authenticate(); }
/** * Authenticate a user using JWT token. * * @return \Symfony\Component\HttpFoundation\Response * @throws \Tymon\JWTAuth\Exceptions\JWTException */ public function verify() { if (!($user = $this->auth->parseToken()->authenticate())) { return response()->json(['user_not_found'], 404); } // the token is valid and we have found the user via the sub claim return response()->json(['data' => compact('user')]); }
/** * Validate Token * * returns Illuminate\Http\JsonResponse */ public function validate() { try { if (!($user = $this->jwt->parseToken()->authenticate())) { return $this->returnUnauthenticatedUserResponse(); } } catch (TokenExpiredException $exception) { return $this->returnTokenExceptionResponse('token_expired', 401); } catch (TokenInvalidException $exception) { return $this->returnTokenExceptionResponse('token_invalid', 401); } catch (JWTException $exception) { return $this->returnTokenExceptionResponse('token_absent', 401); } return $this->returnAuthenticatedUserResponse(compact('user')); }
public function getAuthenticatedUser(Request $request) { try { if (!($user = JWTAuth::parseToken()->authenticate())) { return response()->json(['error' => 'user_not_found'], 404); } } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) { return response()->json(['error' => 'token_expired'], $e->getStatusCode()); } catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) { return response()->json(['error' => 'token_invalid'], $e->getStatusCode()); } catch (Tymon\JWTAuth\Exceptions\JWTException $e) { return response()->json(['error' => 'token_absent'], $e->getStatusCode()); } return response()->json(compact('user')); }
public function getAuthenticatedUser() { try { if (!($user = JWTAuth::parseToken()->authenticate())) { return response()->json(['user_not_found'], 404); } } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) { return response()->json(['token_expired'], $e->getStatusCode()); } catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) { return response()->json(['token_invalid'], $e->getStatusCode()); } catch (Tymon\JWTAuth\Exceptions\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')); }
public function handle($request, Closure $next) { $jwt = new JWTAuth(); try { if (!($user = $jwt->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 $next($request, $user); }
/** * Parse the token from the request. * * @param string $query * @return \Tymon\JWTAuth\JWTAuth * @static */ public static function parseToken($method = 'bearer', $header = 'authorization', $query = 'token') { return \Tymon\JWTAuth\JWTAuth::parseToken($method, $header, $query); }
/** @test */ public function it_should_throw_an_exception_when_token_not_present_in_request() { $this->setExpectedException('Tymon\\JWTAuth\\Exceptions\\JWTException'); $request = Request::create('/foo', 'GET'); $jwtAuth = new JWTAuth($this->manager, $this->user, $this->auth, $request); $jwtAuth->parseToken(); }
public function refresh(JWTAuth $auth) { $token = $auth->parseToken()->refresh(); return $this->response->success($token); }
/** * Parse the token from the request * * @param string $query * @return \Tymon\JWTAuth\JWTAuth * @static */ public static function parseToken($query = 'token') { return \Tymon\JWTAuth\JWTAuth::parseToken($query); }