我把GetUserFromToken
的handle
修改了,但是提示token_invalid
....
public function handle($request, \Closure $next)
{
$expired = false;
$user = null;
if (! $token = $this->auth->setRequest($request)->getToken()) {
return $this->respond('tymon.jwt.absent', 'token_not_provided', 400);
}
try {
$user = $this->auth->authenticate($token);
} catch (TokenExpiredException $e) {
// token 期满
// return $this->respond('tymon.jwt.expired', 'token_expired', $e->getStatusCode(), [$e]);
$expired = true;
} catch (JWTException $e) {
// token 无效
return $this->respond('tymon.jwt.invalid', 'token_invalid', $e->getStatusCode(), [$e]);
}
if ($expired) {
try {
$newToken = $this->auth->setRequest($request)->parseToken()->refresh();
$user = $this->auth->authenticate($newToken);
} catch (TokenExpiredException $e) {
return $this->respond('tymon.jwt.expired', 'token_expired', $e->getStatusCode(), [$e]);
} catch (JWTException $e) {
return $this->respond('tymon.jwt.invalid', 'token_invalid', $e->getStatusCode(), [$e]);
}
// send the refreshed token back to the client
$request->headers->set('Authorization', 'Bearer '.$newToken);
}
if (! $user) {
return $this->respond('tymon.jwt.user_not_found', 'user_not_found', 404);
}
$this->events->fire('tymon.jwt.valid', $user);
return $next($request);
}