Ejemplo n.º 1
0
 /**
  * @return string|null
  */
 function jwt_token()
 {
     $jwt_token = \Session::get('jwt_token');
     if (is_jwt_token_valid_for_refresh($jwt_token, true) || empty($jwt_token) && \Auth::check()) {
         $refreshed_token = refresh_jwt_token();
         if (!empty($refreshed_token)) {
             $jwt_token = $refreshed_token;
         }
     }
     return $jwt_token;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $response = $next($request);
     // verify only if token present
     if ($token = $this->auth->setRequest($request)->getToken()) {
         // valid for refresh
         if (is_jwt_token_valid_for_refresh($token)) {
             $newToken = refresh_jwt_token();
             if (!empty($newToken)) {
                 // send the refreshed token back to the client
                 $response->headers->set('Authorization', $newToken);
             }
         }
     }
     return $response;
 }