Beispiel #1
0
 /**
  * Authenticate user with credentials.
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function login(Request $request)
 {
     $credentials = $request->only('email', 'password');
     if (!($token = $this->auth->attempt($credentials))) {
         return response()->json(['error' => 'invalid_credentials'], 401);
     }
     $user = $this->auth->setToken($token)->toUser();
     return response()->json(['data' => compact('token', 'user')]);
 }
Beispiel #2
0
 /**
  * Authenticate request with a JWT.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Dingo\Api\Routing\Route $route
  *
  * @return mixed
  */
 public function authenticate(Request $request, Route $route)
 {
     $token = $this->getToken($request);
     try {
         return $this->auth->setToken($token)->authenticate();
     } catch (JWTException $e) {
         throw new UnauthorizedHttpException('JWTAuth', $e->getMessage());
     }
     return $user;
 }
Beispiel #3
0
 /**
  * Authenticate request with a JWT.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Dingo\Api\Routing\Route $route
  *
  * @return mixed
  */
 public function authenticate(Request $request, Route $route)
 {
     $token = $this->getToken($request);
     try {
         if (!($user = $this->auth->setToken($token)->authenticate())) {
             throw new UnauthorizedHttpException('JWTAuth', 'Unable to authenticate with invalid token.');
         }
     } catch (JWTException $e) {
         throw new UnauthorizedHttpException('JWTAuth', $e->getMessage());
     }
     return $user;
 }
 /**
  * Set the token.
  *
  * @param string $token
  * @return $this 
  * @static 
  */
 public static function setToken($token)
 {
     return \Tymon\JWTAuth\JWTAuth::setToken($token);
 }