Skip to content

Commit

Permalink
🐛 Fixing a bug. token endpoint 问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lltx committed Mar 8, 2024
1 parent 99384b2 commit 9dde37b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public R<Boolean> logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, requi
}

String tokenValue = authHeader.replace(OAuth2AccessToken.TokenType.BEARER.getValue(), StrUtil.EMPTY).trim();
return removeToken(tokenValue);
return removeToken(new String[]{tokenValue});
}

/**
Expand Down Expand Up @@ -170,25 +170,26 @@ public void checkToken(String token, HttpServletResponse response, HttpServletRe
* 令牌管理调用
* @param token token
*/
@Inner
@DeleteMapping("/{token}")
public R<Boolean> removeToken(@PathVariable("token") String token) {
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
if (authorization == null) {
return R.ok();
}
@DeleteMapping("/delete")
public R<Boolean> removeToken(@RequestBody String[] accessTokens) {
for (String token : accessTokens) {
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
if (authorization == null) {
return R.ok();
}

OAuth2Authorization.Token<OAuth2AccessToken> accessToken = authorization.getAccessToken();
if (accessToken == null || StrUtil.isBlank(accessToken.getToken().getTokenValue())) {
return R.ok();
OAuth2Authorization.Token<OAuth2AccessToken> accessToken = authorization.getAccessToken();
if (accessToken == null || StrUtil.isBlank(accessToken.getToken().getTokenValue())) {
return R.ok();
}
// 清空用户信息
cacheManager.getCache(CacheConstants.USER_DETAILS).evict(authorization.getPrincipalName());
// 清空access token
authorizationService.remove(authorization);
// 处理自定义退出事件,保存相关日志
SpringContextHolder.publishEvent(new LogoutSuccessEvent(new PreAuthenticatedAuthenticationToken(
authorization.getPrincipalName(), authorization.getRegisteredClientId())));
}
// 清空用户信息(立即删除)
cacheManager.getCache(CacheConstants.USER_DETAILS).evictIfPresent(authorization.getPrincipalName());
// 清空access token
authorizationService.remove(authorization);
// 处理自定义退出事件,保存相关日志
SpringContextHolder.publishEvent(new LogoutSuccessEvent(new PreAuthenticatedAuthenticationToken(
authorization.getPrincipalName(), authorization.getRegisteredClientId())));
return R.ok();
}

Expand All @@ -197,7 +198,6 @@ public R<Boolean> removeToken(@PathVariable("token") String token) {
* @param params 分页参数
* @return
*/
@Inner
@PostMapping("/page")
public R<Page> tokenList(@RequestBody Map<String, Object> params) {
// 根据分页参数获取对应数据
Expand Down

This file was deleted.

0 comments on commit 9dde37b

Please sign in to comment.