From b471ea3f5ec5e94f8186551a9eae198a51d83d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 6 Aug 2021 18:14:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Jwt/Jwt.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/System/Jwt/Jwt.php b/System/Jwt/Jwt.php index 6e8bf0ec..7d4eb08f 100644 --- a/System/Jwt/Jwt.php +++ b/System/Jwt/Jwt.php @@ -101,7 +101,11 @@ class Jwt extends Component */ public function getUnionId($token): string|int { - return $this->unpack($token)['unionId']; + $unpack = $this->unpack($token); + if (!$this->_validator($unpack)) { + throw new JWTAuthTokenException('JWT certificate has expired.'); + } + return $unpack['unionId']; } @@ -112,7 +116,16 @@ class Jwt extends Component */ public function validator($token): bool { - $unpack = $this->unpack($token); + return $this->_validator($this->unpack($token)); + } + + + /** + * @param $unpack + * @return bool + */ + private function _validator($unpack): bool + { if ($unpack['expire_at'] < time()) { return false; }