From 0037641eda08ea27a66928c5ce90c5fc970e013a Mon Sep 17 00:00:00 2001 From: liyuzhao <8603583yuPENG> Date: Wed, 26 Feb 2020 15:46:19 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=A7=84=E8=8C=83=E5=BC=82=E5=B8=B8h?= =?UTF-8?q?ttp=E7=8A=B6=E6=80=81=E7=A0=81=EF=BC=8C500=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E7=A0=81=E6=94=B9=E4=B8=BA400=202=E3=80=81=E4=BF=AE=E5=A4=8Dto?= =?UTF-8?q?ken=E9=AA=8C=E8=AF=81=E5=BC=82=E5=B8=B8=E6=97=B6=E6=8A=A5400?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=EF=BC=8C=E5=BA=94=E8=AF=A5=E6=8A=A5?= =?UTF-8?q?401?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/Jwt.php | 4 ++-- src/Traits/CommonTrait.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cec9b44..df6d64c 100644 --- a/README.md +++ b/README.md @@ -242,4 +242,4 @@ class IndexController extends AbstractController 例如:`$this->jwt->getParserData()` ##### 12、建议 -> 目前 `jwt` 抛出的异常目前有两种类型 `Phper666\JwtAuth\Exception\TokenValidException` 和 `Phper666\JwtAuth\Exception\JWTException,TokenValidException` 异常为 token 验证失败的异常,会抛出 `401` ,`JWTException` 异常会抛出 `500`,最好你们自己在项目异常重新返回错误信息 +> 目前 `jwt` 抛出的异常目前有两种类型 `Phper666\JwtAuth\Exception\TokenValidException` 和 `Phper666\JwtAuth\Exception\JWTException,TokenValidException` 异常为 token 验证失败的异常,会抛出 `401` ,`JWTException` 异常会抛出 `400`,最好你们自己在项目异常重新返回错误信息 diff --git a/src/Jwt.php b/src/Jwt.php index 166aca2..2259ae8 100644 --- a/src/Jwt.php +++ b/src/Jwt.php @@ -39,7 +39,7 @@ public function getToken(array $claims, $isInsertSsoBlack = true) $uniqid = uniqid(); } else { // 单点登录 if (empty($claims[$this->ssoKey])) { - throw new JWTException("There is no {$this->ssoKey} key in the claims", 500); + throw new JWTException("There is no {$this->ssoKey} key in the claims", 400); } $uniqid = $claims[$this->ssoKey]; } @@ -74,7 +74,7 @@ public function getToken(array $claims, $isInsertSsoBlack = true) public function refreshToken() { if (!$this->getHeaderToken()) { - throw new JWTException('A token is required', 500); + throw new JWTException('A token is required', 400); } $claims = $this->blacklist->add($this->getTokenObj()); unset($claims['iat']); diff --git a/src/Traits/CommonTrait.php b/src/Traits/CommonTrait.php index 6aa3577..4ac62c3 100644 --- a/src/Traits/CommonTrait.php +++ b/src/Traits/CommonTrait.php @@ -166,7 +166,7 @@ public function verifyToken(Token $token) { $alg = $token->getHeader('alg'); if (empty($this->supportedAlgs[$alg])) { - throw new TokenValidException('Algorithm not supported', 500); + throw new TokenValidException('Algorithm not supported', 401); } /** @var Signer $signer */ $signer = new $this->supportedAlgs[$alg]; @@ -210,7 +210,7 @@ public function getHeaderToken() return $token; } - throw new JWTException('A token is required', 500); + throw new JWTException('A token is required', 400); } /**