diff --git a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java index 4ed466c4623b03740a5414d36207272c3e291c05..a029f668aa41152e3dae99520314a9aae5cfb6b0 100644 --- a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java +++ b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java @@ -47,6 +47,11 @@ public enum AuthDefaultSource implements AuthSource { public String userInfo() { return "https://api.weibo.com/2/users/show.json"; } + + @Override + public String revoke() { + return "https://api.weibo.com/oauth2/revokeoauth2"; + } }, /** * gitee diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java index 5b71d9df449aa18f8248fb46055f6a6b3e9f164a..8b38c8c1cea12a576075181a4eb0479e0ac1f4ae 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java @@ -6,9 +6,11 @@ import com.alibaba.fastjson.JSONObject; import me.zhyd.oauth.cache.AuthStateCache; import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthDefaultSource; +import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.model.AuthCallback; +import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.utils.IpUtils; @@ -90,4 +92,16 @@ public class AuthWeiboRequest extends AuthDefaultRequest { .queryParam("uid", authToken.getUid()) .build(); } + + @Override + public AuthResponse revoke(AuthToken authToken) { + HttpResponse response = doGetRevoke(authToken); + JSONObject object = JSONObject.parseObject(response.body()); + if (object.containsKey("error")) { + return AuthResponse.builder().code(AuthResponseStatus.FAILURE.getCode()).msg(object.getString("error")).build(); + } + // 返回 result = true 表示取消授权成功,否则失败 + AuthResponseStatus status = object.getBooleanValue("result") ? AuthResponseStatus.SUCCESS : AuthResponseStatus.FAILURE; + return AuthResponse.builder().code(status.getCode()).msg(status.getMsg()).build(); + } }