Compare commits
84 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 12ec6226bc | |||
| 9a62332f30 | |||
| a962c96a2c | |||
| d442018c02 | |||
| 8d6d4533e4 | |||
| 2f88c23405 | |||
| cf74f811fa | |||
| bb613010dc | |||
| 7ace410351 | |||
| 65daa0592a | |||
| 25424023c4 | |||
| 67579bfb07 | |||
| 458de3840d | |||
| 1c1d2dc9db | |||
| f5de7f93b5 | |||
| dcf5f30e61 | |||
| e534a4b62e | |||
| 42ede32fc5 | |||
| c0dd700b0a | |||
| f32c341b63 | |||
| 82358cbddb | |||
| 56df9bc1b0 | |||
| 438660621e | |||
| 937fba37f5 | |||
| fde490a205 | |||
| da23fcd54c | |||
| 36b5f333a4 | |||
| d5e0ff3f33 | |||
| b3aee449a2 | |||
| f3619f48fe | |||
| e92f8961f5 | |||
| a6ed65ce3d | |||
| 132c682673 | |||
| 4d92794b1a | |||
| ae9edffc70 | |||
| 7a6ff6c8e5 | |||
| b9ca048d1c | |||
| a07dcbd26f | |||
| 3f67757a3a | |||
| c951ffad59 | |||
| 0c672dee2e | |||
| c8617b4d19 | |||
| a5386666bb | |||
| 90f8d01c56 | |||
| 0237cb383b | |||
| e70dae0b85 | |||
| 41cede22ad | |||
| a9b3d61d4d | |||
| 18d650e59a | |||
| 96ada34347 | |||
| 356a1bf826 | |||
| 9e27ef2f8d | |||
| 334574dfe8 | |||
| d978ca9b19 | |||
| 56bca92c59 | |||
| fd9cb530cd | |||
| dfd5c3b07d | |||
| a2cee9879b | |||
| 663efb35fe | |||
| 94045ea81d | |||
| 5ec49c6c77 | |||
| 5e95cf1384 | |||
| fd90a63f40 | |||
| 4a271c583e | |||
| 14fab8cd77 | |||
| 3c0c809dfc | |||
| 6f40460cce | |||
| e81e92130b | |||
| 85afd754a9 | |||
| a8709a30d3 | |||
| ffa48970e5 | |||
| 5d753de282 | |||
| a739ca374e | |||
| 880a7d4157 | |||
| 6fe1aa62c6 | |||
| 7857db7824 | |||
| 7ed248689f | |||
| d24733e016 | |||
| 2dba2baef7 | |||
| 2abca4f10f | |||
| 7db4dcce2a | |||
| 14c2b4cacf | |||
| 54e97b0ec4 | |||
| aa187dd109 |
@@ -26,3 +26,5 @@ hs_err_pid*
|
||||
.idea
|
||||
*.iml
|
||||
*.sh
|
||||
|
||||
target
|
||||
@@ -5,8 +5,8 @@
|
||||
<strong>Login, so easy.</strong>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://search.maven.org/search?q=g:%22me.zhyd%22%20AND%20a:%22JustAuth%22">
|
||||
<img src="https://img.shields.io/badge/Maven Central-1.0.0-blue.svg" ></img>
|
||||
<a target="_blank" href="https://search.maven.org/search?q=JustAuth">
|
||||
<img src="https://img.shields.io/badge/Maven Central-1.7.0-blue.svg" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" ></img>
|
||||
@@ -18,40 +18,28 @@
|
||||
|
||||
<center>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td align="center" width="200"><a href="https://gitee.com/"><img src="https://gitee.com/logo_icon.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://github.com"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/github.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://weibo.com"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/weibo.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://www.dingtalk.com"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingding.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://developer.baidu.com/"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://www.csdn.net/"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://coding.net"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://dev.tencent.com/"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/tencent_cloud.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://www.oschina.net"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschinas.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://www.alipay.com"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/alipay.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://connect.qq.com/devuser.html#/"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_CN"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="https://open.taobao.com/"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/taobao.png" width="20"></a></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center" width="200"><a href="#授权gitee">Gitee</a></td>
|
||||
<td align="center" width="200"><a href="#授权github">Github</a></td>
|
||||
<td align="center" width="200"><a href="#授权weibo">Weibo</a></td>
|
||||
<td align="center" width="200"><a href="#授权钉钉">钉钉</a></td>
|
||||
<td align="center" width="200"><a href="#授权百度">百度</a></td>
|
||||
<td align="center" width="200"><a href="#授权csdn">CSDN</a></td>
|
||||
<td align="center" width="200"><a href="#授权coding">Coding</a></td>
|
||||
<td align="center" width="200"><a href="#授权腾讯云开发者平台" title="coding升级后就变成腾讯云开发者平台了">腾讯云</a></td>
|
||||
<td align="center" width="200"><a href="#授权oschina">OSChina</a></td>
|
||||
<td align="center" width="200"><a href="#授权支付宝">支付宝</a></td>
|
||||
<td align="center" width="200"><a href="#授权qq">QQ</a></td>
|
||||
<td align="center" width="200"><a href="#授权微信">微信</a></td>
|
||||
<td align="center" width="200"><a href="#授权淘宝">淘宝</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tr>
|
||||
<td align="center" width="200"><a href="#授权gitee"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/gitee.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权github"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/github.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权weibo"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/weibo.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权钉钉"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingtalk.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权百度"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权coding"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权腾讯云开发者平台"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/tencentCloud.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权oschina"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschina.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权支付宝"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/alipay.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权qq"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权微信"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权淘宝"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/taobao.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权google"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/google.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权facebook"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/facebook.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权抖音"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/douyin.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权领英"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/linkedin.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权微软"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/microsoft.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权小米"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/mi.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权今日头条"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/toutiao.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权csdn"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png" width="20"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
|
||||
@@ -63,13 +51,21 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
|
||||
|
||||
项目开源地址:[gitee](https://gitee.com/yadong.zhang/JustAuth) | [github](https://github.com/zhangyd-c/JustAuth)
|
||||
|
||||
## 特点
|
||||
|
||||
废话不多说,就俩字:
|
||||
|
||||
1. **全**:已集成十多家第三方平台(国内外常用的基本都已包含),后续依然还有扩展计划!
|
||||
2. **简**:API就是奔着最简单去设计的(见后面`快速开始`),尽量让您用起来没有障碍感!
|
||||
|
||||
## 快速开始
|
||||
|
||||
- 引入依赖
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<version>1.7.0</version>
|
||||
</dependency>
|
||||
```
|
||||
- 调用api
|
||||
@@ -86,6 +82,8 @@ authRequest.authorize();
|
||||
authRequest.login("code");
|
||||
```
|
||||
|
||||
**配套Demo**:[JustAuth-demo](https://gitee.com/yadong.zhang/JustAuth-demo)
|
||||
|
||||
具体的例子可以参考:
|
||||
|
||||
- [实现Gitee授权登录](http://t.cn/ExDKxQs)
|
||||
@@ -94,19 +92,28 @@ authRequest.login("code");
|
||||
#### API列表
|
||||
| :computer: 平台 | :coffee: API类 | :page_facing_up: SDK |
|
||||
|:------:|:-------:|:-------:|
|
||||
| <img src="https://gitee.com/logo_icon.png" width="20"> | [AuthGiteeRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | <a href="https://gitee.com/api/v5/oauth_doc#list_1" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/gitee.png" width="20"> | [AuthGiteeRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | <a href="https://gitee.com/api/v5/oauth_doc#list_1" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/github.png" width="20"> | [AuthGithubRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | <a href="https://github.com/settings/developers" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/weibo.png" width="20"> | [AuthWeiboRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java) | <a href="https://open.weibo.com/wiki/%E5%BE%AE%E5%8D%9AAPI" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingding.png" width="20"> | [AuthDingTalkRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java) | <a href="https://open-doc.dingtalk.com/microapp/serverapi2/kymkv6" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/dingtalk.png" width="20"> | [AuthDingTalkRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java) | <a href="https://open-doc.dingtalk.com/microapp/serverapi2/kymkv6" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png" width="20"> | [AuthBaiduRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java) | <a href="https://developer.baidu.com/" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png" width="25"> | [AuthCodingRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java) | <a href="https://open.coding.net/references/oauth/" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/tencent_cloud.png" width="25"> | [AuthTencentCloudRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java) | <a href="https://dev.tencent.com/help/doc/faq/b4e5b7aee786/oauth" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschinas.png" width="20"> | [AuthOschinaRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java) | <a href="https://www.oschina.net/openapi/docs/openapi_user" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/tencentCloud.png" width="25"> | [AuthTencentCloudRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java) | <a href="https://dev.tencent.com/help/doc/faq/b4e5b7aee786/oauth" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschina.png" width="20"> | [AuthOschinaRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java) | <a href="https://www.oschina.net/openapi/docs/openapi_user" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/alipay.png" width="20"> | [AuthAlipayRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java) | <a href="https://alipay.open.taobao.com/docs/doc.htm?spm=a219a.7629140.0.0.336d4b70GUKXOl&treeId=193&articleId=105809&docType=1" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png" width="20"> | [AuthQqRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java) | <a href="http://wiki.connect.qq.com/" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png" width="20"> | [AuthCsdnRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java) | 待续 |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png" width="20"> | [AuthWeChatRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java) | <a href="https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316505&token=&lang=zh_CN" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20"> | [AuthWeChatRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java) | <a href="https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316505&token=&lang=zh_CN" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/taobao.png" width="20"> | [AuthTaobaoRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java) | <a href="https://open.taobao.com/doc.htm?spm=a219a.7386797.0.0.4e00669acnkQy6&source=search&docId=105590&docType=1" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/google.png" width="20"> | [AuthGoogleRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java) | <a href="https://developers.google.com/identity/protocols/OpenIDConnect" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/facebook.png" width="20"> | [AuthFacebookRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java) | <a href="https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/douyin.png" width="20"> | [AuthDouyinRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java) | <a href="https://www.douyin.com/platform/doc" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/linkedin.png" width="20"> | [AuthLinkedinRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java) | <a href="https://docs.microsoft.com/zh-cn/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/microsoft.png" width="20"> | [AuthMicrosoftRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java) | <a href="https://docs.microsoft.com/zh-cn/graph/auth/" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/mi.png" width="20"> | [AuthMiRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java) | <a href="https://dev.mi.com/console/doc/detail?pId=711" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/toutiao.png" width="20"> | [AuthToutiaoRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java) | <a href="https://open.mp.toutiao.com/#/resource?_k=y7mfgk" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png" width="20"> | [AuthCsdnRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java) | 无 |
|
||||
|
||||
_请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经下线。如果以前申请过的应用,可以继续使用,但是不再支持申请新的应用。so, 本项目中的CSDN登录只能针对少部分用户使用了_
|
||||
|
||||
## 后续开发计划
|
||||
|
||||
@@ -114,81 +121,38 @@ authRequest.login("code");
|
||||
|
||||
另外,期待您和我一起完善这个项目!
|
||||
|
||||
## 贡献代码
|
||||
|
||||
1. fork本项目到自己的repo
|
||||
2. 把fork过去的项目也就是你仓库中的项目clone到你的本地
|
||||
3. 修改代码
|
||||
4. commit后push到自己的库
|
||||
5. 发起PR(pull request) 请求
|
||||
6. 等待作者合并
|
||||
|
||||
## 致谢
|
||||
|
||||
在项目立项初期,也对当前开源圈的一些相同类型的项目作过调研,同时本项目也参考过这些项目,再次感谢开源圈内的朋友。
|
||||
|
||||
[YurunOAuthLogin](https://gitee.com/yurunsoft/YurunOAuthLogin): PHP 第三方登录授权 SDK
|
||||
|
||||
[阿里妈妈MUX倾力打造的矢量图标库-iconfont](https://www.iconfont.cn/search/index): 本文档中的图标大部分取自该平台
|
||||
|
||||
## 参考图例
|
||||
## 关注&交流
|
||||
|
||||
#### 授权gitee
|
||||
|
||||

|
||||
|
||||
#### 授权github
|
||||
|
||||

|
||||
|
||||
#### 授权weibo
|
||||
|
||||

|
||||
|
||||
#### 授权钉钉
|
||||
|
||||

|
||||
|
||||
#### 授权百度
|
||||
|
||||

|
||||
|
||||
#### 授权coding
|
||||
|
||||

|
||||
|
||||
#### 授权腾讯云开发者平台
|
||||
|
||||

|
||||
|
||||
#### 授权oschina
|
||||
|
||||

|
||||
|
||||
#### 授权支付宝
|
||||
|
||||

|
||||
|
||||
#### 授权qq
|
||||
|
||||
待续
|
||||
|
||||
#### 授权csdn
|
||||
|
||||
待续
|
||||
|
||||
#### 授权微信
|
||||
|
||||
待续
|
||||
|
||||
#### 授权淘宝
|
||||
|
||||
待续
|
||||
|
||||
# 交流
|
||||
|
||||
| 微信(备注:加群) | 公众号 |
|
||||
| 公众号 | 微信(备注:加群) |
|
||||
| :------------: | :------------: |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/wx/wx.png" width="170"/> | <img src="https://gitee.com/yadong.zhang/static/raw/master/wx/wechat_account.jpg" width="200" /> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/wx/wechat_account.jpg" width="200" /> | <img src="https://gitee.com/yadong.zhang/static/raw/master/wx/wx.png" width="170"/> |
|
||||
|
||||
**QQ群**
|
||||
|
||||
[](https://shang.qq.com/wpa/qunwpa?idkey=3571c554a143eff1e15807de033a240196c6b493b25b903d1d37571cfb6040aa)
|
||||
- JustAuth交流群 (230017570):专业交流该项目
|
||||
|
||||
- 开源总群 (190886500):各个开源项目的都有,也有博客建设等方面的朋友。(注意,该群需付费进入,防止发垃圾广告、垃圾推广等人士)
|
||||
|
||||
|
||||
## 请喝咖啡
|
||||
|
||||
| 支付宝 | 微信 |
|
||||
| :------------: | :------------: |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/qrcode/zfb_code.png" width="200"/> | <img src="https://gitee.com/yadong.zhang/static/raw/master/qrcode/wx_code.png" width="200" /> |
|
||||
|
||||
| 支付宝 | 微信 |
|
||||
| :------------: | :------------: |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/qrcode/zfb_code.png" width="200"/> | <img src="https://gitee.com/yadong.zhang/static/raw/master/qrcode/wx_code.png" width="200" /> |
|
||||
@@ -0,0 +1,6 @@
|
||||
# 项目贡献者名单
|
||||
|
||||
- <img src="https://avatar.gitee.com/uploads/99/784199_yadong.zhang.png!avatar100?1462325358" width="20"> · yadong.zhang : <a href="https://github.com/zhangyd-c" target="_blank">[Github]</a> | <a href="https://gitee.com/yadong.zhang" target="_blank">[Gitee]</a> | <a href="https://www.zhyd.me" target="_blank">[个人网站]</a>
|
||||
- <img src="https://avatars0.githubusercontent.com/u/10429917?s=460&v=4" width="20"> · yangkai.shen : <a href="https://github.com/xkcoding" target="_blank">[Github]</a> | <a href="https://xkcoding.com" target="_blank">[个人网站]</a>
|
||||
- <img src="https://avatar.gitee.com/uploads/51/1651_dolphinboy.png!avatar100?1479346570" width="20"> · skqing : <a href="https://gitee.com/skqing" target="_blank">[Gitee]</a> | <a href="https://my.oschina.net/dolphinboy" target="_blank">[个人网站]</a>
|
||||
- 千年等一回,我只为等你...
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
## 各平台授权页面示例
|
||||
|
||||
_注:非全部平台,部分平台可能不存在图例_
|
||||
|
||||
#### 授权gitee
|
||||
|
||||

|
||||
|
||||
#### 授权github
|
||||
|
||||

|
||||
|
||||
#### 授权weibo
|
||||
|
||||

|
||||
|
||||
#### 授权钉钉
|
||||
|
||||

|
||||
|
||||
#### 授权百度
|
||||
|
||||

|
||||
|
||||
#### 授权coding
|
||||
|
||||

|
||||
|
||||
#### 授权腾讯云开发者平台
|
||||
|
||||

|
||||
|
||||
#### 授权oschina
|
||||
|
||||

|
||||
|
||||
#### 授权支付宝
|
||||
|
||||

|
||||
|
||||
#### 授权qq
|
||||
|
||||
暂无
|
||||
|
||||
#### 授权微信
|
||||
|
||||

|
||||
|
||||
#### 授权淘宝
|
||||
|
||||

|
||||
|
||||
|
||||
#### 授权Google
|
||||
|
||||

|
||||
|
||||
#### 授权Facebook
|
||||
|
||||

|
||||
|
||||
#### 授权抖音
|
||||
|
||||
暂无
|
||||
|
||||
#### 授权领英
|
||||
|
||||

|
||||
|
||||
|
||||
#### 授权微软
|
||||
|
||||
暂无
|
||||
|
||||
#### 授权小米
|
||||
|
||||
暂无
|
||||
|
||||
#### 授权今日头条
|
||||
|
||||
暂无
|
||||
|
||||
#### 授权csdn
|
||||
|
||||
暂无
|
||||
|
||||
_请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经下线。如果以前申请过的应用,可以继续使用,但是不再支持申请新的应用。so, 本项目中的CSDN登录只能针对少部分用户使用了_
|
||||
@@ -6,11 +6,14 @@
|
||||
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<version>1.7.0</version>
|
||||
|
||||
<name>JustAuth</name>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth</url>
|
||||
<description>史上最全的整合第三方登录的工具, Just Auth</description>
|
||||
<description>
|
||||
史上最全的整合第三方登录的工具,目前已支持Github、Gitee、微博、钉钉、百度、Coding、腾讯云开发者平台、OSChina、支付宝、QQ、微信、淘宝、Google、Facebook、抖音、领英、小米、微软和今日头条等第三方平台的授权登录。
|
||||
Login, so easy!
|
||||
</description>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
@@ -77,12 +80,6 @@
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson-version}</version>
|
||||
</dependency>
|
||||
<!--<dependency>
|
||||
<groupId>com.google.api-client</groupId>
|
||||
<artifactId>google-api-client</artifactId>
|
||||
<version>${google-api-version}</version>
|
||||
</dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alipay.sdk</groupId>
|
||||
<artifactId>alipay-sdk-java</artifactId>
|
||||
@@ -117,12 +114,10 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Javadoc -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
<!-- GPG -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
@@ -134,7 +129,6 @@
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Source -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
@@ -149,7 +143,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Javadoc -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
@@ -162,7 +155,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- GPG -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package me.zhyd.oauth.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* JustAuth配置类
|
||||
@@ -12,6 +9,7 @@ import lombok.NoArgsConstructor;
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
|
||||
+156
-119
@@ -1,4 +1,4 @@
|
||||
package me.zhyd.oauth.consts;
|
||||
package me.zhyd.oauth.config;
|
||||
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.request.ResponseStatus;
|
||||
@@ -10,7 +10,7 @@ import me.zhyd.oauth.request.ResponseStatus;
|
||||
* @version 1.0
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum ApiUrl {
|
||||
public enum AuthSource {
|
||||
/**
|
||||
* Github
|
||||
*/
|
||||
@@ -29,16 +29,6 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
return "https://api.github.com/user";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 新浪微博
|
||||
@@ -58,16 +48,6 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
return "https://api.weibo.com/2/users/show.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* gitee
|
||||
@@ -87,16 +67,6 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
return "https://gitee.com/api/v5/user";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 钉钉
|
||||
@@ -116,16 +86,6 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
return "https://oapi.dingtalk.com/sns/getuserinfo_bycode";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 百度
|
||||
@@ -150,11 +110,6 @@ public enum ApiUrl {
|
||||
public String revoke() {
|
||||
return "https://openapi.baidu.com/rest/2.0/passport/auth/revokeAuthorization";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* csdn
|
||||
@@ -174,16 +129,6 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
return "https://api.csdn.net/user/getinfo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Coding
|
||||
@@ -203,21 +148,11 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
return "https://coding.net/api/account/current_user";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 腾讯云开发者平台(coding升级后就变成腾讯云开发者平台了)
|
||||
*/
|
||||
TENCENTCLOUD {
|
||||
TENCENT_CLOUD {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://dev.tencent.com/oauth_authorize.html";
|
||||
@@ -232,16 +167,6 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
return "https://dev.tencent.com/api/account/current_user";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* oschina 开源中国
|
||||
@@ -261,16 +186,6 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
return "https://www.oschina.net/action/openapi/user";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 支付宝
|
||||
@@ -290,16 +205,6 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
return "https://openapi.alipay.com/gateway.do";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* QQ
|
||||
@@ -319,16 +224,6 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
return "https://graph.qq.com/user/get_user_info";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 微信
|
||||
@@ -349,11 +244,6 @@ public enum ApiUrl {
|
||||
return "https://api.weixin.qq.com/sns/userinfo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
return "https://api.weixin.qq.com/sns/oauth2/refresh_token";
|
||||
@@ -377,15 +267,158 @@ public enum ApiUrl {
|
||||
public String userInfo() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Google
|
||||
*/
|
||||
GOOGLE {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://accounts.google.com/o/oauth2/v2/auth";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
public String accessToken() {
|
||||
return "https://www.googleapis.com/oauth2/v4/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://oauth2.googleapis.com/tokeninfo";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Facebook
|
||||
*/
|
||||
FACEBOOK {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://www.facebook.com/v3.3/dialog/oauth";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://graph.facebook.com/v3.3/oauth/access_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://graph.facebook.com/v3.3/me";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 抖音
|
||||
*/
|
||||
DOUYIN {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://open.douyin.com/platform/oauth/connect";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://open.douyin.com/oauth/access_token/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://open.douyin.com/oauth/userinfo/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
return "https://open.douyin.com/oauth/refresh_token";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 领英
|
||||
*/
|
||||
LINKEDIN {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://www.linkedin.com/oauth/v2/authorization";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://www.linkedin.com/oauth/v2/accessToken";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://api.linkedin.com/v2/me";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
return "https://www.linkedin.com/oauth/v2/accessToken";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 微软
|
||||
*/
|
||||
MICROSOFT {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://login.microsoftonline.com/common/oauth2/v2.0/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://graph.microsoft.com/v1.0/me";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
return "https://login.microsoftonline.com/common/oauth2/v2.0/token";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 小米
|
||||
*/
|
||||
MI {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://account.xiaomi.com/oauth2/authorize";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://account.xiaomi.com/oauth2/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://open.account.xiaomi.com/user/profile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
return "https://account.xiaomi.com/oauth2/token";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 今日头条
|
||||
*/
|
||||
TOUTIAO {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://open.snssdk.com/auth/authorize";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://open.snssdk.com/auth/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://open.snssdk.com/data/user_profile";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -415,13 +448,17 @@ public enum ApiUrl {
|
||||
*
|
||||
* @return url
|
||||
*/
|
||||
public abstract String revoke();
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新授权的api
|
||||
*
|
||||
* @return url
|
||||
*/
|
||||
public abstract String refresh();
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package me.zhyd.oauth.model;
|
||||
import me.zhyd.oauth.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* 百度授权登录时的异常状态码
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package me.zhyd.oauth.model;
|
||||
|
||||
/**
|
||||
* 钉钉授权登录时的异常状态码
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum AuthDingTalkErrorCode {
|
||||
/**
|
||||
* 异常状态码
|
||||
*/
|
||||
EC1_MINUS(-1, "系统繁忙", "服务器暂不可用,建议稍候再重试1次,最多重试3次"),
|
||||
EC0(0, "请求成功", "接口调用成功"),
|
||||
EC404(404, "请求的URI地址不存在", "地址不存在,检查下url是否和文档里写的一致"),
|
||||
|
||||
@@ -5,6 +5,8 @@ import lombok.Data;
|
||||
import me.zhyd.oauth.request.ResponseStatus;
|
||||
|
||||
/**
|
||||
* JustAuth统一授权响应类
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
@@ -12,7 +14,27 @@ import me.zhyd.oauth.request.ResponseStatus;
|
||||
@Builder
|
||||
@Data
|
||||
public class AuthResponse<T> {
|
||||
private int code = ResponseStatus.SUCCESS.getCode();
|
||||
private String msg = ResponseStatus.SUCCESS.getMsg();
|
||||
/**
|
||||
* 授权响应状态码
|
||||
*/
|
||||
private int code;
|
||||
|
||||
/**
|
||||
* 授权响应信息
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 授权响应数据,当且仅当 code = 2000 时返回
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 是否请求成功
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
public boolean ok() {
|
||||
return this.code == ResponseStatus.SUCCESS.getCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package me.zhyd.oauth.model;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum AuthSource {
|
||||
GITHUB,
|
||||
GITEE,
|
||||
WEIBO,
|
||||
DINGTALK,
|
||||
BAIDU,
|
||||
CSDN,
|
||||
CODING,
|
||||
OSCHINA,
|
||||
TENCEN_CLOUD,
|
||||
ALIPAY,
|
||||
TAOBAO,
|
||||
QQ,
|
||||
WECHAT,
|
||||
GOOGLE,
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 授权所需的token
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
@@ -17,4 +19,19 @@ public class AuthToken {
|
||||
private String uid;
|
||||
private String openId;
|
||||
private String accessCode;
|
||||
private String unionId;
|
||||
|
||||
/**
|
||||
* Google附带属性
|
||||
*/
|
||||
private String scope;
|
||||
private String tokenType;
|
||||
private String idToken;
|
||||
|
||||
/**
|
||||
* 小米附带属性
|
||||
*/
|
||||
private String macAlgorithm;
|
||||
private String macKey;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package me.zhyd.oauth.model;
|
||||
|
||||
/**
|
||||
* 今日头条授权登录时的异常状态码
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum AuthToutiaoErrorCode {
|
||||
EC0(0, "接口调用成功"),
|
||||
EC1(1, "API配置错误,未传入Client Key"),
|
||||
EC2(2, "API配置错误,Client Key错误,请检查是否和开放平台的ClientKey一致"),
|
||||
EC3(3, "没有授权信息"),
|
||||
EC4(4, "响应类型错误"),
|
||||
EC5(5, "授权类型错误"),
|
||||
EC6(6, "client_secret错误"),
|
||||
EC7(7, "authorize_code过期"),
|
||||
EC8(8, "指定url的scheme不是https"),
|
||||
EC9(9, "接口内部错误,请联系头条技术"),
|
||||
EC10(10, "access_token过期"),
|
||||
EC11(11, "缺少access_token"),
|
||||
EC12(12, "参数缺失"),
|
||||
EC13(13, "url错误"),
|
||||
EC21(21, "域名与登记域名不匹配"),
|
||||
EC999(999, "未知错误,请联系头条技术"),
|
||||
;
|
||||
|
||||
private int code;
|
||||
private String desc;
|
||||
|
||||
AuthToutiaoErrorCode(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public static AuthToutiaoErrorCode getErrorCode(int errorCode) {
|
||||
AuthToutiaoErrorCode[] errorCodes = AuthToutiaoErrorCode.values();
|
||||
for (AuthToutiaoErrorCode code : errorCodes) {
|
||||
if (code.getCode() == errorCode) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return EC999;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,11 @@ package me.zhyd.oauth.model;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
|
||||
/**
|
||||
* 授权成功后的用户信息,根据授权平台的不同,获取的数据完整性也不同
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
@@ -11,15 +14,52 @@ import lombok.Data;
|
||||
@Builder
|
||||
@Data
|
||||
public class AuthUser {
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
private String avatar;
|
||||
private String blog;
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickname;
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
private String avatar;
|
||||
/**
|
||||
* 用户网址
|
||||
*/
|
||||
private String blog;
|
||||
/**
|
||||
* 所在公司
|
||||
*/
|
||||
private String company;
|
||||
/**
|
||||
* 位置
|
||||
*/
|
||||
private String location;
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
private String email;
|
||||
/**
|
||||
* 用户备注(各平台中的用户个人介绍)
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
private AuthUserGender gender;
|
||||
/**
|
||||
* 用户来源
|
||||
*/
|
||||
private AuthSource source;
|
||||
/**
|
||||
* 用户授权的token信息
|
||||
*/
|
||||
private AuthToken token;
|
||||
/**
|
||||
* 用户第三方系统的唯一id。在调用方集成改组件时,可以用uuid + source唯一确定一个用户
|
||||
*/
|
||||
private String uuid;
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@ package me.zhyd.oauth.model;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 用户性别
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum AuthUserGender {
|
||||
MALE(1, "男"), FEMALE(0, "女"), UNKNOW(-1, "");
|
||||
MALE(1, "男"), FEMALE(0, "女"), UNKNOW(-1, "未知");
|
||||
private int code;
|
||||
private String desc;
|
||||
|
||||
|
||||
@@ -8,13 +8,13 @@ import com.alipay.api.request.AlipayUserInfoShareRequest;
|
||||
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
||||
import com.alipay.api.response.AlipayUserInfoShareResponse;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.consts.ApiUrl;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.StringUtils;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 支付宝登录
|
||||
@@ -29,7 +29,8 @@ public class AuthAlipayRequest extends BaseAuthRequest {
|
||||
|
||||
public AuthAlipayRequest(AuthConfig config) {
|
||||
super(config, AuthSource.ALIPAY);
|
||||
this.alipayClient = new DefaultAlipayClient(ApiUrl.ALIPAY.accessToken(), config.getClientId(), config.getClientSecret(), "json", "UTF-8", config.getAlipayPublicKey(), "RSA2");
|
||||
this.alipayClient = new DefaultAlipayClient(AuthSource.ALIPAY.accessToken(), config.getClientId(), config.getClientSecret(), "json", "UTF-8", config
|
||||
.getAlipayPublicKey(), "RSA2");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,6 +49,9 @@ public class AuthAlipayRequest extends BaseAuthRequest {
|
||||
}
|
||||
return AuthToken.builder()
|
||||
.accessToken(response.getAccessToken())
|
||||
.uid(response.getUserId())
|
||||
.expireIn(Integer.parseInt(response.getExpiresIn()))
|
||||
.refreshToken(response.getRefreshToken())
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -64,16 +68,30 @@ public class AuthAlipayRequest extends BaseAuthRequest {
|
||||
if (!response.isSuccess()) {
|
||||
throw new AuthException(response.getSubMsg());
|
||||
}
|
||||
|
||||
String province = response.getProvince(),
|
||||
city = response.getCity();
|
||||
String location = String.format("%s %s", StringUtils.isEmpty(province) ? "" : province, StringUtils.isEmpty(city) ? "" : city);
|
||||
|
||||
return AuthUser.builder()
|
||||
.username(response.getUserName())
|
||||
.uuid(response.getUserId())
|
||||
.username(StringUtils.isEmpty(response.getUserName()) ? response.getNickName() : response.getUserName())
|
||||
.nickname(response.getNickName())
|
||||
.avatar(response.getAvatar())
|
||||
.location(String.format("%s %s", StringUtils.isEmpty(province) ? "" : province, StringUtils.isEmpty(city) ? "" : city))
|
||||
.location(location)
|
||||
.gender(AuthUserGender.getRealGender(response.getGender()))
|
||||
.token(authToken)
|
||||
.source(AuthSource.ALIPAY)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getAlipayAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package me.zhyd.oauth.request;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.*;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
@@ -24,16 +24,15 @@ public class AuthBaiduRequest extends BaseAuthRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getBaiduAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
String accessTokenUrl = UrlBuilder.getBaiduAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
|
||||
.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
AuthBaiduErrorCode errorCode = AuthBaiduErrorCode.getErrorCode(accessTokenObject.getString("error"));
|
||||
if (!AuthBaiduErrorCode.OK.equals(errorCode)) {
|
||||
throw new AuthException(errorCode.getDesc());
|
||||
}
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.build();
|
||||
return AuthToken.builder().accessToken(accessTokenObject.getString("access_token")).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,6 +46,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
|
||||
throw new AuthException(errorCode.getDesc());
|
||||
}
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("userid"))
|
||||
.username(object.getString("username"))
|
||||
.nickname(object.getString("username"))
|
||||
.gender(AuthUserGender.getRealGender(object.getString("sex")))
|
||||
@@ -55,13 +55,23 @@ public class AuthBaiduRequest extends BaseAuthRequest {
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getBaiduAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse revoke(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getBaiduRevokeUrl(accessToken)).execute();
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
if(object.containsKey("error_code")) {
|
||||
if (object.containsKey("error_code")) {
|
||||
return AuthResponse.builder()
|
||||
.code(ResponseStatus.FAILURE.getCode())
|
||||
.msg(object.getString("error_msg"))
|
||||
|
||||
@@ -4,8 +4,8 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
@@ -32,9 +32,7 @@ public class AuthCodingRequest extends BaseAuthRequest {
|
||||
if (accessTokenObject.getIntValue("code") != 0) {
|
||||
throw new AuthException("Unable to get token from coding using code [" + code + "]");
|
||||
}
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.build();
|
||||
return AuthToken.builder().accessToken(accessTokenObject.getString("access_token")).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,8 +43,10 @@ public class AuthCodingRequest extends BaseAuthRequest {
|
||||
if (object.getIntValue("code") != 0) {
|
||||
throw new AuthException(object.getString("msg"));
|
||||
}
|
||||
|
||||
object = object.getJSONObject("data");
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("id"))
|
||||
.username(object.getString("name"))
|
||||
.avatar("https://coding.net/" + object.getString("avatar"))
|
||||
.blog("https://coding.net/" + object.getString("path"))
|
||||
@@ -60,4 +60,14 @@ public class AuthCodingRequest extends BaseAuthRequest {
|
||||
.source(AuthSource.CODING)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getCodingAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
@@ -25,15 +26,14 @@ public class AuthCsdnRequest extends BaseAuthRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getCsdnAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
String accessTokenUrl = UrlBuilder.getCsdnAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
|
||||
.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
if (accessTokenObject.containsKey("error_code")) {
|
||||
throw new AuthException("Unable to get token from csdn using code [" + code + "]");
|
||||
}
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.build();
|
||||
return AuthToken.builder().accessToken(accessTokenObject.getString("access_token")).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,9 +45,23 @@ public class AuthCsdnRequest extends BaseAuthRequest {
|
||||
throw new AuthException(object.getString("error"));
|
||||
}
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("username"))
|
||||
.username(object.getString("username"))
|
||||
.remark(object.getString("description"))
|
||||
.blog(object.getString("website"))
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
.token(authToken)
|
||||
.source(AuthSource.CSDN)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getCsdnAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,18 @@ package me.zhyd.oauth.request;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthDingTalkErrorCode;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.GlobalAuthUtil;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 钉钉登录
|
||||
*
|
||||
@@ -29,31 +29,48 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
return AuthToken.builder()
|
||||
.accessCode(code)
|
||||
.build();
|
||||
return AuthToken.builder().accessCode(code).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String code = authToken.getAccessCode();
|
||||
// 根据timestamp, appSecret计算签名值
|
||||
String stringToSign = System.currentTimeMillis() + "";
|
||||
String urlEncodeSignature = GlobalAuthUtil.generateDingTalkSignature(config.getClientSecret(), stringToSign);
|
||||
HttpResponse response = HttpRequest.post(UrlBuilder.getDingTalkUserInfoUrl(urlEncodeSignature, stringToSign, config.getClientId()))
|
||||
.body(Objects.requireNonNull(new JSONObject().put("tmp_auth_code", code)))
|
||||
String timestamp = System.currentTimeMillis() + "";
|
||||
String urlEncodeSignature = GlobalAuthUtil.generateDingTalkSignature(config.getClientSecret(), timestamp);
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("tmp_auth_code", code);
|
||||
HttpResponse response = HttpRequest.post(UrlBuilder.getDingTalkUserInfoUrl(urlEncodeSignature, timestamp, config.getClientId()))
|
||||
.body(param.toJSONString())
|
||||
.execute();
|
||||
String userInfo = response.body();
|
||||
JSONObject object = new JSONObject(userInfo);
|
||||
AuthDingTalkErrorCode errorCode = AuthDingTalkErrorCode.getErrorCode(object.getInt("errcode"));
|
||||
JSONObject object = JSON.parseObject(userInfo);
|
||||
AuthDingTalkErrorCode errorCode = AuthDingTalkErrorCode.getErrorCode(object.getIntValue("errcode"));
|
||||
if (!AuthDingTalkErrorCode.EC0.equals(errorCode)) {
|
||||
throw new AuthException(errorCode.getDesc());
|
||||
}
|
||||
object = object.getJSONObject("user_info");
|
||||
AuthToken token = AuthToken.builder()
|
||||
.openId(object.getString("openid"))
|
||||
.unionId(object.getString("unionid"))
|
||||
.build();
|
||||
return AuthUser.builder()
|
||||
.nickname(object.getStr("nick"))
|
||||
.username(object.getStr("nick"))
|
||||
.uuid(object.getString("unionid"))
|
||||
.nickname(object.getString("nick"))
|
||||
.username(object.getString("nick"))
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
.source(AuthSource.DINGTALK)
|
||||
.token(token)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getDingTalkQrConnectUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* 抖音登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthDouyinRequest extends BaseAuthRequest {
|
||||
|
||||
public AuthDouyinRequest(AuthConfig config) {
|
||||
super(config, AuthSource.DOUYIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getDouyinAccessTokenUrl(config.getClientId(), config.getClientSecret(), code);
|
||||
return this.getToken(accessTokenUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
String openId = authToken.getOpenId();
|
||||
String url = UrlBuilder.getDouyinUserInfoUrl(accessToken, openId);
|
||||
HttpResponse response = HttpRequest.get(url).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
|
||||
JSONObject userInfoObject = this.checkResponse(object);
|
||||
|
||||
return AuthUser.builder()
|
||||
.uuid(userInfoObject.getString("union_id"))
|
||||
.username(userInfoObject.getString("nickname"))
|
||||
.nickname(userInfoObject.getString("nickname"))
|
||||
.avatar(userInfoObject.getString("avatar"))
|
||||
.remark(userInfoObject.getString("description"))
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
.token(authToken)
|
||||
.source(AuthSource.DOUYIN)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getDouyinAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken oldToken) {
|
||||
String refreshTokenUrl = UrlBuilder.getDouyinRefreshUrl(config.getClientId(), oldToken.getRefreshToken());
|
||||
return AuthResponse.builder()
|
||||
.code(ResponseStatus.SUCCESS.getCode())
|
||||
.data(this.getToken(refreshTokenUrl))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查响应内容是否正确
|
||||
*
|
||||
* @param object 请求响应内容
|
||||
* @return 实际请求数据的json对象
|
||||
*/
|
||||
private JSONObject checkResponse(JSONObject object) {
|
||||
String message = object.getString("message");
|
||||
JSONObject data = object.getJSONObject("data");
|
||||
int errorCode = data.getIntValue("error_code");
|
||||
if ("error".equals(message) || errorCode != 0) {
|
||||
throw new AuthException(errorCode, data.getString("description"));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token,适用于获取access_token和刷新token
|
||||
*
|
||||
* @param accessTokenUrl 实际请求token的地址
|
||||
* @return token对象
|
||||
*/
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
String accessTokenStr = response.body();
|
||||
JSONObject object = JSONObject.parseObject(accessTokenStr);
|
||||
|
||||
JSONObject accessTokenObject = this.checkResponse(object);
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.openId(accessTokenObject.getString("open_id"))
|
||||
.expireIn(accessTokenObject.getIntValue("expires_in"))
|
||||
.refreshToken(accessTokenObject.getString("refresh_token"))
|
||||
.scope(accessTokenObject.getString("scope"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* Facebook登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthFacebookRequest extends BaseAuthRequest {
|
||||
|
||||
public AuthFacebookRequest(AuthConfig config) {
|
||||
super(config, AuthSource.FACEBOOK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getFacebookAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
|
||||
.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
|
||||
if (object.containsKey("error")) {
|
||||
throw new AuthException(object.getJSONObject("error").getString("message"));
|
||||
}
|
||||
|
||||
return AuthToken.builder()
|
||||
.accessToken(object.getString("access_token"))
|
||||
.expireIn(object.getIntValue("expires_in"))
|
||||
.tokenType(object.getString("token_type"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getFacebookUserInfoUrl(accessToken)).execute();
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
if (object.containsKey("error")) {
|
||||
throw new AuthException(object.getJSONObject("error").getString("message"));
|
||||
}
|
||||
String picture = null;
|
||||
if (object.containsKey("picture")) {
|
||||
JSONObject pictureObj = object.getJSONObject("picture");
|
||||
pictureObj = pictureObj.getJSONObject("data");
|
||||
if (null != pictureObj) {
|
||||
picture = pictureObj.getString("url");
|
||||
}
|
||||
}
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("id"))
|
||||
.username(object.getString("name"))
|
||||
.nickname(object.getString("name"))
|
||||
.avatar(picture)
|
||||
.location(object.getString("locale"))
|
||||
.email(object.getString("email"))
|
||||
.gender(AuthUserGender.getRealGender(object.getString("gender")))
|
||||
.token(authToken)
|
||||
.source(AuthSource.FACEBOOK)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getFacebookAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,11 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
@@ -25,15 +26,14 @@ public class AuthGiteeRequest extends BaseAuthRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getGiteeAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
String accessTokenUrl = UrlBuilder.getGiteeAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
|
||||
.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
if (accessTokenObject.containsKey("error")) {
|
||||
throw new AuthException("Unable to get token from gitee using code [" + code + "]");
|
||||
}
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.build();
|
||||
return AuthToken.builder().accessToken(accessTokenObject.getString("access_token")).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +43,7 @@ public class AuthGiteeRequest extends BaseAuthRequest {
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("id"))
|
||||
.username(object.getString("login"))
|
||||
.avatar(object.getString("avatar_url"))
|
||||
.blog(object.getString("blog"))
|
||||
@@ -51,8 +52,19 @@ public class AuthGiteeRequest extends BaseAuthRequest {
|
||||
.location(object.getString("address"))
|
||||
.email(object.getString("email"))
|
||||
.remark(object.getString("bio"))
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
.token(authToken)
|
||||
.source(AuthSource.GITEE)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getGiteeAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.GlobalAuthUtil;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
@@ -28,15 +29,14 @@ public class AuthGithubRequest extends BaseAuthRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
|
||||
.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
Map<String, String> res = GlobalAuthUtil.parseStringToMap(response.body());
|
||||
if (res.containsKey("error")) {
|
||||
throw new AuthException(res.get("error") + ":" + res.get("error_description"));
|
||||
}
|
||||
return AuthToken.builder()
|
||||
.accessToken(res.get("access_token"))
|
||||
.build();
|
||||
return AuthToken.builder().accessToken(res.get("access_token")).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,6 +46,7 @@ public class AuthGithubRequest extends BaseAuthRequest {
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("id"))
|
||||
.username(object.getString("login"))
|
||||
.avatar(object.getString("avatar_url"))
|
||||
.blog(object.getString("blog"))
|
||||
@@ -54,8 +55,19 @@ public class AuthGithubRequest extends BaseAuthRequest {
|
||||
.location(object.getString("location"))
|
||||
.email(object.getString("email"))
|
||||
.remark(object.getString("bio"))
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
.token(authToken)
|
||||
.source(AuthSource.GITHUB)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getGithubAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* Google登录
|
||||
*
|
||||
* @author yangkai.shen (https://xkcoding.com)
|
||||
* @version 1.3
|
||||
* @since 1.3
|
||||
*/
|
||||
public class AuthGoogleRequest extends BaseAuthRequest {
|
||||
|
||||
public AuthGoogleRequest(AuthConfig config) {
|
||||
super(config, AuthSource.GOOGLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getGoogleAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
|
||||
.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
|
||||
if (object.containsKey("error") || object.containsKey("error_description")) {
|
||||
throw new AuthException("get google access_token has error:[" + object.getString("error") + "], error_description:[" + object
|
||||
.getString("error_description") + "]");
|
||||
}
|
||||
|
||||
return AuthToken.builder()
|
||||
.accessToken(object.getString("access_token"))
|
||||
.expireIn(object.getIntValue("expires_in"))
|
||||
.scope(object.getString("scope"))
|
||||
.tokenType(object.getString("token_type"))
|
||||
.idToken(object.getString("id_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getIdToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getGoogleUserInfoUrl(accessToken)).execute();
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("sub"))
|
||||
.username(object.getString("name"))
|
||||
.avatar(object.getString("picture"))
|
||||
.nickname(object.getString("name"))
|
||||
.location(object.getString("locale"))
|
||||
.email(object.getString("email"))
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
.token(authToken)
|
||||
.source(AuthSource.GOOGLE)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getGoogleAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.StringUtils;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* 领英登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthLinkedinRequest extends BaseAuthRequest {
|
||||
|
||||
public AuthLinkedinRequest(AuthConfig config) {
|
||||
super(config, AuthSource.LINKEDIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getLinkedinAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
|
||||
.getRedirectUri());
|
||||
return this.getToken(accessTokenUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getLinkedinUserInfoUrl())
|
||||
.header("Host", "api.linkedin.com")
|
||||
.header("Connection", "Keep-Alive")
|
||||
.header("Authorization", "Bearer " + accessToken)
|
||||
.execute();
|
||||
JSONObject userInfoObject = JSONObject.parseObject(response.body());
|
||||
|
||||
this.checkResponse(userInfoObject);
|
||||
|
||||
// 组装用户名
|
||||
String firstName, lastName;
|
||||
// 获取firstName
|
||||
if (userInfoObject.containsKey("localizedFirstName")) {
|
||||
firstName = userInfoObject.getString("localizedFirstName");
|
||||
} else {
|
||||
firstName = getUserName(userInfoObject, "firstName");
|
||||
}
|
||||
// 获取lastName
|
||||
if (userInfoObject.containsKey("localizedLastName")) {
|
||||
lastName = userInfoObject.getString("localizedLastName");
|
||||
} else {
|
||||
lastName = getUserName(userInfoObject, "lastName");
|
||||
}
|
||||
String userName = firstName + " " + lastName;
|
||||
|
||||
// 获取用户头像
|
||||
String avatar = null;
|
||||
JSONObject profilePictureObject = userInfoObject.getJSONObject("profilePicture");
|
||||
if (profilePictureObject.containsKey("displayImage~")) {
|
||||
JSONArray displayImageElements = profilePictureObject.getJSONObject("displayImage~")
|
||||
.getJSONArray("elements");
|
||||
if (null != displayImageElements && displayImageElements.size() > 0) {
|
||||
JSONObject largestImageObj = displayImageElements.getJSONObject(displayImageElements.size() - 1);
|
||||
avatar = largestImageObj.getJSONArray("identifiers").getJSONObject(0).getString("identifier");
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户邮箱地址
|
||||
String email = this.getUserEmail(accessToken);
|
||||
return AuthUser.builder()
|
||||
.uuid(userInfoObject.getString("id"))
|
||||
.username(userName)
|
||||
.nickname(userName)
|
||||
.avatar(avatar)
|
||||
.email(email)
|
||||
.token(authToken)
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
.source(AuthSource.LINKEDIN)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getLinkedinAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
|
||||
private String getUserEmail(String accessToken) {
|
||||
String email = null;
|
||||
HttpResponse emailResponse = HttpRequest.get("https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))")
|
||||
.header("Host", "api.linkedin.com")
|
||||
.header("Connection", "Keep-Alive")
|
||||
.header("Authorization", "Bearer " + accessToken)
|
||||
.execute();
|
||||
System.out.println(emailResponse.body());
|
||||
JSONObject emailObj = JSONObject.parseObject(emailResponse.body());
|
||||
if (emailObj.containsKey("elements")) {
|
||||
email = emailObj.getJSONArray("elements")
|
||||
.getJSONObject(0)
|
||||
.getJSONObject("handle~")
|
||||
.getString("emailAddress");
|
||||
}
|
||||
return email;
|
||||
}
|
||||
|
||||
private String getUserName(JSONObject userInfoObject, String nameKey) {
|
||||
String firstName;
|
||||
JSONObject firstNameObj = userInfoObject.getJSONObject(nameKey);
|
||||
JSONObject localizedObj = firstNameObj.getJSONObject("localized");
|
||||
JSONObject preferredLocaleObj = firstNameObj.getJSONObject("preferredLocale");
|
||||
firstName = localizedObj.getString(preferredLocaleObj.getString("language") + "_" + preferredLocaleObj.getString("country"));
|
||||
return firstName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken oldToken) {
|
||||
if (StringUtils.isEmpty(oldToken.getRefreshToken())) {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
String refreshTokenUrl = UrlBuilder.getLinkedinRefreshUrl(config.getClientId(), config.getClientSecret(), oldToken
|
||||
.getRefreshToken());
|
||||
return AuthResponse.builder()
|
||||
.code(ResponseStatus.SUCCESS.getCode())
|
||||
.data(this.getToken(refreshTokenUrl))
|
||||
.build();
|
||||
}
|
||||
|
||||
private void checkResponse(JSONObject userInfoObject) {
|
||||
if (userInfoObject.containsKey("error")) {
|
||||
throw new AuthException(userInfoObject.getString("error_description"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token,适用于获取access_token和刷新token
|
||||
*
|
||||
* @param accessTokenUrl 实际请求token的地址
|
||||
* @return token对象
|
||||
*/
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl)
|
||||
.header("Host", "www.linkedin.com")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.execute();
|
||||
String accessTokenStr = response.body();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
|
||||
|
||||
this.checkResponse(accessTokenObject);
|
||||
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.expireIn(accessTokenObject.getIntValue("expires_in"))
|
||||
.refreshToken(accessTokenObject.getString("refresh_token"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
* 小米登录
|
||||
*
|
||||
* @author yangkai.shen (https://xkcoding.com)
|
||||
* @version 1.5
|
||||
* @since 1.5
|
||||
*/
|
||||
public class AuthMiRequest extends BaseAuthRequest {
|
||||
private static final String PREFIX = "&&&START&&&";
|
||||
|
||||
public AuthMiRequest(AuthConfig config) {
|
||||
super(config, AuthSource.MI);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getMiAccessTokenUrl(config.getClientId(), config.getClientSecret(), config.getRedirectUri(), code);
|
||||
return getToken(accessTokenUrl);
|
||||
}
|
||||
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
|
||||
String jsonStr = StrUtil.replace(response.body(), PREFIX, StrUtil.EMPTY);
|
||||
JSONObject object = JSONObject.parseObject(jsonStr);
|
||||
|
||||
if (object.containsKey("error")) {
|
||||
throw new AuthException(object.getString("error_description"));
|
||||
}
|
||||
|
||||
return AuthToken.builder()
|
||||
.accessToken(object.getString("access_token"))
|
||||
.expireIn(object.getIntValue("expires_in"))
|
||||
.scope(object.getString("scope"))
|
||||
.tokenType(object.getString("token_type"))
|
||||
.refreshToken(object.getString("refresh_token"))
|
||||
.openId(object.getString("openId"))
|
||||
.macAlgorithm(object.getString("mac_algorithm"))
|
||||
.macKey(object.getString("mac_key"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
// 获取用户信息
|
||||
HttpResponse userResponse = HttpRequest.get(UrlBuilder.getMiUserInfoUrl(config.getClientId(), authToken.getAccessToken()))
|
||||
.execute();
|
||||
|
||||
JSONObject userProfile = JSONObject.parseObject(userResponse.body());
|
||||
if (StrUtil.equalsIgnoreCase(userProfile.getString("result"), "error")) {
|
||||
throw new AuthException(userProfile.getString("description"));
|
||||
}
|
||||
|
||||
JSONObject user = userProfile.getJSONObject("data");
|
||||
|
||||
AuthUser authUser = AuthUser.builder()
|
||||
.uuid(authToken.getOpenId())
|
||||
.username(user.getString("miliaoNick"))
|
||||
.nickname(user.getString("miliaoNick"))
|
||||
.avatar(user.getString("miliaoIcon"))
|
||||
.email(user.getString("mail"))
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
.token(authToken)
|
||||
.source(AuthSource.MI)
|
||||
.build();
|
||||
|
||||
// 获取用户邮箱手机号等信息
|
||||
String emailPhoneUrl = MessageFormat.format("{0}?clientId={1}&token={2}", "https://open.account.xiaomi.com/user/phoneAndEmail", config
|
||||
.getClientId(), authToken.getAccessToken());
|
||||
|
||||
HttpResponse emailResponse = HttpRequest.get(emailPhoneUrl).execute();
|
||||
JSONObject userEmailPhone = JSONObject.parseObject(emailResponse.body());
|
||||
if (!StrUtil.equalsIgnoreCase(userEmailPhone.getString("result"), "error")) {
|
||||
JSONObject emailPhone = userEmailPhone.getJSONObject("data");
|
||||
authUser.setEmail(emailPhone.getString("email"));
|
||||
}
|
||||
|
||||
return authUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getMiAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新access token (续期)
|
||||
*
|
||||
* @param authToken 登录成功后返回的Token信息
|
||||
* @return AuthResponse
|
||||
*/
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken authToken) {
|
||||
String miRefreshUrl = UrlBuilder.getMiRefreshUrl(config.getClientId(), config.getClientSecret(), config.getRedirectUri(), authToken
|
||||
.getRefreshToken());
|
||||
|
||||
return AuthResponse.builder().code(ResponseStatus.SUCCESS.getCode()).data(getToken(miRefreshUrl)).build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 微软登录
|
||||
*
|
||||
* @author yangkai.shen (https://xkcoding.com)
|
||||
* @version 1.5
|
||||
* @since 1.5
|
||||
*/
|
||||
public class AuthMicrosoftRequest extends BaseAuthRequest {
|
||||
public AuthMicrosoftRequest(AuthConfig config) {
|
||||
super(config, AuthSource.MICROSOFT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getMicrosoftAccessTokenUrl(config.getClientId(), config.getClientSecret(), config
|
||||
.getRedirectUri(), code);
|
||||
|
||||
return getToken(accessTokenUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token,适用于获取access_token和刷新token
|
||||
*
|
||||
* @param accessTokenUrl 实际请求token的地址
|
||||
* @return token对象
|
||||
*/
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
Map<String, Object> paramMap = new HashMap<>(6);
|
||||
HttpUtil.decodeParamMap(accessTokenUrl, "UTF-8").forEach(paramMap::put);
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl)
|
||||
.header("Host", "https://login.microsoftonline.com")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.form(paramMap)
|
||||
.execute();
|
||||
String accessTokenStr = response.body();
|
||||
JSONObject object = JSONObject.parseObject(accessTokenStr);
|
||||
|
||||
this.checkResponse(object);
|
||||
|
||||
return AuthToken.builder()
|
||||
.accessToken(object.getString("access_token"))
|
||||
.expireIn(object.getIntValue("expires_in"))
|
||||
.scope(object.getString("scope"))
|
||||
.tokenType(object.getString("token_type"))
|
||||
.refreshToken(object.getString("refresh_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
private void checkResponse(JSONObject response) {
|
||||
if (response.containsKey("error")) {
|
||||
throw new AuthException(response.getString("error_description"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String token = authToken.getAccessToken();
|
||||
String tokenType = authToken.getTokenType();
|
||||
String jwt = tokenType + " " + token;
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getMicrosoftUserInfoUrl())
|
||||
.header("Authorization", jwt)
|
||||
.execute();
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("id"))
|
||||
.username(object.getString("userPrincipalName"))
|
||||
.nickname(object.getString("displayName"))
|
||||
.location(object.getString("officeLocation"))
|
||||
.email(object.getString("mail"))
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
.token(authToken)
|
||||
.source(AuthSource.MICROSOFT)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getMicrosoftAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新access token (续期)
|
||||
*
|
||||
* @param authToken 登录成功后返回的Token信息
|
||||
* @return AuthResponse
|
||||
*/
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken authToken) {
|
||||
String refreshTokenUrl = UrlBuilder.getMicrosoftRefreshUrl(config.getClientId(), config.getClientSecret(), config
|
||||
.getRedirectUri(), authToken.getRefreshToken());
|
||||
|
||||
return AuthResponse.builder().code(ResponseStatus.SUCCESS.getCode()).data(getToken(refreshTokenUrl)).build();
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
@@ -26,15 +26,14 @@ public class AuthOschinaRequest extends BaseAuthRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getOschinaAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
String accessTokenUrl = UrlBuilder.getOschinaAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
|
||||
.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
if (accessTokenObject.containsKey("error")) {
|
||||
throw new AuthException("Unable to get token from oschina using code [" + code + "]");
|
||||
}
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.build();
|
||||
return AuthToken.builder().accessToken(accessTokenObject.getString("access_token")).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,6 +45,7 @@ public class AuthOschinaRequest extends BaseAuthRequest {
|
||||
throw new AuthException(object.getString("error_description"));
|
||||
}
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("id"))
|
||||
.username(object.getString("name"))
|
||||
.nickname(object.getString("name"))
|
||||
.avatar(object.getString("avatar"))
|
||||
@@ -57,4 +57,14 @@ public class AuthOschinaRequest extends BaseAuthRequest {
|
||||
.source(AuthSource.OSCHINA)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getOschinaAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.GlobalAuthUtil;
|
||||
import me.zhyd.oauth.utils.StringUtils;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* qq登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @author yangkai.shen (https://xkcoding.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
@@ -26,22 +31,26 @@ public class AuthQqRequest extends BaseAuthRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getQqAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
String accessTokenUrl = UrlBuilder.getQqAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
|
||||
.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
|
||||
Map<String, String> accessTokenObject = GlobalAuthUtil.parseStringToMap(response.body());
|
||||
if (!accessTokenObject.containsKey("access_token")) {
|
||||
throw new AuthException("Unable to get token from qq using code [" + code + "]");
|
||||
}
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.accessToken(accessTokenObject.get("access_token"))
|
||||
.expireIn(Integer.valueOf(accessTokenObject.get("expires_in")))
|
||||
.refreshToken(accessTokenObject.get("refresh_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
String openId = this.getOpenId(accessToken);
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getQqUserInfoUrl(accessToken, openId)).execute();
|
||||
String openId = this.getOpenId(authToken);
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getQqUserInfoUrl(config.getClientId(), accessToken, openId))
|
||||
.execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.getIntValue("ret") != 0) {
|
||||
throw new AuthException(object.getString("msg"));
|
||||
@@ -50,25 +59,48 @@ public class AuthQqRequest extends BaseAuthRequest {
|
||||
if (StringUtils.isEmpty(avatar)) {
|
||||
avatar = object.getString("figureurl_qq_1");
|
||||
}
|
||||
|
||||
String location = String.format("%s-%s", object.getString("province"), object.getString("city"));
|
||||
return AuthUser.builder()
|
||||
.username(object.getString("nickname"))
|
||||
.nickname(object.getString("nickname"))
|
||||
.avatar(avatar)
|
||||
.location(location)
|
||||
.uuid(openId)
|
||||
.gender(AuthUserGender.getRealGender(object.getString("gender")))
|
||||
.token(authToken)
|
||||
.source(AuthSource.QQ)
|
||||
.build();
|
||||
}
|
||||
|
||||
private String getOpenId(String accessToken) {
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getQqOpenidUrl("https://graph.qq.com/oauth2.0/me", accessToken)).execute();
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getQqAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
|
||||
private String getOpenId(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getQqOpenidUrl("https://graph.qq.com/oauth2.0/me", accessToken))
|
||||
.execute();
|
||||
if (response.isOk()) {
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.containsKey("openid")) {
|
||||
return object.getString("openid");
|
||||
String body = response.body();
|
||||
String removePrefix = StrUtil.replace(body, "callback(", "");
|
||||
String removeSuffix = StrUtil.replace(removePrefix, ");", "");
|
||||
String openId = StrUtil.trim(removeSuffix);
|
||||
JSONObject object = JSONObject.parseObject(openId);
|
||||
if (object.containsKey("error")) {
|
||||
throw new AuthException(object.get("error") + ":" + object.get("error_description"));
|
||||
}
|
||||
throw new AuthException("Invalid openId");
|
||||
authToken.setOpenId(object.getString("openid"));
|
||||
authToken.setUnionId(object.getString("unionid"));
|
||||
return StringUtils.isEmpty(authToken.getUnionId()) ? authToken.getOpenId() : authToken.getUnionId();
|
||||
}
|
||||
throw new AuthException("Invalid openId");
|
||||
|
||||
throw new AuthException("request error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
@@ -27,15 +27,14 @@ public class AuthTaobaoRequest extends BaseAuthRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
return AuthToken.builder()
|
||||
.accessCode(code)
|
||||
.build();
|
||||
return AuthToken.builder().accessCode(code).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessCode = authToken.getAccessCode();
|
||||
HttpResponse response = HttpRequest.post(UrlBuilder.getTaobaoAccessTokenUrl(this.config.getClientId(), this.config.getClientSecret(), accessCode, this.config.getRedirectUri())).execute();
|
||||
HttpResponse response = HttpRequest.post(UrlBuilder.getTaobaoAccessTokenUrl(this.config.getClientId(), this.config
|
||||
.getClientSecret(), accessCode, this.config.getRedirectUri())).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.containsKey("error")) {
|
||||
throw new AuthException(ResponseStatus.FAILURE + ":" + object.getString("error_description"));
|
||||
@@ -48,6 +47,7 @@ public class AuthTaobaoRequest extends BaseAuthRequest {
|
||||
|
||||
String nick = GlobalAuthUtil.urlDecode(object.getString("taobao_user_nick"));
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("taobao_user_id"))
|
||||
.username(nick)
|
||||
.nickname(nick)
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
@@ -55,4 +55,14 @@ public class AuthTaobaoRequest extends BaseAuthRequest {
|
||||
.source(AuthSource.TAOBAO)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getTaobaoAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
@@ -21,7 +21,7 @@ import me.zhyd.oauth.utils.UrlBuilder;
|
||||
public class AuthTencentCloudRequest extends BaseAuthRequest {
|
||||
|
||||
public AuthTencentCloudRequest(AuthConfig config) {
|
||||
super(config, AuthSource.TENCEN_CLOUD);
|
||||
super(config, AuthSource.TENCENT_CLOUD);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,9 +32,7 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
|
||||
if (object.getIntValue("code") != 0) {
|
||||
throw new AuthException("Unable to get token from tencent cloud using code [" + code + "]: " + object.get("msg"));
|
||||
}
|
||||
return AuthToken.builder()
|
||||
.accessToken(object.getString("access_token"))
|
||||
.build();
|
||||
return AuthToken.builder().accessToken(object.getString("access_token")).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,6 +45,7 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
|
||||
}
|
||||
object = object.getJSONObject("data");
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("id"))
|
||||
.username(object.getString("name"))
|
||||
.avatar("https://dev.tencent.com/" + object.getString("avatar"))
|
||||
.blog("https://dev.tencent.com/" + object.getString("path"))
|
||||
@@ -57,7 +56,17 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
|
||||
.email(object.getString("email"))
|
||||
.remark(object.getString("slogan"))
|
||||
.token(authToken)
|
||||
.source(AuthSource.TENCEN_CLOUD)
|
||||
.source(AuthSource.TENCENT_CLOUD)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getTencentCloudAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthToutiaoErrorCode;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 今日头条登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.5
|
||||
* @since 1.5
|
||||
*/
|
||||
public class AuthToutiaoRequest extends BaseAuthRequest {
|
||||
|
||||
public AuthToutiaoRequest(AuthConfig config) {
|
||||
super(config, AuthSource.TOUTIAO);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getToutiaoAccessTokenUrl(config.getClientId(), config.getClientSecret(), code);
|
||||
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
|
||||
if (object.containsKey("error_code")) {
|
||||
throw new AuthException(AuthToutiaoErrorCode.getErrorCode(object.getIntValue("error_code")).getDesc());
|
||||
}
|
||||
|
||||
return AuthToken.builder()
|
||||
.accessToken(object.getString("access_token"))
|
||||
.expireIn(object.getIntValue("expires_in"))
|
||||
.openId(object.getString("open_id"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
HttpResponse userResponse = HttpRequest.get(UrlBuilder.getToutiaoUserInfoUrl(config.getClientId(), authToken.getAccessToken())).execute();
|
||||
|
||||
JSONObject userProfile = JSONObject.parseObject(userResponse.body());
|
||||
|
||||
if (userProfile.containsKey("error_code")) {
|
||||
throw new AuthException(AuthToutiaoErrorCode.getErrorCode(userProfile.getIntValue("error_code")).getDesc());
|
||||
}
|
||||
|
||||
JSONObject user = userProfile.getJSONObject("data");
|
||||
|
||||
boolean isAnonymousUser = user.getIntValue("uid_type") == 14;
|
||||
String anonymousUserName = "匿名用户";
|
||||
|
||||
return AuthUser.builder()
|
||||
.uuid(user.getString("uid"))
|
||||
.username(isAnonymousUser ? anonymousUserName : user.getString("screen_name"))
|
||||
.nickname(isAnonymousUser ? anonymousUserName : user.getString("screen_name"))
|
||||
.avatar(user.getString("avatar_url"))
|
||||
.remark(user.getString("description"))
|
||||
.gender(AuthUserGender.getRealGender(user.getString("gender")))
|
||||
.token(authToken)
|
||||
.source(AuthSource.TOUTIAO)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getToutiaoAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,12 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.*;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
@@ -29,18 +33,7 @@ public class AuthWeChatRequest extends BaseAuthRequest {
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getWeChatAccessTokenUrl(config.getClientId(), config.getClientSecret(), code);
|
||||
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
if (!accessTokenObject.containsKey("access_token") || !accessTokenObject.containsKey("openid") || !accessTokenObject
|
||||
.containsKey("refresh_token")) {
|
||||
throw new AuthException("Unable to get access_token or openid or refresh_token from wechat using code [" + code + "]");
|
||||
}
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
return AuthToken.builder()
|
||||
.accessToken(object.getString("access_token"))
|
||||
.refreshToken(object.getString("refresh_token"))
|
||||
.openId(object.getString("openid"))
|
||||
.build();
|
||||
return this.getToken(accessTokenUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,32 +43,69 @@ public class AuthWeChatRequest extends BaseAuthRequest {
|
||||
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getWeChatUserInfoUrl(accessToken, openId)).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.containsKey("errcode")) {
|
||||
throw new AuthException(object.getString("errmsg"));
|
||||
}
|
||||
|
||||
this.checkResponse(object);
|
||||
|
||||
String location = String.format("%s-%s-%s", object.getString("country"), object.getString("province"), object.getString("city"));
|
||||
return AuthUser.builder()
|
||||
.username(object.getString("nickname"))
|
||||
.nickname(object.getString("nickname"))
|
||||
.avatar(object.getString("headimgurl"))
|
||||
.location(object.getString("country") + "-" + object.getString("province") + "-" + object.getString("city"))
|
||||
.location(location)
|
||||
.uuid(openId)
|
||||
.gender(AuthUserGender.getRealGender(object.getString("sex")))
|
||||
.token(authToken)
|
||||
.source(AuthSource.WECHAT)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken authToken) {
|
||||
String refreshToken = authToken.getRefreshToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getWeChatRefreshUrl(config.getClientId(), refreshToken))
|
||||
.execute();
|
||||
public String authorize() {
|
||||
return UrlBuilder.getWeChatAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken oldToken) {
|
||||
String refreshTokenUrl = UrlBuilder.getWeChatRefreshUrl(config.getClientId(), oldToken.getRefreshToken());
|
||||
return AuthResponse.builder()
|
||||
.code(ResponseStatus.SUCCESS.getCode())
|
||||
.data(this.getToken(refreshTokenUrl))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查响应内容是否正确
|
||||
*
|
||||
* @param object 请求响应内容
|
||||
*/
|
||||
private void checkResponse(JSONObject object) {
|
||||
if (object.containsKey("errcode")) {
|
||||
throw new AuthException(object.getString("errmsg"));
|
||||
throw new AuthException(object.getIntValue("errcode"), object.getString("errmsg"));
|
||||
}
|
||||
}
|
||||
|
||||
return AuthResponse.builder().data(object).build();
|
||||
/**
|
||||
* 获取token,适用于获取access_token和刷新token
|
||||
*
|
||||
* @param accessTokenUrl 实际请求token的地址
|
||||
* @return token对象
|
||||
*/
|
||||
private AuthToken getToken(String accessTokenUrl) {
|
||||
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
|
||||
this.checkResponse(object);
|
||||
|
||||
return AuthToken.builder()
|
||||
.accessToken(object.getString("access_token"))
|
||||
.refreshToken(object.getString("refresh_token"))
|
||||
.expireIn(object.getIntValue("expires_in"))
|
||||
.openId(object.getString("openid"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.model.AuthUserGender;
|
||||
import me.zhyd.oauth.utils.GlobalAuthUtil;
|
||||
import me.zhyd.oauth.utils.IpUtils;
|
||||
import me.zhyd.oauth.utils.StringUtils;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
@@ -30,7 +29,8 @@ public class AuthWeiboRequest extends BaseAuthRequest {
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getWeiboAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
String accessTokenUrl = UrlBuilder.getWeiboAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config
|
||||
.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
String accessTokenStr = response.body();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
|
||||
@@ -48,19 +48,22 @@ public class AuthWeiboRequest extends BaseAuthRequest {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
String uid = authToken.getUid();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getWeiboUserInfoUrl(accessToken))
|
||||
.header("Authorization", "OAuth2 " + String.format("uid=%s&access_token=%s", uid, accessToken))
|
||||
String oauthParam = String.format("uid=%s&access_token=%s", uid, accessToken);
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getWeiboUserInfoUrl(oauthParam))
|
||||
.header("Authorization", "OAuth2 " + oauthParam)
|
||||
.header("API-RemoteIP", IpUtils.getIp())
|
||||
.execute();
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
if(object.containsKey("error")) {
|
||||
if (object.containsKey("error")) {
|
||||
throw new AuthException(object.getString("error"));
|
||||
}
|
||||
return AuthUser.builder()
|
||||
.uuid(object.getString("id"))
|
||||
.username(object.getString("name"))
|
||||
.avatar(object.getString("profile_image_url"))
|
||||
.blog(StringUtils.isEmpty(object.getString("url")) ? "https://weibo.com/" + object.getString("profile_url") : object.getString("url"))
|
||||
.blog(StringUtils.isEmpty(object.getString("url")) ? "https://weibo.com/" + object.getString("profile_url") : object
|
||||
.getString("url"))
|
||||
.nickname(object.getString("screen_name"))
|
||||
.location(object.getString("location"))
|
||||
.remark(object.getString("description"))
|
||||
@@ -69,4 +72,14 @@ public class AuthWeiboRequest extends BaseAuthRequest {
|
||||
.source(AuthSource.WEIBO)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public String authorize() {
|
||||
return UrlBuilder.getWeiboAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@ package me.zhyd.oauth.request;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
import me.zhyd.oauth.utils.AuthConfigChecker;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
@@ -23,9 +22,11 @@ public abstract class BaseAuthRequest implements AuthRequest {
|
||||
public BaseAuthRequest(AuthConfig config, AuthSource source) {
|
||||
this.config = config;
|
||||
this.source = source;
|
||||
if (!AuthConfigChecker.isSupportedAuth(config)) {
|
||||
if (!AuthConfigChecker.isSupportedAuth(config, source)) {
|
||||
throw new AuthException(ResponseStatus.PARAMETER_INCOMPLETE);
|
||||
}
|
||||
// 校验配置合法性
|
||||
AuthConfigChecker.check(config, source);
|
||||
}
|
||||
|
||||
protected abstract AuthToken getAccessToken(String code);
|
||||
@@ -35,61 +36,27 @@ public abstract class BaseAuthRequest implements AuthRequest {
|
||||
@Override
|
||||
public AuthResponse login(String code) {
|
||||
try {
|
||||
AuthUser user = this.getUserInfo(this.getAccessToken(code));
|
||||
return AuthResponse.builder().data(user).build();
|
||||
AuthToken authToken = this.getAccessToken(code);
|
||||
AuthUser user = this.getUserInfo(authToken);
|
||||
return AuthResponse.builder().code(ResponseStatus.SUCCESS.getCode()).data(user).build();
|
||||
} catch (Exception e) {
|
||||
return AuthResponse.builder().code(500).msg(e.getMessage()).build();
|
||||
return this.responseError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String authorize() {
|
||||
String authorizeUrl = null;
|
||||
switch (source) {
|
||||
case WEIBO:
|
||||
authorizeUrl = UrlBuilder.getWeiboAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case BAIDU:
|
||||
authorizeUrl = UrlBuilder.getBaiduAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case DINGTALK:
|
||||
authorizeUrl = UrlBuilder.getDingTalkQrConnectUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case GITEE:
|
||||
authorizeUrl = UrlBuilder.getGiteeAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case GITHUB:
|
||||
authorizeUrl = UrlBuilder.getGithubAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case CSDN:
|
||||
authorizeUrl = UrlBuilder.getCsdnAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case CODING:
|
||||
authorizeUrl = UrlBuilder.getCodingAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case TENCEN_CLOUD:
|
||||
authorizeUrl = UrlBuilder.getTencentCloudAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case OSCHINA:
|
||||
authorizeUrl = UrlBuilder.getOschinaAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case ALIPAY:
|
||||
authorizeUrl = UrlBuilder.getAlipayAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case QQ:
|
||||
authorizeUrl = UrlBuilder.getQqAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case WECHAT:
|
||||
authorizeUrl = UrlBuilder.getWeChatAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case TAOBAO:
|
||||
authorizeUrl = UrlBuilder.getTaobaoAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
break;
|
||||
case GOOGLE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
private AuthResponse responseError(Exception e) {
|
||||
int errorCode = ResponseStatus.FAILURE.getCode();
|
||||
if (e instanceof AuthException) {
|
||||
errorCode = ((AuthException) e).getErrorCode();
|
||||
}
|
||||
return authorizeUrl;
|
||||
return AuthResponse.builder().code(errorCode).msg(e.getMessage()).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
@Override
|
||||
public abstract String authorize();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ public enum ResponseStatus {
|
||||
NOT_IMPLEMENTED(5001, "Not Implemented"),
|
||||
PARAMETER_INCOMPLETE(5002, "Parameter incomplete"),
|
||||
UNSUPPORTED(5003, "Unsupported operation"),
|
||||
NO_AUTH_SOURCE(5004, "AuthSource cannot be null"),
|
||||
UNIDENTIFIED_PLATFORM(5005, "Unidentified platform"),
|
||||
ILLEGAL_REDIRECT_URI(5006, "Illegal redirect uri"),
|
||||
;
|
||||
|
||||
private int code;
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package me.zhyd.oauth.utils;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.request.ResponseStatus;
|
||||
|
||||
/**
|
||||
* 授权配置类的校验器
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
@@ -13,9 +18,35 @@ public class AuthConfigChecker {
|
||||
* 是否支持第三方登录
|
||||
*
|
||||
* @param config config
|
||||
* @param source source
|
||||
* @return true or false
|
||||
*/
|
||||
public static boolean isSupportedAuth(AuthConfig config) {
|
||||
return StringUtils.isNotEmpty(config.getClientId()) && StringUtils.isNotEmpty(config.getClientSecret()) && StringUtils.isNotEmpty(config.getRedirectUri());
|
||||
public static boolean isSupportedAuth(AuthConfig config, AuthSource source) {
|
||||
boolean isSupported = StringUtils.isNotEmpty(config.getClientId()) && StringUtils.isNotEmpty(config.getClientSecret()) && StringUtils.isNotEmpty(config.getRedirectUri());
|
||||
if (isSupported && AuthSource.ALIPAY == source) {
|
||||
isSupported = StringUtils.isNotEmpty(config.getAlipayPublicKey());
|
||||
}
|
||||
return isSupported;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查配置合法性。针对部分平台, 对redirect uri有特定要求。一般来说redirect uri都是http://,而对于facebook平台, redirect uri 必须是https的链接
|
||||
*
|
||||
* @param config config
|
||||
* @param source source
|
||||
*/
|
||||
public static void check(AuthConfig config, AuthSource source) {
|
||||
String redirectUri = config.getRedirectUri();
|
||||
if (!GlobalAuthUtil.isHttpProtocol(redirectUri) && !GlobalAuthUtil.isHttpsProtocol(redirectUri)) {
|
||||
throw new AuthException(ResponseStatus.ILLEGAL_REDIRECT_URI);
|
||||
}
|
||||
// facebook的回调地址必须为https的链接
|
||||
if (AuthSource.FACEBOOK == source && !GlobalAuthUtil.isHttpsProtocol(redirectUri)) {
|
||||
throw new AuthException(ResponseStatus.ILLEGAL_REDIRECT_URI);
|
||||
}
|
||||
// 支付宝在创建回调地址时,不允许使用localhost或者127.0.0.1
|
||||
if (AuthSource.ALIPAY == source && GlobalAuthUtil.isLocalHost(redirectUri)) {
|
||||
throw new AuthException(ResponseStatus.ILLEGAL_REDIRECT_URI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,20 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 全局的工具类
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class GlobalAuthUtil {
|
||||
private static final String DEFAULT_ENCODING = "UTF-8";
|
||||
private static final String ALGORITHM = "HmacSHA256";
|
||||
|
||||
public static String generateDingTalkSignature(String canonicalString, String secret) {
|
||||
public static String generateDingTalkSignature(String secretKey, String timestamp) {
|
||||
try {
|
||||
byte[] signData = sign(canonicalString.getBytes(DEFAULT_ENCODING), secret.getBytes(DEFAULT_ENCODING));
|
||||
byte[] signData = sign(secretKey.getBytes(DEFAULT_ENCODING), timestamp.getBytes(DEFAULT_ENCODING));
|
||||
return urlEncode(new String(Base64.encode(signData, false)));
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new AuthException("Unsupported algorithm: " + DEFAULT_ENCODING, ex);
|
||||
@@ -77,4 +84,23 @@ public class GlobalAuthUtil {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static boolean isHttpProtocol(String url) {
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
return false;
|
||||
}
|
||||
return url.startsWith("http://");
|
||||
}
|
||||
|
||||
public static boolean isHttpsProtocol(String url) {
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
return false;
|
||||
}
|
||||
return url.startsWith("https://");
|
||||
}
|
||||
|
||||
public static boolean isLocalHost(String url) {
|
||||
return StringUtils.isEmpty(url) || url.contains("127.0.0.1") || url.contains("localhost");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package me.zhyd.oauth.utils;
|
||||
|
||||
import me.zhyd.oauth.consts.ApiUrl;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
@@ -17,6 +17,10 @@ public class UrlBuilder {
|
||||
private static final String GITHUB_USER_INFO_PATTERN = "{0}?access_token={1}";
|
||||
private static final String GITHUB_AUTHORIZE_PATTERN = "{0}?client_id={1}&state=1&redirect_uri={2}";
|
||||
|
||||
private static final String GOOGLE_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&scope=openid%20email%20profile&redirect_uri={2}&state={3}";
|
||||
private static final String GOOGLE_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
|
||||
private static final String GOOGLE_USER_INFO_PATTERN = "{0}?id_token={1}";
|
||||
|
||||
private static final String WEIBO_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
|
||||
private static final String WEIBO_USER_INFO_PATTERN = "{0}?{1}";
|
||||
private static final String WEIBO_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}";
|
||||
@@ -52,29 +56,57 @@ public class UrlBuilder {
|
||||
private static final String ALIPAY_AUTHORIZE_PATTERN = "{0}?app_id={1}&scope=auth_user&redirect_uri={2}&state=init";
|
||||
|
||||
private static final String QQ_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}";
|
||||
private static final String QQ_USER_INFO_PATTERN = "{0}?access_token={1}&oauth_consumer_key=12345&openid={2}";
|
||||
private static final String QQ_USER_INFO_PATTERN = "{0}?oauth_consumer_key={1}&access_token={2}&openid={3}";
|
||||
private static final String QQ_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&state={3}";
|
||||
private static final String QQ_OPENID_PATTERN = "{0}?access_token={1}";
|
||||
private static final String QQ_OPENID_PATTERN = "{0}?access_token={1}&unionid=1";
|
||||
|
||||
private static final String WECHAT_AUTHORIZE_PATTERN = "{0}?appid={1}&redirect_uri={2}&response_type=code&scope=snsapi_login&state={3}#wechat_redirect";
|
||||
private static final String WECHAT_ACCESS_TOKEN_PATTERN = "{0}?appid={1}&secret={2}&code={3}&grant_type=authorization_code";
|
||||
private static final String WECHAT_REFRESH_TOKEN_PATTERN = "{0}?appid={1}&grant_type=refresh_token&refresh_token={2}";
|
||||
private static final String WECHAT_USER_INFO_PATTERN = "{0}?access_token={1}&openid={2}&lang=zh_CN";
|
||||
|
||||
private static final String TAOBAO_AUTHORIZE_PATTERN = "{0}?response_type=code&client_id={1}&redirect_uri={2}&state=&view=web";
|
||||
private static final String TAOBAO_AUTHORIZE_PATTERN = "{0}?response_type=code&client_id={1}&redirect_uri={2}&state={3}&view=web";
|
||||
private static final String TAOBAO_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
|
||||
|
||||
private static final String FACEBOOK_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&state={3}&response_type=code&scope=";
|
||||
private static final String FACEBOOK_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
|
||||
private static final String FACEBOOK_USER_INFO_PATTERN = "{0}?access_token={1}&fields=id,name,birthday,gender,hometown,email,devices,picture.width(400)";
|
||||
|
||||
private static final String DOUYIN_AUTHORIZE_PATTERN = "{0}?client_key={1}&redirect_uri={2}&state={3}&response_type=code&scope=user_info";
|
||||
private static final String DOUYIN_ACCESS_TOKEN_PATTERN = "{0}?client_key={1}&client_secret={2}&code={3}&grant_type=authorization_code";
|
||||
private static final String DOUYIN_USER_INFO_PATTERN = "{0}?access_token={1}&open_id={2}";
|
||||
private static final String DOUYIN_REFRESH_TOKEN_PATTERN = "{0}?client_key={1}&refresh_token={2}&grant_type=refresh_token";
|
||||
|
||||
private static final String LINKEDIN_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&state={3}&response_type=code&scope=r_liteprofile%20r_emailaddress%20w_member_social";
|
||||
private static final String LINKEDIN_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}&grant_type=authorization_code";
|
||||
private static final String LINKEDIN_USER_INFO_PATTERN = "{0}?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))";
|
||||
private static final String LINKEDIN_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&refresh_token={3}&grant_type=refresh_token";
|
||||
|
||||
private static final String MICROSOFT_AUTHORIZE_PATTERN = "{0}?client_id={1}&response_type=code&redirect_uri={2}&response_mode=query&scope=offline_access%20user.read%20mail.read&state={3}";
|
||||
private static final String MICROSOFT_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&scope=user.read%20mail.read&redirect_uri={3}&code={4}&grant_type=authorization_code";
|
||||
private static final String MICROSOFT_USER_INFO_PATTERN = "{0}";
|
||||
private static final String MICROSOFT_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&scope=user.read%20mail.read&redirect_uri={3}&refresh_token={4}&grant_type=refresh_token";
|
||||
|
||||
private static final String MI_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&response_type=code&scope=user/profile%20user/openIdV2%20user/phoneAndEmail&state={3}&skip_confirm=false";
|
||||
private static final String MI_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&redirect_uri={3}&code={4}&grant_type=authorization_code";
|
||||
private static final String MI_USER_INFO_PATTERN = "{0}?clientId={1}&token={2}";
|
||||
private static final String MI_REFRESH_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&redirect_uri={3}&refresh_token={4}&grant_type=refresh_token";
|
||||
|
||||
private static final String TOUTIAO_ACCESS_TOKEN_PATTERN = "{0}?client_key={1}&client_secret={2}&code={3}&grant_type=authorize_code";
|
||||
private static final String TOUTIAO_USER_INFO_PATTERN = "{0}?client_key={1}&access_token={2}";
|
||||
private static final String TOUTIAO_AUTHORIZE_PATTERN = "{0}?client_key={1}&redirect_uri={2}&state={3}&response_type=code&auth_only=1&display=0";
|
||||
|
||||
/**
|
||||
* 获取githubtoken的接口地址
|
||||
*
|
||||
* @param clientId github应用的Client ID
|
||||
* @param clientSecret github应用的Client Secret
|
||||
* @param code github授权前的code,用来换token
|
||||
* @param clientId github 应用的Client ID
|
||||
* @param clientSecret github 应用的Client Secret
|
||||
* @param code github 授权前的code,用来换token
|
||||
* @param redirectUri 待跳转的页面
|
||||
* @return full url
|
||||
*/
|
||||
public static String getGithubAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
|
||||
return MessageFormat.format(GITHUB_ACCESS_TOKEN_PATTERN, ApiUrl.GITHUB.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
return MessageFormat.format(GITHUB_ACCESS_TOKEN_PATTERN, AuthSource.GITHUB.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +116,7 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getGithubUserInfoUrl(String token) {
|
||||
return MessageFormat.format(GITHUB_USER_INFO_PATTERN, ApiUrl.GITHUB.userInfo(), token);
|
||||
return MessageFormat.format(GITHUB_USER_INFO_PATTERN, AuthSource.GITHUB.userInfo(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,20 +127,20 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getGithubAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(GITHUB_AUTHORIZE_PATTERN, ApiUrl.GITHUB.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(GITHUB_AUTHORIZE_PATTERN, AuthSource.GITHUB.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取weibo token的接口地址
|
||||
*
|
||||
* @param clientId weibo应用的App Key
|
||||
* @param clientSecret weibo应用的App Secret
|
||||
* @param code weibo授权前的code,用来换token
|
||||
* @param clientId weibo 应用的App Key
|
||||
* @param clientSecret weibo 应用的App Secret
|
||||
* @param code weibo 授权前的code,用来换token
|
||||
* @param redirectUri 待跳转的页面
|
||||
* @return full url
|
||||
*/
|
||||
public static String getWeiboAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
|
||||
return MessageFormat.format(WEIBO_ACCESS_TOKEN_PATTERN, ApiUrl.WEIBO.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
return MessageFormat.format(WEIBO_ACCESS_TOKEN_PATTERN, AuthSource.WEIBO.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +150,7 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getWeiboUserInfoUrl(String token) {
|
||||
return MessageFormat.format(WEIBO_USER_INFO_PATTERN, ApiUrl.WEIBO.userInfo(), token);
|
||||
return MessageFormat.format(WEIBO_USER_INFO_PATTERN, AuthSource.WEIBO.userInfo(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,20 +161,20 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getWeiboAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(WEIBO_AUTHORIZE_PATTERN, ApiUrl.WEIBO.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(WEIBO_AUTHORIZE_PATTERN, AuthSource.WEIBO.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取gitee token的接口地址
|
||||
*
|
||||
* @param clientId gitee应用的Client ID
|
||||
* @param clientSecret gitee应用的Client Secret
|
||||
* @param code gitee授权前的code,用来换token
|
||||
* @param clientId gitee 应用的Client ID
|
||||
* @param clientSecret gitee 应用的Client Secret
|
||||
* @param code gitee 授权前的code,用来换token
|
||||
* @param redirectUri 待跳转的页面
|
||||
* @return full url
|
||||
*/
|
||||
public static String getGiteeAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
|
||||
return MessageFormat.format(GITEE_ACCESS_TOKEN_PATTERN, ApiUrl.GITEE.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
return MessageFormat.format(GITEE_ACCESS_TOKEN_PATTERN, AuthSource.GITEE.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +184,7 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getGiteeUserInfoUrl(String token) {
|
||||
return MessageFormat.format(GITEE_USER_INFO_PATTERN, ApiUrl.GITEE.userInfo(), token);
|
||||
return MessageFormat.format(GITEE_USER_INFO_PATTERN, AuthSource.GITEE.userInfo(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,7 +195,7 @@ public class UrlBuilder {
|
||||
* @return json
|
||||
*/
|
||||
public static String getGiteeAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(GITEE_AUTHORIZE_PATTERN, ApiUrl.GITEE.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(GITEE_AUTHORIZE_PATTERN, AuthSource.GITEE.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +206,7 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getDingTalkQrConnectUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(DING_TALK_QRCONNECT_PATTERN, ApiUrl.DINGTALK.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(DING_TALK_QRCONNECT_PATTERN, AuthSource.DINGTALK.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,20 +218,20 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getDingTalkUserInfoUrl(String signature, String timestamp, String accessKey) {
|
||||
return MessageFormat.format(DING_TALK_USER_INFO_PATTERN, ApiUrl.DINGTALK.userInfo(), signature, timestamp, accessKey);
|
||||
return MessageFormat.format(DING_TALK_USER_INFO_PATTERN, AuthSource.DINGTALK.userInfo(), signature, timestamp, accessKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取baidu token的接口地址
|
||||
*
|
||||
* @param clientId baidu应用的API Key
|
||||
* @param clientSecret baidu应用的Secret Key
|
||||
* @param code baidu授权前的code,用来换token
|
||||
* @param clientId baidu 应用的API Key
|
||||
* @param clientSecret baidu 应用的Secret Key
|
||||
* @param code baidu 授权前的code,用来换token
|
||||
* @param redirectUri 待跳转的页面
|
||||
* @return full url
|
||||
*/
|
||||
public static String getBaiduAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
|
||||
return MessageFormat.format(BAIDU_ACCESS_TOKEN_PATTERN, ApiUrl.BAIDU.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
return MessageFormat.format(BAIDU_ACCESS_TOKEN_PATTERN, AuthSource.BAIDU.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +241,7 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getBaiduUserInfoUrl(String token) {
|
||||
return MessageFormat.format(BAIDU_USER_INFO_PATTERN, ApiUrl.BAIDU.userInfo(), token);
|
||||
return MessageFormat.format(BAIDU_USER_INFO_PATTERN, AuthSource.BAIDU.userInfo(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,30 +252,30 @@ public class UrlBuilder {
|
||||
* @return json
|
||||
*/
|
||||
public static String getBaiduAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(BAIDU_AUTHORIZE_PATTERN, ApiUrl.BAIDU.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(BAIDU_AUTHORIZE_PATTERN, AuthSource.BAIDU.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取收回baidu授权的地址
|
||||
*
|
||||
* @param accessToken baidu授权登录后的token
|
||||
* @param accessToken baidu 授权登录后的token
|
||||
* @return json
|
||||
*/
|
||||
public static String getBaiduRevokeUrl(String accessToken) {
|
||||
return MessageFormat.format(BAIDU_REVOKE_PATTERN, ApiUrl.BAIDU.revoke(), accessToken);
|
||||
return MessageFormat.format(BAIDU_REVOKE_PATTERN, AuthSource.BAIDU.revoke(), accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取csdn token的接口地址
|
||||
*
|
||||
* @param clientId csdn应用的App Key
|
||||
* @param clientSecret csdn应用的App Secret
|
||||
* @param code csdn授权前的code,用来换token
|
||||
* @param clientId csdn 应用的App Key
|
||||
* @param clientSecret csdn 应用的App Secret
|
||||
* @param code csdn 授权前的code,用来换token
|
||||
* @param redirectUri 待跳转的页面
|
||||
* @return full url
|
||||
*/
|
||||
public static String getCsdnAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
|
||||
return MessageFormat.format(CSDN_ACCESS_TOKEN_PATTERN, ApiUrl.CSDN.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
return MessageFormat.format(CSDN_ACCESS_TOKEN_PATTERN, AuthSource.CSDN.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,7 +285,7 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getCsdnUserInfoUrl(String token) {
|
||||
return MessageFormat.format(CSDN_USER_INFO_PATTERN, ApiUrl.CSDN.userInfo(), token);
|
||||
return MessageFormat.format(CSDN_USER_INFO_PATTERN, AuthSource.CSDN.userInfo(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,19 +296,19 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getCsdnAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(CSDN_AUTHORIZE_PATTERN, ApiUrl.CSDN.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(CSDN_AUTHORIZE_PATTERN, AuthSource.CSDN.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取coding token的接口地址
|
||||
*
|
||||
* @param clientId coding应用的App Key
|
||||
* @param clientSecret coding应用的App Secret
|
||||
* @param code coding授权前的code,用来换token
|
||||
* @param clientId coding 应用的App Key
|
||||
* @param clientSecret coding 应用的App Secret
|
||||
* @param code coding 授权前的code,用来换token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getCodingAccessTokenUrl(String clientId, String clientSecret, String code) {
|
||||
return MessageFormat.format(CODING_ACCESS_TOKEN_PATTERN, ApiUrl.CODING.accessToken(), clientId, clientSecret, code);
|
||||
return MessageFormat.format(CODING_ACCESS_TOKEN_PATTERN, AuthSource.CODING.accessToken(), clientId, clientSecret, code);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,7 +318,7 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getCodingUserInfoUrl(String token) {
|
||||
return MessageFormat.format(CODING_USER_INFO_PATTERN, ApiUrl.CODING.userInfo(), token);
|
||||
return MessageFormat.format(CODING_USER_INFO_PATTERN, AuthSource.CODING.userInfo(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,19 +329,19 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getCodingAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(CODING_AUTHORIZE_PATTERN, ApiUrl.CODING.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(CODING_AUTHORIZE_PATTERN, AuthSource.CODING.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取腾讯云开发者平台 token的接口地址
|
||||
*
|
||||
* @param clientId coding应用的App Key
|
||||
* @param clientSecret coding应用的App Secret
|
||||
* @param code coding授权前的code,用来换token
|
||||
* @param clientId coding 应用的App Key
|
||||
* @param clientSecret coding 应用的App Secret
|
||||
* @param code coding 授权前的code,用来换token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getTencentCloudAccessTokenUrl(String clientId, String clientSecret, String code) {
|
||||
return MessageFormat.format(TENCENT_ACCESS_TOKEN_PATTERN, ApiUrl.TENCENTCLOUD.accessToken(), clientId, clientSecret, code);
|
||||
return MessageFormat.format(TENCENT_ACCESS_TOKEN_PATTERN, AuthSource.TENCENT_CLOUD.accessToken(), clientId, clientSecret, code);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,7 +351,7 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getTencentCloudUserInfoUrl(String token) {
|
||||
return MessageFormat.format(TENCENT_USER_INFO_PATTERN, ApiUrl.TENCENTCLOUD.userInfo(), token);
|
||||
return MessageFormat.format(TENCENT_USER_INFO_PATTERN, AuthSource.TENCENT_CLOUD.userInfo(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,20 +362,20 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getTencentCloudAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(TENCENT_AUTHORIZE_PATTERN, ApiUrl.TENCENTCLOUD.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(TENCENT_AUTHORIZE_PATTERN, AuthSource.TENCENT_CLOUD.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取oschina token的接口地址
|
||||
*
|
||||
* @param clientId oschina应用的App Key
|
||||
* @param clientSecret oschina应用的App Secret
|
||||
* @param code oschina授权前的code,用来换token
|
||||
* @param clientId oschina 应用的App Key
|
||||
* @param clientSecret oschina 应用的App Secret
|
||||
* @param code oschina 授权前的code,用来换token
|
||||
* @param redirectUri 待跳转的页面
|
||||
* @return full url
|
||||
*/
|
||||
public static String getOschinaAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
|
||||
return MessageFormat.format(OSCHINA_ACCESS_TOKEN_PATTERN, ApiUrl.OSCHINA.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
return MessageFormat.format(OSCHINA_ACCESS_TOKEN_PATTERN, AuthSource.OSCHINA.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,7 +385,7 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getOschinaUserInfoUrl(String token) {
|
||||
return MessageFormat.format(OSCHINA_USER_INFO_PATTERN, ApiUrl.OSCHINA.userInfo(), token);
|
||||
return MessageFormat.format(OSCHINA_USER_INFO_PATTERN, AuthSource.OSCHINA.userInfo(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,31 +396,32 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getOschinaAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(OSCHINA_AUTHORIZE_PATTERN, ApiUrl.OSCHINA.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(OSCHINA_AUTHORIZE_PATTERN, AuthSource.OSCHINA.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取qq token的接口地址
|
||||
*
|
||||
* @param clientId qq应用的App Key
|
||||
* @param clientSecret qq应用的App Secret
|
||||
* @param code qq授权前的code,用来换token
|
||||
* @param clientId qq 应用的App Key
|
||||
* @param clientSecret qq 应用的App Secret
|
||||
* @param code qq 授权前的code,用来换token
|
||||
* @param redirectUri 待跳转的页面
|
||||
* @return full url
|
||||
*/
|
||||
public static String getQqAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
|
||||
return MessageFormat.format(QQ_ACCESS_TOKEN_PATTERN, ApiUrl.QQ.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
return MessageFormat.format(QQ_ACCESS_TOKEN_PATTERN, AuthSource.QQ.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取qq用户详情的接口地址
|
||||
*
|
||||
* @param token qq 应用的token
|
||||
* @param openId qq 应用的openId
|
||||
* @param clientId qq 应用的clientId
|
||||
* @param token qq 应用的token
|
||||
* @param openId qq 应用的openId
|
||||
* @return full url
|
||||
*/
|
||||
public static String getQqUserInfoUrl(String token, String openId) {
|
||||
return MessageFormat.format(QQ_USER_INFO_PATTERN, ApiUrl.QQ.userInfo(), token, openId);
|
||||
public static String getQqUserInfoUrl(String clientId, String token, String openId) {
|
||||
return MessageFormat.format(QQ_USER_INFO_PATTERN, AuthSource.QQ.userInfo(), clientId, token, openId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,7 +432,7 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getQqAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(QQ_AUTHORIZE_PATTERN, ApiUrl.QQ.authorize(), clientId, redirectUrl, System.currentTimeMillis());
|
||||
return MessageFormat.format(QQ_AUTHORIZE_PATTERN, AuthSource.QQ.authorize(), clientId, redirectUrl, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,65 +454,66 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getAlipayAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(ALIPAY_AUTHORIZE_PATTERN, ApiUrl.ALIPAY.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(ALIPAY_AUTHORIZE_PATTERN, AuthSource.ALIPAY.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信 授权地址
|
||||
*
|
||||
* @param clientId 微信应用的appid
|
||||
* @param redirectUrl 微信应用授权成功后的回调地址
|
||||
* @param clientId 微信 应用的appid
|
||||
* @param redirectUrl 微信 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getWeChatAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(WECHAT_AUTHORIZE_PATTERN, ApiUrl.WECHAT.authorize(), clientId, redirectUrl, System.currentTimeMillis());
|
||||
return MessageFormat.format(WECHAT_AUTHORIZE_PATTERN, AuthSource.WECHAT.authorize(), clientId, redirectUrl, System
|
||||
.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信 token的接口地址
|
||||
*
|
||||
* @param clientId 微信应用的appid
|
||||
* @param clientSecret 微信应用的secret
|
||||
* @param code 微信授权前的code,用来换token
|
||||
* @param clientId 微信 应用的appid
|
||||
* @param clientSecret 微信 应用的secret
|
||||
* @param code 微信 授权前的code,用来换token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getWeChatAccessTokenUrl(String clientId, String clientSecret, String code) {
|
||||
return MessageFormat.format(WECHAT_ACCESS_TOKEN_PATTERN, ApiUrl.WECHAT.accessToken(), clientId, clientSecret, code);
|
||||
return MessageFormat.format(WECHAT_ACCESS_TOKEN_PATTERN, AuthSource.WECHAT.accessToken(), clientId, clientSecret, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信 用户详情的接口地址
|
||||
*
|
||||
* @param token 微信应用返回的 access token
|
||||
* @param openId 微信应用返回的openId
|
||||
* @param token 微信 应用返回的 access token
|
||||
* @param openId 微信 应用返回的openId
|
||||
* @return full url
|
||||
*/
|
||||
public static String getWeChatUserInfoUrl(String token, String openId) {
|
||||
return MessageFormat.format(WECHAT_USER_INFO_PATTERN, ApiUrl.WECHAT.userInfo(), token, openId);
|
||||
return MessageFormat.format(WECHAT_USER_INFO_PATTERN, AuthSource.WECHAT.userInfo(), token, openId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信 刷新令牌 地址
|
||||
*
|
||||
* @param clientId 微信应用的appid
|
||||
* @param refreshToken 微信应用返回的刷新token
|
||||
* @param clientId 微信 应用的appid
|
||||
* @param refreshToken 微信 应用返回的刷新token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getWeChatRefreshUrl(String clientId, String refreshToken) {
|
||||
return MessageFormat.format(WECHAT_REFRESH_TOKEN_PATTERN, ApiUrl.WECHAT.refresh(), clientId, refreshToken);
|
||||
return MessageFormat.format(WECHAT_REFRESH_TOKEN_PATTERN, AuthSource.WECHAT.refresh(), clientId, refreshToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Taobao token的接口地址: 淘宝的授权登录,在这一步就会返回用户信息
|
||||
*
|
||||
* @param clientId taobao应用的App Key
|
||||
* @param clientSecret taobao应用的App Secret
|
||||
* @param code taobao授权前的code,用来换token
|
||||
* @param clientId taobao 应用的App Key
|
||||
* @param clientSecret taobao 应用的App Secret
|
||||
* @param code taobao 授权前的code,用来换token
|
||||
* @param redirectUri 待跳转的页面
|
||||
* @return full url
|
||||
*/
|
||||
public static String getTaobaoAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
|
||||
return MessageFormat.format(TAOBAO_ACCESS_TOKEN_PATTERN, ApiUrl.TAOBAO.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
return MessageFormat.format(TAOBAO_ACCESS_TOKEN_PATTERN, AuthSource.TAOBAO.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -490,6 +524,299 @@ public class UrlBuilder {
|
||||
* @return full url
|
||||
*/
|
||||
public static String getTaobaoAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(TAOBAO_AUTHORIZE_PATTERN, ApiUrl.TAOBAO.authorize(), clientId, redirectUrl);
|
||||
return MessageFormat.format(TAOBAO_AUTHORIZE_PATTERN, AuthSource.TAOBAO.authorize(), clientId, redirectUrl, System
|
||||
.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Google授权地址
|
||||
*
|
||||
* @param clientId google 应用的Client ID
|
||||
* @param redirectUrl google 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getGoogleAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(GOOGLE_AUTHORIZE_PATTERN, AuthSource.GOOGLE.authorize(), clientId, redirectUrl, System
|
||||
.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Google token的接口地址
|
||||
*
|
||||
* @param clientId google 应用的Client ID
|
||||
* @param clientSecret google 应用的Client Secret
|
||||
* @param code google 授权前的code,用来换token
|
||||
* @param redirectUri 待跳转的页面
|
||||
* @return full url
|
||||
*/
|
||||
public static String getGoogleAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
|
||||
return MessageFormat.format(GOOGLE_ACCESS_TOKEN_PATTERN, AuthSource.GOOGLE.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Google用户详情的接口地址
|
||||
*
|
||||
* @param token google 应用的token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getGoogleUserInfoUrl(String token) {
|
||||
return MessageFormat.format(GOOGLE_USER_INFO_PATTERN, AuthSource.GOOGLE.userInfo(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Facebook授权地址
|
||||
*
|
||||
* @param clientId Facebook 应用的Client ID
|
||||
* @param redirectUrl Facebook 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getFacebookAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(FACEBOOK_AUTHORIZE_PATTERN, AuthSource.FACEBOOK.authorize(), clientId, redirectUrl, System
|
||||
.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Facebook token的接口地址
|
||||
*
|
||||
* @param clientId Facebook 应用的Client ID
|
||||
* @param clientSecret Facebook 应用的Client Secret
|
||||
* @param code Facebook 授权前的code,用来换token
|
||||
* @param redirectUri 待跳转的页面
|
||||
* @return full url
|
||||
*/
|
||||
public static String getFacebookAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUri) {
|
||||
return MessageFormat.format(FACEBOOK_ACCESS_TOKEN_PATTERN, AuthSource.FACEBOOK.accessToken(), clientId, clientSecret, code, redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Facebook用户详情的接口地址
|
||||
*
|
||||
* @param token Facebook 应用的token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getFacebookUserInfoUrl(String token) {
|
||||
return MessageFormat.format(FACEBOOK_USER_INFO_PATTERN, AuthSource.FACEBOOK.userInfo(), token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Douyin授权地址
|
||||
*
|
||||
* @param clientId Douyin 应用的Client ID
|
||||
* @param redirectUrl Douyin 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getDouyinAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(DOUYIN_AUTHORIZE_PATTERN, AuthSource.DOUYIN.authorize(), clientId, redirectUrl, System
|
||||
.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Douyin token的接口地址
|
||||
*
|
||||
* @param clientId Douyin 应用的Client ID
|
||||
* @param clientSecret Douyin 应用的Client Secret
|
||||
* @param code Douyin 授权前的code,用来换token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getDouyinAccessTokenUrl(String clientId, String clientSecret, String code) {
|
||||
return MessageFormat.format(DOUYIN_ACCESS_TOKEN_PATTERN, AuthSource.DOUYIN.accessToken(), clientId, clientSecret, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Douyin用户详情的接口地址
|
||||
*
|
||||
* @param token Douyin 应用的token
|
||||
* @param openId 用户在当前应用的唯一标识 通过token接口获取
|
||||
* @return full url
|
||||
*/
|
||||
public static String getDouyinUserInfoUrl(String token, String openId) {
|
||||
return MessageFormat.format(DOUYIN_USER_INFO_PATTERN, AuthSource.DOUYIN.userInfo(), token, openId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Douyin 刷新令牌 地址
|
||||
*
|
||||
* @param clientId Douyin 应用的client_key
|
||||
* @param refreshToken Douyin 应用返回的refresh_token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getDouyinRefreshUrl(String clientId, String refreshToken) {
|
||||
return MessageFormat.format(DOUYIN_REFRESH_TOKEN_PATTERN, AuthSource.DOUYIN.refresh(), clientId, refreshToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Linkedin授权地址
|
||||
*
|
||||
* @param clientId Linkedin 应用的Client ID
|
||||
* @param redirectUrl Linkedin 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getLinkedinAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(LINKEDIN_AUTHORIZE_PATTERN, AuthSource.LINKEDIN.authorize(), clientId, redirectUrl, System
|
||||
.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Linkedin token的接口地址
|
||||
*
|
||||
* @param clientId Linkedin 应用的Client ID
|
||||
* @param clientSecret Linkedin 应用的Client Secret
|
||||
* @param code Linkedin 授权前的code,用来换token
|
||||
* @param redirectUrl Linkedin 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getLinkedinAccessTokenUrl(String clientId, String clientSecret, String code, String redirectUrl) {
|
||||
return MessageFormat.format(LINKEDIN_ACCESS_TOKEN_PATTERN, AuthSource.LINKEDIN.accessToken(), clientId, clientSecret, code, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Linkedin用户详情的接口地址
|
||||
*
|
||||
* @return full url
|
||||
*/
|
||||
public static String getLinkedinUserInfoUrl() {
|
||||
return MessageFormat.format(LINKEDIN_USER_INFO_PATTERN, AuthSource.LINKEDIN.userInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Linkedin 刷新令牌 地址
|
||||
*
|
||||
* @param clientId Linkedin 应用的client_key
|
||||
* @param clientSecret Linkedin 应用的Client Secret
|
||||
* @param refreshToken Linkedin 应用返回的refresh_token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getLinkedinRefreshUrl(String clientId, String clientSecret, String refreshToken) {
|
||||
return MessageFormat.format(LINKEDIN_REFRESH_TOKEN_PATTERN, AuthSource.LINKEDIN.refresh(), clientId, clientSecret, refreshToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微软授权地址
|
||||
*
|
||||
* @param clientId 微软 应用的Client ID
|
||||
* @param redirectUrl 微软 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getMicrosoftAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(MICROSOFT_AUTHORIZE_PATTERN, AuthSource.MICROSOFT.authorize(), clientId, redirectUrl, System
|
||||
.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微软 token的接口地址
|
||||
*
|
||||
* @param clientId 微软 应用的Client ID
|
||||
* @param clientSecret 微软 应用的Client Secret
|
||||
* @param redirectUrl 微软 应用授权成功后的回调地址
|
||||
* @param code 微软 授权前的code,用来换token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getMicrosoftAccessTokenUrl(String clientId, String clientSecret, String redirectUrl, String code) {
|
||||
return MessageFormat.format(MICROSOFT_ACCESS_TOKEN_PATTERN, AuthSource.MICROSOFT.accessToken(), clientId, clientSecret, redirectUrl, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微软用户详情的接口地址
|
||||
*
|
||||
* @return full url
|
||||
*/
|
||||
public static String getMicrosoftUserInfoUrl() {
|
||||
return MessageFormat.format(MICROSOFT_USER_INFO_PATTERN, AuthSource.MICROSOFT.userInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微软 刷新令牌 地址
|
||||
*
|
||||
* @param clientId 微软 应用的client_key
|
||||
* @param clientSecret 微软 应用的Client Secret
|
||||
* @param redirectUrl 微软 应用授权成功后的回调地址
|
||||
* @param refreshToken 微软 应用返回的refresh_token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getMicrosoftRefreshUrl(String clientId, String clientSecret, String redirectUrl, String refreshToken) {
|
||||
return MessageFormat.format(MICROSOFT_REFRESH_TOKEN_PATTERN, AuthSource.MICROSOFT.refresh(), clientId, clientSecret, redirectUrl, refreshToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小米授权地址
|
||||
*
|
||||
* @param clientId 小米 应用的Client ID
|
||||
* @param redirectUrl 小米 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getMiAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(MI_AUTHORIZE_PATTERN, AuthSource.MI.authorize(), clientId, redirectUrl, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小米 token的接口地址
|
||||
*
|
||||
* @param clientId 小米 应用的Client ID
|
||||
* @param clientSecret 小米 应用的Client Secret
|
||||
* @param redirectUrl 小米 应用授权成功后的回调地址
|
||||
* @param code 小米 授权前的code,用来换token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getMiAccessTokenUrl(String clientId, String clientSecret, String redirectUrl, String code) {
|
||||
return MessageFormat.format(MI_ACCESS_TOKEN_PATTERN, AuthSource.MI.accessToken(), clientId, clientSecret, redirectUrl, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小米用户详情的接口地址
|
||||
*
|
||||
* @param clientId 小米 应用的client_key
|
||||
* @param token token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getMiUserInfoUrl(String clientId, String token) {
|
||||
return MessageFormat.format(MI_USER_INFO_PATTERN, AuthSource.MI.userInfo(), clientId, token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小米 刷新令牌 地址
|
||||
*
|
||||
* @param clientId 小米 应用的client_key
|
||||
* @param clientSecret 小米 应用的Client Secret
|
||||
* @param redirectUrl 小米 应用授权成功后的回调地址
|
||||
* @param refreshToken 小米 应用返回的refresh_token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getMiRefreshUrl(String clientId, String clientSecret, String redirectUrl, String refreshToken) {
|
||||
return MessageFormat.format(MI_REFRESH_TOKEN_PATTERN, AuthSource.MI.refresh(), clientId, clientSecret, redirectUrl, refreshToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取今日头条授权地址
|
||||
*
|
||||
* @param clientId 今日头条 应用的Client ID
|
||||
* @param redirectUrl 今日头条 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getToutiaoAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(TOUTIAO_AUTHORIZE_PATTERN, AuthSource.TOUTIAO.authorize(), clientId, redirectUrl, System
|
||||
.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取今日头条 token的接口地址
|
||||
*
|
||||
* @param clientId 今日头条 应用的Client ID
|
||||
* @param clientSecret 今日头条 应用的Client Secret
|
||||
* @param code 今日头条 授权前的code,用来换token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getToutiaoAccessTokenUrl(String clientId, String clientSecret, String code) {
|
||||
return MessageFormat.format(TOUTIAO_ACCESS_TOKEN_PATTERN, AuthSource.TOUTIAO.accessToken(), clientId, clientSecret, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取今日头条用户详情的接口地址
|
||||
*
|
||||
* @param clientId 今日头条 应用的client_key
|
||||
* @param token token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getToutiaoUserInfoUrl(String clientId, String token) {
|
||||
return MessageFormat.format(TOUTIAO_USER_INFO_PATTERN, AuthSource.TOUTIAO.userInfo(), clientId, token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,4 +141,56 @@ public class AuthRequestTest {
|
||||
// 授权登录后会返回一个code,用这个code进行登录
|
||||
AuthResponse login = authRequest.login("code");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void googleTest() {
|
||||
AuthRequest authRequest = new AuthGoogleRequest(AuthConfig.builder()
|
||||
.clientId("clientId")
|
||||
.clientSecret("clientSecret")
|
||||
.redirectUri("redirectUri")
|
||||
.build());
|
||||
// 返回授权页面,可自行调整
|
||||
String url = authRequest.authorize();
|
||||
// 授权登录后会返回一个code,用这个code进行登录
|
||||
AuthResponse login = authRequest.login("code");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void facebookTest() {
|
||||
AuthRequest authRequest = new AuthFacebookRequest(AuthConfig.builder()
|
||||
.clientId("clientId")
|
||||
.clientSecret("clientSecret")
|
||||
.redirectUri("redirectUri")
|
||||
.build());
|
||||
// 返回授权页面,可自行调整
|
||||
String url = authRequest.authorize();
|
||||
// 授权登录后会返回一个code,用这个code进行登录
|
||||
AuthResponse login = authRequest.login("code");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void microsoftTest() {
|
||||
AuthRequest authRequest = new AuthMicrosoftRequest(AuthConfig.builder()
|
||||
.clientId("clientId")
|
||||
.clientSecret("clientSecret")
|
||||
.redirectUri("redirectUri")
|
||||
.build());
|
||||
// 返回授权页面,可自行调整
|
||||
String url = authRequest.authorize();
|
||||
// 授权登录后会返回一个code,用这个code进行登录
|
||||
AuthResponse login = authRequest.login("code");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void miTest() {
|
||||
AuthRequest authRequest = new AuthMiRequest(AuthConfig.builder()
|
||||
.clientId("clientId")
|
||||
.clientSecret("clientSecret")
|
||||
.redirectUri("redirectUri")
|
||||
.build());
|
||||
// 返回授权页面,可自行调整
|
||||
String url = authRequest.authorize();
|
||||
// 授权登录后会返回一个code,用这个code进行登录
|
||||
AuthResponse login = authRequest.login("code");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,45 @@
|
||||
### 2019/06/19
|
||||
1. 合并[xkcoding](https://github.com/xkcoding)提交的[PR](https://github.com/zhangyd-c/JustAuth/pull/14),重构了部分代码,jar包由原来的`130+kb`优化到现在的`110+kb`
|
||||
2. 合并[skqing](https://gitee.com/skqing)提交的[PR](https://gitee.com/yadong.zhang/JustAuth/pulls/3), 解决抖音登录失败问题
|
||||
|
||||
### 2019/06/18
|
||||
1. 解决Issue [#IY2HW](https://gitee.com/yadong.zhang/JustAuth/issues/IY2HW)
|
||||
2. 解决Issue [#IY2OH](https://gitee.com/yadong.zhang/JustAuth/issues/IY2OH)
|
||||
3. 解决Issue [#IY2FV](https://gitee.com/yadong.zhang/JustAuth/issues/IY2FV)
|
||||
4. 修复部分注释、拼写错误
|
||||
5. 解决Issue [#IY1QR](https://gitee.com/yadong.zhang/JustAuth/issues/IY1QR) 增加对Config属性的校验功能,主要校验redirect uri的合法性
|
||||
6. 合并[skqing](https://gitee.com/skqing)提交的[PR](https://gitee.com/yadong.zhang/JustAuth/pulls/2),解决一些BUG
|
||||
|
||||
### 2019/06/06
|
||||
1. 增加今日头条的授权登陆
|
||||
2. 发布1.6.0-beta版本,今日头条开发者暂时不能认证, 所以无法做测试,等测试通过后,正式发布release版本
|
||||
|
||||
### 2019/05/28
|
||||
1. 增加小米账号和微软的授权登陆
|
||||
2. 发布1.5.0版本
|
||||
|
||||
### 2019/05/26
|
||||
1. 增加抖音和Linkedin的授权登陆
|
||||
2. 修改部分图片命名
|
||||
3. 优化部分代码
|
||||
4. 修复`AuthSource`中腾讯云开发平台的拼写错误:`TENCEN_CLOUD`->`TENCENT_CLOUD`
|
||||
5. 修复支付宝登陆时用户名为空的问题
|
||||
|
||||
|
||||
### 2019/05/24
|
||||
1. 修复一些问题
|
||||
2. 升级api,在AuthUser中增加`uuid`属性,可以通过`uuid` + `source`唯一确定一个用户,此举解决了用户身份归属的问题。
|
||||
3. 发布1.3.3版本的jar包到公开仓库(1.3.2忘记发布了,( ╯□╰ ))
|
||||
4. 重要:经咨询官方客服得知,CSDN的授权开放平台已经下线,如果以前申请过的应用,可以继续使用,但是不再支持申请新的应用。so, 本项目中的CSDN登录只能针对少部分用户使用了
|
||||
|
||||
### 2019/05/23
|
||||
1. 修复QQ登录的问题
|
||||
2. 发布1.3.1版本的jar包到公开仓库
|
||||
|
||||
### 2019/05/21
|
||||
1. 新增google授权登录
|
||||
2. 新增facebook授权登录
|
||||
3. 发布1.3.0版本的jar包到公开仓库
|
||||
|
||||
### 2019/05/18
|
||||
1. 发布1.1.0版本的jar包到公开仓库(支持qq和微信登录)
|
||||
@@ -6,7 +48,6 @@
|
||||
4. 修复一些bug
|
||||
5. 发布1.2.0版本的jar包到公开仓库(支持淘宝登录)
|
||||
|
||||
----
|
||||
### 2019/05/17
|
||||
1. 增加qq和微信的授权登录
|
||||
2. 修改getAccessToken方法的返回值
|
||||
Reference in New Issue
Block a user