diff --git a/sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/template/SaOAuth2Template.java b/sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/template/SaOAuth2Template.java index 5ce1b8fb..71b8b277 100644 --- a/sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/template/SaOAuth2Template.java +++ b/sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/template/SaOAuth2Template.java @@ -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,根据索引: clientId、loginId + * @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 / diff --git a/sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/template/SaOAuth2Util.java b/sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/template/SaOAuth2Util.java index a59077e4..17e7d88a 100644 --- a/sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/template/SaOAuth2Util.java +++ b/sa-token-plugin/sa-token-oauth2/src/main/java/cn/dev33/satoken/oauth2/template/SaOAuth2Util.java @@ -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,根据索引: clientId、loginId + * @param clientId / + * @param loginId / + */ + public static void revokeRefreshTokenByIndex(String clientId, Object loginId) { + SaOAuth2Manager.getTemplate().revokeRefreshTokenByIndex(clientId, loginId); + } + /** * 根据 RefreshToken 刷新出一个 AccessToken * @param refreshToken /