From b8edb45a46018a83257d4e84877893691eefdaa8 Mon Sep 17 00:00:00 2001 From: frank Date: Wed, 4 Dec 2024 15:35:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=AE=A9token=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=9B=B4=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Jwt/AbstractJwt.php | 4 +++- src/Jwt/AccessTokenConstraint.php | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/Jwt/AccessTokenConstraint.php diff --git a/src/Jwt/AbstractJwt.php b/src/Jwt/AbstractJwt.php index 107bfcd..7f208ad 100644 --- a/src/Jwt/AbstractJwt.php +++ b/src/Jwt/AbstractJwt.php @@ -31,6 +31,7 @@ public function __construct( private readonly array $config, private readonly CacheManager $cacheManager, private readonly Clock $clock, + private readonly AccessTokenConstraint $accessTokenConstraint, private readonly RefreshTokenConstraint $refreshTokenConstraint ) {} @@ -72,7 +73,8 @@ public function parserRefreshToken(string $refreshToken): UnencryptedToken $this->clock, $this->clock->now()->diff($this->getRefreshExpireAt($this->clock->now())) ), - $this->getBlackListConstraint() + $this->getBlackListConstraint(), + $this->accessTokenConstraint ); } diff --git a/src/Jwt/AccessTokenConstraint.php b/src/Jwt/AccessTokenConstraint.php new file mode 100644 index 0000000..b2caaae --- /dev/null +++ b/src/Jwt/AccessTokenConstraint.php @@ -0,0 +1,27 @@ +isRelatedTo('refresh')) { + throw ConstraintViolation::error('Token is not a refresh token', $this); + } + } +}