|
|
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|
|
|
|
|
namespace SixShop\Auth\Hook;
|
|
|
|
|
|
+use Firebase\JWT\ExpiredException;
|
|
|
use SixShop\Auth\Auth;
|
|
|
use SixShop\Core\Attribute\Hook;
|
|
|
use think\Cache;
|
|
|
@@ -23,9 +24,13 @@ class AuthHook
|
|
|
public function checkToken($payload): void
|
|
|
{
|
|
|
if ($this->cache->has(self::TOKEN_REVOKE . $payload->jti)
|
|
|
- && $this->cache->get(self::TOKEN_REVOKE . $payload->jti) < time() + Auth::SLEEP_WAY) {
|
|
|
- throw new \Exception('token 已失效');
|
|
|
+ && $this->cache->get(self::TOKEN_REVOKE . $payload->jti) > time() + Auth::SLEEP_WAY) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ $ex = new ExpiredException('Expired token');
|
|
|
+ $ex->setPayload($payload->exp);
|
|
|
+ $ex->setTimestamp($timestamp);
|
|
|
+ throw $ex;
|
|
|
}
|
|
|
|
|
|
#[Hook("token_revoke")]
|