提交 19ec5650 编写于 作者: 智布道's avatar 智布道 👁

🍻 增加微博授权登录的revoke方法,支持手动回收授权

上级 028924ec
...@@ -47,6 +47,11 @@ public enum AuthDefaultSource implements AuthSource { ...@@ -47,6 +47,11 @@ public enum AuthDefaultSource implements AuthSource {
public String userInfo() { public String userInfo() {
return "https://api.weibo.com/2/users/show.json"; return "https://api.weibo.com/2/users/show.json";
} }
@Override
public String revoke() {
return "https://api.weibo.com/oauth2/revokeoauth2";
}
}, },
/** /**
* gitee * gitee
......
...@@ -6,9 +6,11 @@ import com.alibaba.fastjson.JSONObject; ...@@ -6,9 +6,11 @@ import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache; import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource; import me.zhyd.oauth.config.AuthDefaultSource;
import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender; import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.IpUtils; import me.zhyd.oauth.utils.IpUtils;
...@@ -90,4 +92,16 @@ public class AuthWeiboRequest extends AuthDefaultRequest { ...@@ -90,4 +92,16 @@ public class AuthWeiboRequest extends AuthDefaultRequest {
.queryParam("uid", authToken.getUid()) .queryParam("uid", authToken.getUid())
.build(); .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();
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册