|
|
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
|
|
|
|
|
namespace SixShop\Auth;
|
|
|
|
|
|
+use Firebase\JWT\ExpiredException;
|
|
|
use Firebase\JWT\JWT;
|
|
|
use Firebase\JWT\Key;
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
@@ -28,9 +29,7 @@ class Auth implements AuthInterface
|
|
|
|
|
|
public function refreshToken(string $jwt): string
|
|
|
{
|
|
|
- $res = $this->generateToken($this->verifyToken($jwt));
|
|
|
- $this->revokeToken($jwt);
|
|
|
- return $res;
|
|
|
+ return $this->generateToken($this->verifyToken($jwt));
|
|
|
}
|
|
|
|
|
|
public function generateToken(string $userId): string
|
|
|
@@ -52,7 +51,11 @@ class Auth implements AuthInterface
|
|
|
public function verifyToken(string $jwt): string
|
|
|
{
|
|
|
JWT::$leeway = self::SLEEP_WAY;
|
|
|
- $payload = JWT::decode($jwt, new Key($this->config['jwt_secret'], self::ALGORITHM));
|
|
|
+ try {
|
|
|
+ $payload = JWT::decode($jwt, new Key($this->config['jwt_secret'], self::ALGORITHM));
|
|
|
+ } catch (ExpiredException) {
|
|
|
+ // ... 忽略
|
|
|
+ }
|
|
|
$res = match (UserTypeEnum::tryFrom($payload->aud)) {
|
|
|
$this->userType => decrypt_data($payload->sub, $this->config['jwt_secret']),
|
|
|
default => throw new \Exception('token 类型错误'),
|