diff --git a/docs/_media/oauth/weibo_01.png b/docs/_media/oauth/weibo_01.png new file mode 100644 index 0000000000000000000000000000000000000000..9c2903861a3b1cdedfcc1acb5b7987a8cf67c33d Binary files /dev/null and b/docs/_media/oauth/weibo_01.png differ diff --git a/docs/_media/oauth/weibo_02.png b/docs/_media/oauth/weibo_02.png new file mode 100644 index 0000000000000000000000000000000000000000..4b39e41e8a8961d89ec5a6cbbf803f68a73b5292 Binary files /dev/null and b/docs/_media/oauth/weibo_02.png differ diff --git a/docs/_media/oauth/weibo_03.png b/docs/_media/oauth/weibo_03.png new file mode 100644 index 0000000000000000000000000000000000000000..43e8a3819ce399c0d27785fd7a5572ed8dbf0938 Binary files /dev/null and b/docs/_media/oauth/weibo_03.png differ diff --git a/docs/_media/oauth/weibo_04.png b/docs/_media/oauth/weibo_04.png new file mode 100644 index 0000000000000000000000000000000000000000..88c2687580c6b8829da362e4eb50244ddd2c57c3 Binary files /dev/null and b/docs/_media/oauth/weibo_04.png differ diff --git a/docs/_media/oauth/weibo_05.png b/docs/_media/oauth/weibo_05.png new file mode 100644 index 0000000000000000000000000000000000000000..1d227a999439dfe43d8a407b9a28e5dde25b1ee2 Binary files /dev/null and b/docs/_media/oauth/weibo_05.png differ diff --git a/docs/_media/oauth/weibo_06.png b/docs/_media/oauth/weibo_06.png new file mode 100644 index 0000000000000000000000000000000000000000..c4e89c9df0bee469d89e873c725c6a1c107c1569 Binary files /dev/null and b/docs/_media/oauth/weibo_06.png differ diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 65ccdcf167e00421d11725784becd402ae787624..410643ffd7ca2579bf93cc9e61cf074dc6f6250f 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -10,14 +10,14 @@ - [√ Github登录](oauth/github.md) - [√ qq登录](oauth/qq.md) - [√ 微信登录](oauth/wechat.md) - - [微博登录](oauth/weibo.md) + - [√ 微博登录](oauth/weibo.md) - [√ 支付宝登录](oauth/alipay.md) - [百度登录](oauth/baidu.md) - [Coding登录](oauth/coding.md) - [钉钉登录](oauth/dingtalk.md) - [开源中国登录](oauth/oschina.md) - [淘宝登录](oauth/taobao.md) - - [腾讯云登录](oauth/tenchentCloud.md) + - [腾讯云登录](oauth/tencentCloud.md) - [Google登录](oauth/google.md) - [Facebook登录](oauth/facebook.md) - [抖音登录](oauth/douyin.md) diff --git a/docs/index.html b/docs/index.html index 0b91255734f36ffe694202f8680f5d8308af7a7c..687d057af16158100d0798a6c3f8d2130f75f8b3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -17,11 +17,13 @@ +
Please wait...
- + + diff --git a/docs/oauth/weibo.md b/docs/oauth/weibo.md index 00ff6e4b57c63ff0bf9041d762d4776acca02f47..71717e2a0bb696b0a4a7fcf650cdc5fa5cd16b26 100644 --- a/docs/oauth/weibo.md +++ b/docs/oauth/weibo.md @@ -1,7 +1,153 @@ -(敬请期待...) - ## 1. 申请应用 +### 1.注册微博开放平台账号 +https://open.weibo.com/apps。如果已有则忽略该步骤,直接进入第二步。 +### 2.创建应用 +通过顶部菜单栏的【微连接-网站接入】或者直接点击【[网站接入](https://open.weibo.com/connect)】进入网站接入界面 + +![file](../_media/oauth/weibo_01.png) + +点击【立即接入】按钮进入创建应用页面,填入**应用名称**,**应用分类**选择默认的“网页应用”即可 + +![file](../_media/oauth/weibo_02.png) + +创建完成后会自动跳转到应用信息页面,如下图,根据提示完善应用即可 + +![file](../_media/oauth/weibo_03.png) + +注:全部填写完成后,需要提交审核。 + +提交审核完成后,将Oauth需要用到的数据copy下来(下面截图取自我已经审核通过的应用): + +![file](../_media/oauth/weibo_04.png) + +![file](../_media/oauth/weibo_05.png) + +微博平台的OAuth支持revoke操作,所以会有一个【取消授权回调页】配置。 + ## 2. 集成JustAuth -## 3. 授权结果 \ No newline at end of file + +### 2.1 引入依赖 + +```xml + + me.zhyd.oauth + JustAuth + ${latest.version} + +``` + +`${latest.version}`表示当前最新的版本,可以在[这儿](https://github.com/justauth/JustAuth/releases)获取最新的版本信息。 + +### 2.2 创建Request + +```java +AuthRequest authRequest = new AuthWeiboRequest(AuthConfig.builder() + .clientId("App Key") + .clientSecret("App Secret") + .redirectUri("授权回调页") + .build()); +``` + +### 2.3 生成授权地址 + +我们可以直接使用以下方式生成第三方平台的授权链接: +```java +String authorizeUrl = authRequest.authorize(AuthStateUtils.createState()); +``` +这个链接我们可以直接后台重定向跳转,也可以返回到前端后,前端控制跳转。前端控制的好处就是,可以将第三方的授权页嵌入到iframe中,适配网站设计。 + + +### 2.4 以上完整代码如下 + +```java +import me.zhyd.oauth.config.AuthConfig; +import me.zhyd.oauth.request.AuthWeiboRequest; +import me.zhyd.oauth.request.AuthRequest; +import me.zhyd.oauth.utils.AuthStateUtils; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + + +@RestController +@RequestMapping("/oauth") +public class RestAuthController { + + @RequestMapping("/render") + public void renderAuth(HttpServletResponse response) throws IOException { + AuthRequest authRequest = getAuthRequest(); + response.sendRedirect(authRequest.authorize(AuthStateUtils.createState())); + } + + @RequestMapping("/callback") + public Object login(String code) { + AuthRequest authRequest = getAuthRequest(); + return authRequest.login(code); + } + + @RequestMapping("/revoke/{token}") + public Object revokeAuth(@PathVariable("token") String token) throws IOException { + AuthRequest authRequest = getAuthRequest(); + return authRequest.revoke(AuthToken.builder().accessToken(token).build()); + } + + private AuthRequest getAuthRequest() { + return new AuthWeiboRequest(AuthConfig.builder() + .clientId("App Key") + .clientSecret("App Secret") + .redirectUri("授权回调页") + .build()); + } +} +``` +授权链接访问成功后会看到以下页面内容: +![授权登录](../_media/oauth/weibo_06.png) + +网页登录或者手机扫码登录并授权第三方应用的登录请求后,将会获取到用户的信息 + +## 3. 授权结果 + +```json +{ + "code": 2000, + "msg": null, + "data": { + "uuid": "xxxxxxx", + "username": "七彩狼丿", + "nickname": "七彩狼丿", + "avatar": "https://tva3.sinaimg.cn/crop.0.0.1424.1424.50/649b9a6fjw8ezwz4inarqj213k13kwjh.jpg?KID=imgbed,tva&Expires=1577025808&ssig=Q7m4jDuwUt", + "blog": "https://www.zhyd.me", + "company": null, + "location": "北京 朝阳区", + "email": null, + "remark": "长大了,不得不接受一些事实", + "gender": "MALE", + "source": "WEIBO", + "token": { + "accessToken": "2.xxxxxCNUC", + "expireIn": 157679999, + "refreshToken": null, + "uid": "xxxxxxx", + "openId": "xxxxxxx", + "accessCode": null, + "unionId": null, + "scope": null, + "tokenType": null, + "idToken": null, + "macAlgorithm": null, + "macKey": null, + "code": null, + "oauthToken": null, + "oauthTokenSecret": null, + "userId": null, + "screenName": null, + "oauthCallbackConfirmed": null + } + } +} +``` \ No newline at end of file diff --git a/docs/update.md b/docs/update.md index a3372c7dcd25da7ce769b6d0f01dceffefb3fd57..b546434b490186ac3ae83823a5a56ee8a21639ad 100644 --- a/docs/update.md +++ b/docs/update.md @@ -5,9 +5,12 @@ - `checkState`方法从`AuthDefaultRequest`中提出到`AuthChecker`中 - `AuthResponseStatus`枚举类中增加`ILLEGAL_STATUS`、`REQUIRED_REFRESH_TOKEN`两个枚举值 - `AuthSource`接口中增加`getName`方法,用来对外提供实际`source`的字符串值 -- 增加微信、QQ、支付宝授权登录的帮助文档 +- `AuthWeiboRequest`微博授权登录中实现`revoke`方法,支持手动回收授权 +- 增加微信、QQ、支付宝、微博授权登录的帮助文档 - [帮助文档](https://docs.justauth.whnb.wang)中增加自定义的404页面 - [帮助文档](https://docs.justauth.whnb.wang)中增加Gittalk插件 +- [帮助文档](https://docs.justauth.whnb.wang)中增加Java代码高亮的插件 +- [帮助文档](https://docs.justauth.whnb.wang)中修复[腾讯云登录]链接错误的问题 ## v1.13.1 ### 2019/11/12