Ejemplo n.º 1
0
 /**
  * Return request headers needed to interact with the API.
  *
  * @return Array array of headers.
  */
 protected function headers($user = null)
 {
     $headers = ['Accept' => 'application/json'];
     if (!is_null($user)) {
         $token = JWTAuth::fromUser($user);
         JWTAuth::setToken($token);
         $headers['Authorization'] = 'Bearer ' . $token;
     }
     return $headers;
 }
Ejemplo n.º 2
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, \Closure $next, $isRest = "Rest")
 {
     Log::debug("CheckJWT.handle.begin");
     $isAjax = $isRest == "Rest";
     Log::warning("Rest call:" . $isAjax);
     $jwt = DragoCookie::getCookie();
     $token = null;
     if ($jwt != null) {
         $token = JWTAuth::setToken($jwt);
     } else {
         $token = JWTAuth::getToken();
     }
     if ($token == null) {
         Log::warning("CheckJWT.handle.token invalid");
         if ($isAjax) {
             return response("token invalid", 401);
         } else {
             return redirect('login');
         }
     }
     try {
         $user = $token->authenticate();
         Log::debug("CheckJWT.handle.user:"******"CheckJWT.handle.token expired");
         if ($isAjax) {
             return response("token expired", 401);
         } else {
             return redirect('login');
         }
     } catch (JWTException $e) {
         Log::warning("CheckJWT.handle.token invalid");
         if ($isAjax) {
             return response("token invalid", 401);
         } else {
             return redirect('login');
         }
     }
     if (!$user) {
         Log::warning("CheckJWT.handle.user not found");
         if ($isAjax) {
             return response("token invalid", 401);
         } else {
             return redirect('login');
         }
     }
     Log::debug("CheckJWT.handle.end");
     return $next($request);
 }
Ejemplo n.º 3
0
 /**
  * Set the token.
  *
  * @param  Token|string $token
  *
  * @return JwtGuard
  */
 public function setToken($token)
 {
     $this->token = $token;
     JWTAuth::setToken($token);
     return $this;
 }