Skip to content

Commit 2f67b9e

Browse files
committed
update
1 parent eef43ca commit 2f67b9e

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/Service/Manager.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare (strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace xiaodi\JWTAuth\Service;
66

@@ -77,6 +77,19 @@ public function logout(Token $token): void
7777
$this->pushBlacklist($store, $jti, (string) $token, $exp);
7878
}
7979

80+
public function wasBan(Token $token): bool
81+
{
82+
$jti = $token->getClaim('jti');
83+
$store = $token->getClaim('store');
84+
85+
return $this->getBlacklist($store, $jti) ? true : false;
86+
}
87+
88+
protected function getBlacklist($store, $jti)
89+
{
90+
return $this->getCache($store, $jti, $this->config->getBlacklist());
91+
}
92+
8093
public function destroyStoreWhitelist($store): void
8194
{
8295
$this->clearStoreWhitelist($store);
@@ -137,4 +150,11 @@ private function clearCache($store, $type, $uid): void
137150

138151
$this->app->cache->delete($key);
139152
}
153+
154+
private function getCache($store, $uid, $type)
155+
{
156+
$key = implode('', [$this->config->getPrefix(), $store, $type, $uid]);
157+
158+
return $this->app->cache->get($key);
159+
}
140160
}

src/Service/Token.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ public function verify(string $token): ?bool
186186
} else {
187187
throw new TokenAlreadyEexpired('Token 刷新时间已过,请重新登录', $this->config->getReloginCode());
188188
}
189+
} else {
190+
// 是否存在黑名单
191+
if (true === $this->app->get('jwt.manager')->wasBan($this->token)) {
192+
throw new TokenAlreadyEexpired('Token 已被禁用,请重新登录', $this->config->getReloginCode());
193+
}
189194
}
190195

191196
$data = new ValidationData();

0 commit comments

Comments
 (0)