Compare commits
41 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 14fab8cd77 | |||
| 3c0c809dfc | |||
| 6f40460cce | |||
| e81e92130b | |||
| 85afd754a9 | |||
| a8709a30d3 | |||
| ffa48970e5 | |||
| 5d753de282 | |||
| a739ca374e | |||
| 880a7d4157 | |||
| 6fe1aa62c6 | |||
| 7857db7824 | |||
| 7ed248689f | |||
| d24733e016 | |||
| 2dba2baef7 | |||
| 2abca4f10f | |||
| 7db4dcce2a | |||
| 14c2b4cacf | |||
| 54e97b0ec4 | |||
| aa187dd109 | |||
| 3cf8beab83 | |||
| 3824bc0887 | |||
| b8c3caea73 | |||
| 4fb81436e2 | |||
| a52d34ed75 | |||
| 83856c8350 | |||
| 79574a66e5 | |||
| 6186236a13 | |||
| 8abe74db9d | |||
| 188c52ca6b | |||
| e04d2abe3a | |||
| 144decd932 | |||
| 87c2a1b2cd | |||
| 2e0262ed7e | |||
| 8520d0b24c | |||
| 40b48a9f2a | |||
| d176b6089c | |||
| 9b1bf7bb47 | |||
| 0ed1814deb | |||
| 755b72de99 | |||
| 0e24f06022 |
@@ -21,3 +21,10 @@
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
# exclude idea files
|
||||
.idea
|
||||
*.iml
|
||||
*.sh
|
||||
|
||||
target
|
||||
@@ -9,7 +9,7 @@
|
||||
<img src="https://img.shields.io/badge/Maven Central-1.0.0-blue.svg" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/badge/License-GPL%20v3-yellow.svg" ></img>
|
||||
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" ></img>
|
||||
</a>
|
||||
<a target="_blank" href="https://www.oracle.com/technetwork/java/javase/downloads/index.html">
|
||||
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
|
||||
@@ -18,38 +18,23 @@
|
||||
|
||||
<center>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<td align="center" width="200"><a href="https://gitee.com/"><img src="https://gitee.com/logo_icon.png" width="30"></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="30"></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="30"></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="30"></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="30"></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="30"></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="30"></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="30"></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="30"></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="30"></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="30"></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="30"></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>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tr>
|
||||
<td align="center" width="200"><a href="#授权gitee"><img src="https://gitee.com/logo_icon.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/dingding.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/tencent_cloud.png" width="20"></a></td>
|
||||
<td align="center" width="200"><a href="#授权oschina"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschinas.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/wechats.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="#授权csdn"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png" width="20"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
|
||||
@@ -67,7 +52,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
|
||||
<dependency>
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
```
|
||||
- 调用api
|
||||
@@ -84,6 +69,8 @@ authRequest.authorize();
|
||||
authRequest.login("code");
|
||||
```
|
||||
|
||||
**配套Demo**:[JustAuth-demo](https://gitee.com/yadong.zhang/JustAuth-demo)
|
||||
|
||||
具体的例子可以参考:
|
||||
|
||||
- [实现Gitee授权登录](http://t.cn/ExDKxQs)
|
||||
@@ -94,16 +81,19 @@ authRequest.login("code");
|
||||
|:------:|:-------:|:-------:|
|
||||
| <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/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/apps?_blank" 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/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/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/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/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/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/qq.png" width="20"> | AuthQqRequest | <a href="https://connect.qq.com/" target="_blank">参考文档</a> |
|
||||
| <img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png" width="20"> | AuthWechatRequest | 待续 |
|
||||
|
||||
## 后续开发计划
|
||||
|
||||
@@ -111,6 +101,15 @@ authRequest.login("code");
|
||||
|
||||
另外,期待您和我一起完善这个项目!
|
||||
|
||||
## 贡献代码
|
||||
|
||||
1. fork本项目到自己的repo
|
||||
2. 把fork过去的项目也就是你仓库中的项目clone到你的本地
|
||||
3. 修改代码
|
||||
4. commit后push到自己的库
|
||||
5. 发起PR(pull request) 请求
|
||||
6. 等待作者合并
|
||||
|
||||
## 致谢
|
||||
|
||||
在项目立项初期,也对当前开源圈的一些相同类型的项目作过调研,同时本项目也参考过这些项目,再次感谢开源圈内的朋友。
|
||||
@@ -118,7 +117,7 @@ authRequest.login("code");
|
||||
[YurunOAuthLogin](https://gitee.com/yurunsoft/YurunOAuthLogin): PHP 第三方登录授权 SDK
|
||||
|
||||
|
||||
## 参考图例
|
||||
## 参考授权图例
|
||||
|
||||
#### 授权gitee
|
||||
|
||||
@@ -156,11 +155,11 @@ authRequest.login("code");
|
||||
|
||||

|
||||
|
||||
#### 授权csdn
|
||||
#### 授权qq
|
||||
|
||||
待续
|
||||
|
||||
#### 授权qq
|
||||
#### 授权csdn
|
||||
|
||||
待续
|
||||
|
||||
@@ -168,6 +167,32 @@ authRequest.login("code");
|
||||
|
||||
待续
|
||||
|
||||
#### 授权淘宝
|
||||
|
||||

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

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

|
||||
|
||||
## 关注&交流
|
||||
|
||||
| 公众号 | 微信(备注:加群) |
|
||||
| :------------: | :------------: |
|
||||
| <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群**
|
||||
|
||||
- JustAuth交流群 (230017570):专业交流该项目
|
||||
|
||||
- 开源总群 (190886500):各个开源项目的都有,也有博客建设等方面的朋友。(注意,该群需付费进入,防止发垃圾广告、垃圾推广等人士)
|
||||
|
||||
|
||||
## 请喝咖啡
|
||||
|
||||
| 支付宝 | 微信 |
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.3.1</version>
|
||||
|
||||
<name>JustAuth</name>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth</url>
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<name>MIT</name>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE</url>
|
||||
</license>
|
||||
</licenses>
|
||||
@@ -29,6 +29,12 @@
|
||||
<developer>
|
||||
<name>yadong.zhang</name>
|
||||
<email>yadong.zhang0415@gmail.com</email>
|
||||
<url>https://www.zhyd.me</url>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>Yangkai.Shen</name>
|
||||
<email>shenyangkai1994@gmail.com</email>
|
||||
<url>https://xkcoding.com</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
@@ -45,6 +51,7 @@
|
||||
<junit-version>4.11</junit-version>
|
||||
<fastjson-version>1.2.44</fastjson-version>
|
||||
<google-api-version>1.28.0</google-api-version>
|
||||
<guava-version>27.1-jre</guava-version>
|
||||
<alipay-sdk-version>3.7.4.ALL</alipay-sdk-version>
|
||||
</properties>
|
||||
|
||||
@@ -172,14 +179,14 @@
|
||||
</build>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>sonatype-oss</id>
|
||||
<id>sonatype-nexus-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>sonatype-oss</id>
|
||||
<id>sonatype-nexus-staging</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
</project>
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 支付宝授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AlipayAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getAlipayAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
|
||||
/**
|
||||
* 授权接口,用来获取具体第三方平台的授权地址
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public interface Authorization {
|
||||
|
||||
String getAuthorizeUrl(AuthConfig config);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.request.ResponseStatus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 授权工厂类,负责创建指定平台的授权类获取授权地址
|
||||
* <p>
|
||||
* 使用策略模式 + 工厂模式 避免大量的if else(swatch)操作
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthorizationFactory {
|
||||
|
||||
private static Map<String, Authorization> authorizationMap = new HashMap<>();
|
||||
private static boolean loader = false;
|
||||
|
||||
private AuthorizationFactory() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据第三方平台,获取具体的授权工具
|
||||
*
|
||||
* @param source 平台
|
||||
* @return 具体的Authorization
|
||||
*/
|
||||
public static Authorization getAuthorize(AuthSource source) {
|
||||
if (null == source) {
|
||||
throw new AuthException(ResponseStatus.NO_AUTH_SOURCE);
|
||||
}
|
||||
registerAllAuthorize();
|
||||
|
||||
Authorization authorization = authorizationMap.get(source.toString());
|
||||
if (null == authorization) {
|
||||
throw new AuthException(ResponseStatus.UNIDENTIFIED_PLATFORM);
|
||||
}
|
||||
return authorization;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将所有Authorize的实现类注册到authorizeMap中,
|
||||
* 每次增加新的平台都需要在这儿添加注册代码
|
||||
*/
|
||||
private static void registerAllAuthorize() {
|
||||
if (loader) {
|
||||
return;
|
||||
}
|
||||
AuthorizationFactory.register(AuthSource.ALIPAY, new AlipayAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.BAIDU, new BaiduAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.CODING, new CodingAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.CSDN, new CsdnAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.DINGTALK, new DingTalkAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.GITEE, new GiteeAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.GITHUB, new GithubAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.GOOGLE, new GoogleAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.OSCHINA, new OschinaAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.QQ, new QqAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.TAOBAO, new TaobaoAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.TENCEN_CLOUD, new TencentCloudAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.WECHAT, new WeChatAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.WEIBO, new WeiboAuthorization());
|
||||
AuthorizationFactory.register(AuthSource.FACEBOOK, new FacebookAuthorization());
|
||||
loader = true;
|
||||
}
|
||||
|
||||
private static void register(AuthSource authSource, Authorization authorization) {
|
||||
authorizationMap.put(authSource.toString(), authorization);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 百度授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class BaiduAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getBaiduAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* Coding授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class CodingAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getCodingAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* CSDN授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class CsdnAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getCsdnAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 钉钉授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class DingTalkAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getDingTalkQrConnectUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* Facebook授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.3
|
||||
* @since 1.3
|
||||
*/
|
||||
public class FacebookAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getFacebookAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 码云授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class GiteeAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getGiteeAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* Github授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class GithubAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getGithubAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* Google授权
|
||||
*
|
||||
* @author yangkai.shen (https://xkcoding.com)
|
||||
* @version 1.3
|
||||
* @since 1.3
|
||||
*/
|
||||
public class GoogleAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getGoogleAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 开源中国授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class OschinaAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getOschinaAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* QQ授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class QqAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getQqAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 淘宝授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class TaobaoAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getTaobaoAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 腾讯云授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class TencentCloudAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getTencentCloudAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 微信授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class WeChatAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getWeChatAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zhyd.oauth.authorization;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 微博授权
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class WeiboAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getAuthorizeUrl(AuthConfig config) {
|
||||
return UrlBuilder.getWeiboAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,31 @@
|
||||
package me.zhyd.oauth.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* JustAuth配置类
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 14:03
|
||||
* @since 1.8
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AuthConfig {
|
||||
|
||||
/**
|
||||
* 客户端id:对应个平台的appKey
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 客户端Secret:对应个平台的appSecret
|
||||
*/
|
||||
private String clientSecret;
|
||||
|
||||
/**
|
||||
* 登录成功后的回调地址
|
||||
*/
|
||||
|
||||
@@ -8,8 +8,6 @@ import me.zhyd.oauth.request.ResponseStatus;
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/24 21:20
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum ApiUrl {
|
||||
@@ -298,20 +296,190 @@ public enum ApiUrl {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* QQ
|
||||
*/
|
||||
QQ {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://graph.qq.com/oauth2.0/authorize";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://graph.qq.com/oauth2.0/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 微信
|
||||
*/
|
||||
WECHAT {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://open.weixin.qq.com/connect/qrconnect";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://api.weixin.qq.com/sns/oauth2/access_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
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";
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 淘宝
|
||||
*/
|
||||
TAOBAO {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://oauth.taobao.com/authorize";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://oauth.taobao.com/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Google
|
||||
*/
|
||||
GOOGLE {
|
||||
@Override
|
||||
public String authorize() {
|
||||
return "https://accounts.google.com/o/oauth2/v2/auth";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String accessToken() {
|
||||
return "https://www.googleapis.com/oauth2/v4/token";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String userInfo() {
|
||||
return "https://oauth2.googleapis.com/tokeninfo";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 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";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String revoke() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refresh() {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 授权的api
|
||||
*
|
||||
* @return url
|
||||
*/
|
||||
public abstract String authorize();
|
||||
|
||||
/**
|
||||
* 获取accessToken的api
|
||||
*
|
||||
* @return url
|
||||
*/
|
||||
public abstract String accessToken();
|
||||
|
||||
/**
|
||||
* 获取用户信息的api
|
||||
*
|
||||
* @return url
|
||||
*/
|
||||
public abstract String userInfo();
|
||||
|
||||
/**
|
||||
* 取消授权的api
|
||||
*
|
||||
* @return url
|
||||
*/
|
||||
public abstract String revoke();
|
||||
|
||||
/**
|
||||
* 刷新授权的api
|
||||
*
|
||||
* @return url
|
||||
*/
|
||||
public abstract String refresh();
|
||||
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import me.zhyd.oauth.request.ResponseStatus;
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 16:05
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthException extends RuntimeException {
|
||||
|
||||
@@ -5,8 +5,6 @@ import me.zhyd.oauth.utils.StringUtils;
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/19 19:13
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum AuthBaiduErrorCode {
|
||||
|
||||
@@ -3,8 +3,6 @@ package me.zhyd.oauth.model;
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/19 9:42
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum AuthDingTalkErrorCode {
|
||||
|
||||
@@ -7,8 +7,6 @@ import me.zhyd.oauth.request.ResponseStatus;
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 15:43
|
||||
* @since 1.8
|
||||
*/
|
||||
@Builder
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package me.zhyd.oauth.model;
|
||||
|
||||
/**
|
||||
* 授权来源(平台)
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 13:52
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum AuthSource {
|
||||
@@ -18,8 +18,12 @@ public enum AuthSource {
|
||||
OSCHINA,
|
||||
TENCEN_CLOUD,
|
||||
ALIPAY,
|
||||
|
||||
TAOBAO,
|
||||
QQ,
|
||||
WECHAT,
|
||||
/**
|
||||
* 谷歌登录,参考文档:https://developers.google.com/identity/protocols/OpenIDConnect
|
||||
*/
|
||||
GOOGLE,
|
||||
FACEBOOK,
|
||||
}
|
||||
|
||||
@@ -6,15 +6,23 @@ import lombok.Data;
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 15:43
|
||||
* @since 1.8
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class AuthToken {
|
||||
private String accessToken;
|
||||
private String expireIn;
|
||||
private int expireIn;
|
||||
private String refreshToken;
|
||||
private String uid;
|
||||
private String openId;
|
||||
private String accessCode;
|
||||
|
||||
/**
|
||||
* Google附带属性
|
||||
*/
|
||||
private String scope;
|
||||
private String tokenType;
|
||||
private String idToken;
|
||||
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import lombok.Data;
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 13:47
|
||||
* @since 1.8
|
||||
*/
|
||||
@Builder
|
||||
@@ -23,5 +21,5 @@ public class AuthUser {
|
||||
private String remark;
|
||||
private AuthUserGender gender;
|
||||
private AuthSource source;
|
||||
private String accessToken;
|
||||
private AuthToken token;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package me.zhyd.oauth.model;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 17:24
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum AuthUserGender {
|
||||
@@ -21,10 +21,12 @@ public enum AuthUserGender {
|
||||
if (code == null) {
|
||||
return UNKNOW;
|
||||
}
|
||||
if ("m".equals(code) || "男".equals(code) || "1".equals(code) || "male".equalsIgnoreCase(code) || "F".equalsIgnoreCase(code)) {
|
||||
String[] males = {"m", "男", "1", "male", "F"};
|
||||
if (Arrays.asList(males).contains(code)) {
|
||||
return MALE;
|
||||
}
|
||||
if ("f".equals(code) || "女".equals(code) || "0".equals(code) || "female".equalsIgnoreCase(code)) {
|
||||
String[] females = {"f", "女", "0", "female"};
|
||||
if (Arrays.asList(females).contains(code)) {
|
||||
return FEMALE;
|
||||
}
|
||||
return UNKNOW;
|
||||
|
||||
@@ -11,15 +11,16 @@ import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.consts.ApiUrl;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 支付宝登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/3/25 22:48
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthAlipayRequest extends BaseAuthRequest {
|
||||
@@ -32,7 +33,7 @@ public class AuthAlipayRequest extends BaseAuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAccessToken(String code) {
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
|
||||
request.setGrantType("authorization_code");
|
||||
request.setCode(code);
|
||||
@@ -45,11 +46,14 @@ public class AuthAlipayRequest extends BaseAuthRequest {
|
||||
if (!response.isSuccess()) {
|
||||
throw new AuthException(response.getSubMsg());
|
||||
}
|
||||
return response.getAccessToken();
|
||||
return AuthToken.builder()
|
||||
.accessToken(response.getAccessToken())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(String accessToken) {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest();
|
||||
AlipayUserInfoShareResponse response = null;
|
||||
try {
|
||||
@@ -68,7 +72,7 @@ public class AuthAlipayRequest extends BaseAuthRequest {
|
||||
.avatar(response.getAvatar())
|
||||
.location(String.format("%s %s", StringUtils.isEmpty(province) ? "" : province, StringUtils.isEmpty(city) ? "" : city))
|
||||
.gender(AuthUserGender.getRealGender(response.getGender()))
|
||||
.accessToken(accessToken)
|
||||
.token(authToken)
|
||||
.source(AuthSource.ALIPAY)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -3,16 +3,17 @@ 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.exception.AuthException;
|
||||
import me.zhyd.oauth.model.*;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 百度账号登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/19 18:43
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthBaiduRequest extends BaseAuthRequest {
|
||||
@@ -22,7 +23,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAccessToken(String code) {
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getBaiduAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
@@ -30,11 +31,14 @@ public class AuthBaiduRequest extends BaseAuthRequest {
|
||||
if (!AuthBaiduErrorCode.OK.equals(errorCode)) {
|
||||
throw new AuthException(errorCode.getDesc());
|
||||
}
|
||||
return accessTokenObject.getString("access_token");
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(String accessToken) {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getBaiduUserInfoUrl(accessToken)).execute();
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
@@ -46,16 +50,23 @@ public class AuthBaiduRequest extends BaseAuthRequest {
|
||||
.username(object.getString("username"))
|
||||
.nickname(object.getString("username"))
|
||||
.gender(AuthUserGender.getRealGender(object.getString("sex")))
|
||||
.accessToken(accessToken)
|
||||
.token(authToken)
|
||||
.source(AuthSource.BAIDU)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse revoke(String accessToken) {
|
||||
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")) {
|
||||
return AuthResponse.builder()
|
||||
.code(ResponseStatus.FAILURE.getCode())
|
||||
.msg(object.getString("error_msg"))
|
||||
.build();
|
||||
}
|
||||
ResponseStatus status = object.getIntValue("result") == 1 ? ResponseStatus.SUCCESS : ResponseStatus.FAILURE;
|
||||
return AuthResponse.builder().code(status.getCode()).msg(status.getMsg()).build();
|
||||
}
|
||||
|
||||
@@ -6,15 +6,16 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Cooding登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/23 15:48
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthCodingRequest extends BaseAuthRequest {
|
||||
@@ -24,18 +25,21 @@ public class AuthCodingRequest extends BaseAuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAccessToken(String code) {
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getCodingAccessTokenUrl(config.getClientId(), config.getClientSecret(), code);
|
||||
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
|
||||
if (accessTokenObject.getIntValue("code") != 0) {
|
||||
throw new AuthException("Unable to get token from coding using code [" + code + "]");
|
||||
}
|
||||
return accessTokenObject.getString("access_token");
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(String accessToken) {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getCodingUserInfoUrl(accessToken)).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.getIntValue("code") != 0) {
|
||||
@@ -52,7 +56,7 @@ public class AuthCodingRequest extends BaseAuthRequest {
|
||||
.gender(AuthUserGender.getRealGender(object.getString("sex")))
|
||||
.email(object.getString("email"))
|
||||
.remark(object.getString("slogan"))
|
||||
.accessToken(accessToken)
|
||||
.token(authToken)
|
||||
.source(AuthSource.CODING)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -6,14 +6,15 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
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.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* CSDN登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/23 15:00
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthCsdnRequest extends BaseAuthRequest {
|
||||
@@ -23,18 +24,21 @@ public class AuthCsdnRequest extends BaseAuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAccessToken(String code) {
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
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 accessTokenObject.getString("access_token");
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(String accessToken) {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getCsdnUserInfoUrl(accessToken)).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.containsKey("error_code")) {
|
||||
@@ -42,7 +46,7 @@ public class AuthCsdnRequest extends BaseAuthRequest {
|
||||
}
|
||||
return AuthUser.builder()
|
||||
.username(object.getString("username"))
|
||||
.accessToken(accessToken)
|
||||
.token(authToken)
|
||||
.source(AuthSource.CSDN)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import cn.hutool.json.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthDingTalkErrorCode;
|
||||
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.GlobalAuthUtil;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
@@ -15,10 +15,10 @@ import me.zhyd.oauth.utils.UrlBuilder;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 钉钉登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/18 18:43
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthDingTalkRequest extends BaseAuthRequest {
|
||||
@@ -28,12 +28,15 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAccessToken(String code) {
|
||||
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
return AuthToken.builder()
|
||||
.accessCode(code)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(String code) {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String code = authToken.getAccessCode();
|
||||
// 根据timestamp, appSecret计算签名值
|
||||
String stringToSign = System.currentTimeMillis() + "";
|
||||
String urlEncodeSignature = GlobalAuthUtil.generateDingTalkSignature(config.getClientSecret(), stringToSign);
|
||||
@@ -49,14 +52,8 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
|
||||
object = object.getJSONObject("user_info");
|
||||
return AuthUser.builder()
|
||||
.nickname(object.getStr("nick"))
|
||||
.username(object.getStr("nick"))
|
||||
.source(AuthSource.DINGTALK)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse login(String code) {
|
||||
return AuthResponse.builder()
|
||||
.data(this.getUserInfo(code))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* 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()
|
||||
.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();
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,15 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
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.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* Gitee登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 16:31
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthGiteeRequest extends BaseAuthRequest {
|
||||
@@ -23,18 +24,21 @@ public class AuthGiteeRequest extends BaseAuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAccessToken(String code) {
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
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 accessTokenObject.getString("access_token");
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(String accessToken) {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getGiteeUserInfoUrl(accessToken)).execute();
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
@@ -47,7 +51,7 @@ public class AuthGiteeRequest extends BaseAuthRequest {
|
||||
.location(object.getString("address"))
|
||||
.email(object.getString("email"))
|
||||
.remark(object.getString("bio"))
|
||||
.accessToken(accessToken)
|
||||
.token(authToken)
|
||||
.source(AuthSource.GITEE)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
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.utils.GlobalAuthUtil;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
@@ -13,10 +14,10 @@ import me.zhyd.oauth.utils.UrlBuilder;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Github登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 16:31
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthGithubRequest extends BaseAuthRequest {
|
||||
@@ -26,18 +27,21 @@ public class AuthGithubRequest extends BaseAuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAccessToken(String code) {
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
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 res.get("access_token");
|
||||
return AuthToken.builder()
|
||||
.accessToken(res.get("access_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(String accessToken) {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getGithubUserInfoUrl(accessToken)).execute();
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
@@ -50,7 +54,7 @@ public class AuthGithubRequest extends BaseAuthRequest {
|
||||
.location(object.getString("location"))
|
||||
.email(object.getString("email"))
|
||||
.remark(object.getString("bio"))
|
||||
.accessToken(accessToken)
|
||||
.token(authToken)
|
||||
.source(AuthSource.GITHUB)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
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.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthSource;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
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()
|
||||
.username(object.getString("name"))
|
||||
.avatar(object.getString("picture"))
|
||||
.nickname(object.getString("name"))
|
||||
.location(object.getString("locale"))
|
||||
.email(object.getString("email"))
|
||||
.token(authToken)
|
||||
.source(AuthSource.GOOGLE)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,16 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
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;
|
||||
|
||||
/**
|
||||
* oschina登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/23 15:48
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthOschinaRequest extends BaseAuthRequest {
|
||||
@@ -24,18 +25,21 @@ public class AuthOschinaRequest extends BaseAuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAccessToken(String code) {
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
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 accessTokenObject.getString("access_token");
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(String accessToken) {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getOschinaUserInfoUrl(accessToken)).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.containsKey("error")) {
|
||||
@@ -49,7 +53,7 @@ public class AuthOschinaRequest extends BaseAuthRequest {
|
||||
.location(object.getString("location"))
|
||||
.gender(AuthUserGender.getRealGender(object.getString("gender")))
|
||||
.email(object.getString("email"))
|
||||
.accessToken(accessToken)
|
||||
.token(authToken)
|
||||
.source(AuthSource.OSCHINA)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
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.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)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthQqRequest extends BaseAuthRequest {
|
||||
public AuthQqRequest(AuthConfig config) {
|
||||
super(config, AuthSource.QQ);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
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.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();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.getIntValue("ret") != 0) {
|
||||
throw new AuthException(object.getString("msg"));
|
||||
}
|
||||
String avatar = object.getString("figureurl_qq_2");
|
||||
if (StringUtils.isEmpty(avatar)) {
|
||||
avatar = object.getString("figureurl_qq_1");
|
||||
}
|
||||
return AuthUser.builder()
|
||||
.username(object.getString("nickname"))
|
||||
.nickname(object.getString("nickname"))
|
||||
.avatar(avatar)
|
||||
.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();
|
||||
if (response.isOk()) {
|
||||
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("openid")) {
|
||||
return object.getString("openid");
|
||||
}
|
||||
throw new AuthException("Invalid openId");
|
||||
}
|
||||
throw new AuthException("Invalid openId");
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,19 @@ package me.zhyd.oauth.request;
|
||||
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.model.AuthToken;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 15:45
|
||||
* @since 1.8
|
||||
*/
|
||||
public interface AuthRequest {
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @return 返回授权地址
|
||||
*/
|
||||
default String authorize() {
|
||||
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
|
||||
@@ -32,18 +33,20 @@ public interface AuthRequest {
|
||||
/**
|
||||
* 撤销授权
|
||||
*
|
||||
* @param accessToken 登录成功后返回的accessToken
|
||||
* @param authToken 登录成功后返回的Token信息
|
||||
* @return AuthResponse
|
||||
*/
|
||||
default AuthResponse revoke(String accessToken) {
|
||||
default AuthResponse revoke(AuthToken authToken) {
|
||||
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新access token (续期)
|
||||
*
|
||||
* @param accessToken 登录成功后返回的accessToken
|
||||
* @param authToken 登录成功后返回的Token信息
|
||||
* @return AuthResponse
|
||||
*/
|
||||
default AuthResponse refresh(String accessToken) {
|
||||
default AuthResponse refresh(AuthToken authToken) {
|
||||
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
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.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;
|
||||
|
||||
/**
|
||||
* 淘宝登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthTaobaoRequest extends BaseAuthRequest {
|
||||
|
||||
public AuthTaobaoRequest(AuthConfig config) {
|
||||
super(config, AuthSource.TAOBAO);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
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();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.containsKey("error")) {
|
||||
throw new AuthException(ResponseStatus.FAILURE + ":" + object.getString("error_description"));
|
||||
}
|
||||
authToken.setAccessToken(object.getString("access_token"));
|
||||
authToken.setRefreshToken(object.getString("refresh_token"));
|
||||
authToken.setExpireIn(object.getIntValue("expires_in"));
|
||||
authToken.setUid(object.getString("taobao_user_id"));
|
||||
authToken.setOpenId(object.getString("taobao_open_uid"));
|
||||
|
||||
String nick = GlobalAuthUtil.urlDecode(object.getString("taobao_user_nick"));
|
||||
return AuthUser.builder()
|
||||
.username(nick)
|
||||
.nickname(nick)
|
||||
.gender(AuthUserGender.UNKNOW)
|
||||
.token(authToken)
|
||||
.source(AuthSource.TAOBAO)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,16 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 腾讯云登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/23 15:48
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthTencentCloudRequest extends BaseAuthRequest {
|
||||
@@ -24,18 +25,21 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAccessToken(String code) {
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getTencentCloudAccessTokenUrl(config.getClientId(), config.getClientSecret(), code);
|
||||
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.getIntValue("code") != 0) {
|
||||
throw new AuthException("Unable to get token from tencent cloud using code [" + code + "]: " + object.get("msg"));
|
||||
}
|
||||
return object.getString("access_token");
|
||||
return AuthToken.builder()
|
||||
.accessToken(object.getString("access_token"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(String accessToken) {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getTencentCloudUserInfoUrl(accessToken)).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.getIntValue("code") != 0) {
|
||||
@@ -52,7 +56,7 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
|
||||
.gender(AuthUserGender.getRealGender(object.getString("sex")))
|
||||
.email(object.getString("email"))
|
||||
.remark(object.getString("slogan"))
|
||||
.accessToken(accessToken)
|
||||
.token(authToken)
|
||||
.source(AuthSource.TENCEN_CLOUD)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
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.exception.AuthException;
|
||||
import me.zhyd.oauth.model.*;
|
||||
import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
*
|
||||
* @author yangkai.shen (https://xkcoding.com)
|
||||
* @version 1.0
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthWeChatRequest extends BaseAuthRequest {
|
||||
public AuthWeChatRequest(AuthConfig config) {
|
||||
super(config, AuthSource.WECHAT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信的特殊性,此时返回的信息同时包含 openid 和 access_token
|
||||
*
|
||||
* @param code 授权码
|
||||
* @return 所有信息
|
||||
*/
|
||||
@Override
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
String accessTokenUrl = UrlBuilder.getWeChatAccessTokenUrl(config.getClientId(), config.getClientSecret(), code);
|
||||
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (!object.containsKey("access_token") || !object.containsKey("openid") || !object
|
||||
.containsKey("refresh_token")) {
|
||||
throw new AuthException("Unable to get access_token or openid or refresh_token from wechat using code [" + code + "]");
|
||||
}
|
||||
return AuthToken.builder()
|
||||
.accessToken(object.getString("access_token"))
|
||||
.refreshToken(object.getString("refresh_token"))
|
||||
.openId(object.getString("openid"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
String openId = authToken.getOpenId();
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
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"))
|
||||
.gender(AuthUserGender.getRealGender(object.getString("sex")))
|
||||
.token(authToken)
|
||||
.source(AuthSource.WECHAT)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse refresh(AuthToken authToken) {
|
||||
String refreshToken = authToken.getRefreshToken();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getWeChatRefreshUrl(config.getClientId(), refreshToken))
|
||||
.execute();
|
||||
|
||||
JSONObject object = JSONObject.parseObject(response.body());
|
||||
if (object.containsKey("errcode")) {
|
||||
throw new AuthException(object.getString("errmsg"));
|
||||
}
|
||||
|
||||
return AuthResponse.builder().data(object).build();
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
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;
|
||||
@@ -15,10 +16,10 @@ import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* 微博登录
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 16:31
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthWeiboRequest extends BaseAuthRequest {
|
||||
@@ -28,27 +29,34 @@ public class AuthWeiboRequest extends BaseAuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAccessToken(String code) {
|
||||
protected AuthToken getAccessToken(String code) {
|
||||
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);
|
||||
if (accessTokenObject.containsKey("error")) {
|
||||
throw new AuthException("Unable to get token from gitee using code [" + code + "]");
|
||||
throw new AuthException("Unable to get token from weibo using code [" + code + "]:" + accessTokenObject.getString("error_description"));
|
||||
}
|
||||
String accessToken = accessTokenObject.getString("access_token");
|
||||
String uid = accessTokenObject.getString("uid");
|
||||
return String.format("uid=%s&access_token=%s", uid, accessToken);
|
||||
return AuthToken.builder()
|
||||
.accessToken(accessTokenObject.getString("access_token"))
|
||||
.uid(accessTokenObject.getString("uid"))
|
||||
.expireIn(accessTokenObject.getIntValue("remind_in"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthUser getUserInfo(String accessToken) {
|
||||
protected AuthUser getUserInfo(AuthToken authToken) {
|
||||
String accessToken = authToken.getAccessToken();
|
||||
String uid = authToken.getUid();
|
||||
HttpResponse response = HttpRequest.get(UrlBuilder.getWeiboUserInfoUrl(accessToken))
|
||||
.header("Authorization", "OAuth2 " + accessToken)
|
||||
.header("Authorization", "OAuth2 " + String.format("uid=%s&access_token=%s", uid, accessToken))
|
||||
.header("API-RemoteIP", IpUtils.getIp())
|
||||
.execute();
|
||||
String userInfo = response.body();
|
||||
JSONObject object = JSONObject.parseObject(userInfo);
|
||||
if(object.containsKey("error")) {
|
||||
throw new AuthException(object.getString("error"));
|
||||
}
|
||||
return AuthUser.builder()
|
||||
.username(object.getString("name"))
|
||||
.avatar(object.getString("profile_image_url"))
|
||||
@@ -57,7 +65,7 @@ public class AuthWeiboRequest extends BaseAuthRequest {
|
||||
.location(object.getString("location"))
|
||||
.remark(object.getString("description"))
|
||||
.gender(AuthUserGender.getRealGender(object.getString("gender")))
|
||||
.accessToken(GlobalAuthUtil.parseStringToMap(accessToken).get("access_token"))
|
||||
.token(authToken)
|
||||
.source(AuthSource.WEIBO)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhyd.oauth.authorization.AuthorizationFactory;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
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)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/18 13:11
|
||||
* @since 1.8
|
||||
*/
|
||||
@Data
|
||||
@@ -29,9 +28,9 @@ public abstract class BaseAuthRequest implements AuthRequest {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String getAccessToken(String code);
|
||||
protected abstract AuthToken getAccessToken(String code);
|
||||
|
||||
protected abstract AuthUser getUserInfo(String accessToken);
|
||||
protected abstract AuthUser getUserInfo(AuthToken authToken);
|
||||
|
||||
@Override
|
||||
public AuthResponse login(String code) {
|
||||
@@ -45,47 +44,6 @@ public abstract class BaseAuthRequest implements AuthRequest {
|
||||
|
||||
@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:
|
||||
break;
|
||||
case WECHAT:
|
||||
break;
|
||||
case GOOGLE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return authorizeUrl;
|
||||
return AuthorizationFactory.getAuthorize(source).getAuthorizeUrl(config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package me.zhyd.oauth.request;
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 16:37
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum ResponseStatus {
|
||||
@@ -13,6 +11,8 @@ 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"),
|
||||
;
|
||||
|
||||
private int code;
|
||||
|
||||
@@ -5,8 +5,6 @@ import me.zhyd.oauth.config.AuthConfig;
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 15:46
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthConfigChecker {
|
||||
@@ -14,6 +12,7 @@ public class AuthConfigChecker {
|
||||
/**
|
||||
* 是否支持第三方登录
|
||||
*
|
||||
* @param config config
|
||||
* @return true or false
|
||||
*/
|
||||
public static boolean isSupportedAuth(AuthConfig config) {
|
||||
|
||||
@@ -8,14 +8,14 @@ import java.net.UnknownHostException;
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 16:31
|
||||
* @since 1.0
|
||||
*/
|
||||
public class IpUtils {
|
||||
|
||||
/**
|
||||
* 获取IP
|
||||
*
|
||||
* @return ip
|
||||
*/
|
||||
public static String getIp() {
|
||||
try {
|
||||
|
||||
@@ -3,8 +3,6 @@ package me.zhyd.oauth.utils;
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 15:48
|
||||
* @since 1.8
|
||||
*/
|
||||
public class StringUtils {
|
||||
|
||||
@@ -9,8 +9,6 @@ import java.text.MessageFormat;
|
||||
*
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/1/31 12:26
|
||||
* @since 1.0
|
||||
*/
|
||||
public class UrlBuilder {
|
||||
@@ -19,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}";
|
||||
@@ -53,6 +55,23 @@ 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_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 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_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)";
|
||||
|
||||
/**
|
||||
* 获取githubtoken的接口地址
|
||||
*
|
||||
@@ -356,6 +375,52 @@ public class UrlBuilder {
|
||||
return MessageFormat.format(OSCHINA_AUTHORIZE_PATTERN, ApiUrl.OSCHINA.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取qq 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取qq用户详情的接口地址
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取qq授权地址
|
||||
*
|
||||
* @param clientId qq 应用的Client ID
|
||||
* @param redirectUrl qq 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getQqAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(QQ_AUTHORIZE_PATTERN, ApiUrl.QQ.authorize(), clientId, redirectUrl, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取qq授权地址
|
||||
*
|
||||
* @param url 获取qqopenid的api接口地址
|
||||
* @param token qq 应用授权的token
|
||||
* @return full url
|
||||
*/
|
||||
public static String getQqOpenidUrl(String url, String token) {
|
||||
return MessageFormat.format(QQ_OPENID_PATTERN, url, token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取alipay授权地址
|
||||
*
|
||||
@@ -366,4 +431,141 @@ public class UrlBuilder {
|
||||
public static String getAlipayAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(ALIPAY_AUTHORIZE_PATTERN, ApiUrl.ALIPAY.authorize(), clientId, 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信 用户详情的接口地址
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信 刷新令牌 地址
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Taobao 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Taobao授权地址
|
||||
*
|
||||
* @param clientId Taobao 应用的Client ID
|
||||
* @param redirectUrl Taobao 应用授权成功后的回调地址
|
||||
* @return full url
|
||||
*/
|
||||
public static String getTaobaoAuthorizeUrl(String clientId, String redirectUrl) {
|
||||
return MessageFormat.format(TAOBAO_AUTHORIZE_PATTERN, ApiUrl.TAOBAO.authorize(), clientId, redirectUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取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, ApiUrl.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, ApiUrl.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, ApiUrl.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, ApiUrl.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, ApiUrl.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, ApiUrl.FACEBOOK.userInfo(), token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package me.zhyd.oauth;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
import me.zhyd.oauth.request.*;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/18 13:10
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AuthRequestTest {
|
||||
@@ -116,4 +115,43 @@ public class AuthRequestTest {
|
||||
// 授权登录后会返回一个code,用这个code进行登录
|
||||
authRequest.login("code");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void qqTest() {
|
||||
AuthRequest authRequest = new AuthQqRequest(AuthConfig.builder()
|
||||
.clientId("clientId")
|
||||
.clientSecret("clientSecret")
|
||||
.redirectUri("redirectUri")
|
||||
.build());
|
||||
// 返回授权页面,可自行调整
|
||||
String url = authRequest.authorize();
|
||||
// 授权登录后会返回一个code,用这个code进行登录
|
||||
AuthResponse login = authRequest.login("code");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wechatTest() {
|
||||
AuthRequest authRequest = new AuthWeChatRequest(AuthConfig.builder()
|
||||
.clientId("clientId")
|
||||
.clientSecret("clientSecret")
|
||||
.redirectUri("redirectUri")
|
||||
.build());
|
||||
// 返回授权页面,可自行调整
|
||||
String url = authRequest.authorize();
|
||||
// 授权登录后会返回一个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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
### 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和微信登录)
|
||||
2. 支持淘宝登录
|
||||
3. 修改`AuthUser.java`类中的`accessToken`属性,由原本的~~accessToken (String)~~改为`token (AuthToken)`
|
||||
4. 修复一些bug
|
||||
5. 发布1.2.0版本的jar包到公开仓库(支持淘宝登录)
|
||||
|
||||
----
|
||||
### 2019/05/17
|
||||
1. 增加qq和微信的授权登录
|
||||
2. 修改getAccessToken方法的返回值
|
||||
Reference in New Issue
Block a user