feat(oauth2): 增加回收 Refresh-Token 方法: revokeRefreshTokenrevokeRefreshTokenByIndex

This commit is contained in:
click33 2024-11-26 18:36:29 +08:00
parent d1a0402c52
commit a8851cf54d
2 changed files with 50 additions and 0 deletions

View File

@ -521,6 +521,38 @@ public class SaOAuth2Template {
return SaOAuth2Manager.getDao().getRefreshTokenValue(clientId, loginId);
}
/**
* 回收 Refresh-Token
* @param refreshToken Refresh-Token
*/
public void revokeRefreshToken(String refreshToken) {
RefreshTokenModel rt = getRefreshToken(refreshToken);
if(rt == null) {
return;
}
// rt索引
SaOAuth2Dao dao = SaOAuth2Manager.getDao();
dao.deleteRefreshToken(refreshToken);
dao.deleteRefreshTokenIndex(rt.clientId, rt.loginId);
}
/**
* 回收 Refresh-Token根据索引 clientIdloginId
* @param clientId /
* @param loginId /
*/
public void revokeRefreshTokenByIndex(String clientId, Object loginId) {
SaOAuth2Dao dao = SaOAuth2Manager.getDao();
// rt删索引
String refreshToken = getRefreshTokenValue(clientId, loginId);
if(refreshToken != null) {
dao.deleteRefreshToken(refreshToken);
dao.deleteRefreshTokenIndex(clientId, loginId);
}
}
/**
* 根据 RefreshToken 刷新出一个 AccessToken
* @param refreshToken /

View File

@ -16,6 +16,7 @@
package cn.dev33.satoken.oauth2.template;
import cn.dev33.satoken.oauth2.SaOAuth2Manager;
import cn.dev33.satoken.oauth2.dao.SaOAuth2Dao;
import cn.dev33.satoken.oauth2.data.model.AccessTokenModel;
import cn.dev33.satoken.oauth2.data.model.ClientTokenModel;
import cn.dev33.satoken.oauth2.data.model.RefreshTokenModel;
@ -242,6 +243,23 @@ public class SaOAuth2Util {
return SaOAuth2Manager.getTemplate().getRefreshTokenValue(clientId, loginId);
}
/**
* 回收 Refresh-Token
* @param refreshToken Refresh-Token
*/
public static void revokeRefreshToken(String refreshToken) {
SaOAuth2Manager.getTemplate().revokeRefreshToken(refreshToken);
}
/**
* 回收 Refresh-Token根据索引 clientIdloginId
* @param clientId /
* @param loginId /
*/
public static void revokeRefreshTokenByIndex(String clientId, Object loginId) {
SaOAuth2Manager.getTemplate().revokeRefreshTokenByIndex(clientId, loginId);
}
/**
* 根据 RefreshToken 刷新出一个 AccessToken
* @param refreshToken /