修正解析token时过期时处理
This commit is contained in:
parent
2aa253fa5d
commit
17c979105c
@ -62,9 +62,9 @@ class AuthMiddleware implements MiddlewareInterface
|
||||
$white_api = $Auth->checkApiWhiteList($path_info, $method);
|
||||
|
||||
if (!empty($token)){
|
||||
$res = $redis->get('jwt_black_' . $token);
|
||||
if ($white_api){
|
||||
// 存在token,免鉴权
|
||||
$res = $redis->get('jwt_black_' . $token);
|
||||
if ($res && time() >= $res) {
|
||||
// token存在黑名单中
|
||||
return $handler->handle($request);
|
||||
@ -78,12 +78,12 @@ class AuthMiddleware implements MiddlewareInterface
|
||||
}
|
||||
}else{
|
||||
// 存在token,鉴权
|
||||
$res = $redis->get('jwt_black_' . $token);
|
||||
if ($res && time() >= $res) {
|
||||
// token存在黑名单中
|
||||
return $this->response->json(fail(HttpEnumCode::TOKEN_ERROR));
|
||||
}
|
||||
|
||||
try {
|
||||
// jwt验证
|
||||
$result = $Jwt->decode($token);
|
||||
|
||||
@ -104,6 +104,12 @@ class AuthMiddleware implements MiddlewareInterface
|
||||
$response = $response->withHeader('Authorization', $new_token);
|
||||
Context::set(ResponseInterface::class, $response);
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
if ($e->getCode() == 405 || $e->getCode() == 406){
|
||||
return $this->response->json(fail($e->getCode()));
|
||||
}
|
||||
return $this->response->json(fail(HttpEnumCode::SERVER_ERROR));
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if ($white_api){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user