From 19ec5650045de57130e2a567ae96eda88f2b4cbc Mon Sep 17 00:00:00 2001 From: "yadong.zhang" Date: Sun, 22 Dec 2019 20:02:26 +0800 Subject: [PATCH] =?UTF-8?q?:beers:=20=E5=A2=9E=E5=8A=A0=E5=BE=AE=E5=8D=9A?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E5=BD=95=E7=9A=84revoke=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E6=94=AF=E6=8C=81=E6=89=8B=E5=8A=A8=E5=9B=9E?= =?UTF-8?q?=E6=94=B6=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/zhyd/oauth/config/AuthDefaultSource.java | 5 +++++ .../me/zhyd/oauth/request/AuthWeiboRequest.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java index 4ed466c..a029f66 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 5b71d9d..8b38c8c 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(); + } } -- GitLab