Skip to content

Commit 052266c

Browse files
committed
update
1 parent f21c280 commit 052266c

4 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/Handle/Url.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class Url extends RequestToken
88
{
99
public function handle()
1010
{
11-
return $this->app->request->param('token');
11+
return $this->app->request->get('token');
1212
}
1313
}

src/Service/Jwt.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,14 @@ public function ttl()
111111
{
112112
return $this->app->get('jwt.token')->getRefreshTTL();
113113
}
114+
115+
public function refresh(?string $token = null)
116+
{
117+
return $this->app->get('jwt.token')->refresh($token);
118+
}
119+
120+
public function logout(?string $token = null)
121+
{
122+
return $this->app->get('jwt.token')->logout($token);
123+
}
114124
}

src/Service/Manager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function wasBan(Token $token): bool
8787

8888
protected function getBlacklist($store, $jti)
8989
{
90+
dump($this->config->getBlacklist());
9091
return $this->getCache($store, $jti, $this->config->getBlacklist());
9192
}
9293

@@ -153,8 +154,8 @@ private function clearCache($store, $type, $uid): void
153154

154155
private function getCache($store, $uid, $type)
155156
{
156-
$key = implode('', [$this->config->getPrefix(), $store, $type, $uid]);
157-
157+
$key = implode(':', [$this->config->getPrefix(), $store, $type, $uid]);
158+
158159
return $this->app->cache->get($key);
159160
}
160161
}

src/Service/Token.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public function verify(string $token): ?bool
187187
throw new TokenAlreadyEexpired('Token 刷新时间已过,请重新登录', $this->config->getReloginCode());
188188
}
189189
} else {
190+
dump($this->app->get('jwt.manager')->wasBan($this->token));
190191
// 是否存在黑名单
191192
if (true === $this->app->get('jwt.manager')->wasBan($this->token)) {
192193
throw new TokenAlreadyEexpired('Token 已被禁用,请重新登录', $this->config->getReloginCode());
@@ -207,6 +208,33 @@ public function verify(string $token): ?bool
207208
return true;
208209
}
209210

211+
public function refresh(string $token = null): JwtToken
212+
{
213+
$token = $token ?: $this->getRequestToken();
214+
$token = $this->parseToken($token);
215+
216+
$claims = $token->getClaims();
217+
218+
unset($claims['iat']);
219+
unset($claims['jti']);
220+
unset($claims['nbf']);
221+
unset($claims['exp']);
222+
unset($claims['iss']);
223+
unset($claims['aud']);
224+
225+
$this->app->get('jwt.manager')->logout($token);
226+
227+
return $this->make($claims);
228+
}
229+
230+
public function logout(?string $token = null): void
231+
{
232+
$token = $token ?: $this->getRequestToken();
233+
$token = $this->parseToken($token);
234+
235+
$this->app->get('jwt.manager')->logout($token);
236+
}
237+
210238
/**
211239
* 自动获取请求下的Token.
212240
*

0 commit comments

Comments
 (0)