From ee1b6c8c5fbdb7f8b3ade03ca8d1b37bad170c50 Mon Sep 17 00:00:00 2001
From: "yadong.zhang"
Date: Tue, 3 Sep 2019 09:14:50 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E9=9B=86=E6=88=90=E9=85=B7?=
=?UTF-8?q?=E5=AE=B6=E4=B9=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.en-US.md | 10 +++---
README.md | 12 +++----
docs/README.md | 9 ++---
docs/_coverpage.md | 2 +-
docs/how-to-use.md | 4 +--
docs/update.md | 5 +++
pom.xml | 5 +--
.../java/me/zhyd/oauth/config/AuthSource.java | 2 +-
.../oauth/request/AuthKujialeRequest.java | 34 +++++++++++--------
9 files changed, 48 insertions(+), 35 deletions(-)
diff --git a/README.en-US.md b/README.en-US.md
index cdb2936..7617b23 100644
--- a/README.en-US.md
+++ b/README.en-US.md
@@ -6,7 +6,7 @@
-
+
@@ -15,7 +15,7 @@
-
+
@@ -64,6 +64,7 @@
|
|
|
+ |
@@ -91,7 +92,7 @@ These artifacts are available from Maven Central:
me.zhyd.oauth
JustAuth
- 1.10.1
+ 1.11.0
```
- Using JustAuth
@@ -103,7 +104,7 @@ AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
.redirectUri("redirectUri")
.build());
// Generate authorization url
-authRequest.authorize();
+authRequest.authorize("state");
// After authorization to login, it will return: code(auth_code(Alipay only)),state, After version 1.8.0, you can use the AuthCallback as a parameter to the callback interface
// Note: JustAuth saves state for 3 minutes by default. If it is not used within 3 minutes, the expired state will be cleared automatically.
authRequest.login(callback);
@@ -147,6 +148,7 @@ authRequest.login(callback);
| | [AuthHuaweiRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java) | 参考文档 |
| | [AuthWeChatEnterpriseRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseRequest.java) | 参考文档 |
| | [AuthCsdnRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java) | 无 |
+| | [AuthKujialeRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java) | 参考文档 |
diff --git a/README.md b/README.md
index 9b605cd..31823e2 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
-
+
@@ -15,7 +15,7 @@
-
+
@@ -64,7 +64,7 @@
|
|
|
- |
+ |
@@ -92,7 +92,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
me.zhyd.oauth
JustAuth
- 1.10.1
+ 1.11.0
```
- 调用api
@@ -104,7 +104,7 @@ AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
.redirectUri("redirectUri")
.build());
// 生成授权页面
-authRequest.authorize();
+authRequest.authorize("state");
// 授权登录后会返回code(auth_code(仅限支付宝))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的参数
// 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
authRequest.login(callback);
@@ -158,7 +158,7 @@ authRequest.login(callback);
| | [AuthHuaweiRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java) | 参考文档 |
| | [AuthWeChatEnterpriseRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseRequest.java) | 参考文档 |
| | [AuthCsdnRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java) | 无 |
-| | [AuthKujialeRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java) | 参考文档 |
+| | [AuthKujialeRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java) | 参考文档 |
_请知悉:经咨询CSDN官方客服得知,CSDN的授权开放平台已经下线。如果以前申请过的应用,可以继续使用,但是不再支持申请新的应用。so, 本项目中的CSDN登录只能针对少部分用户使用了_
diff --git a/docs/README.md b/docs/README.md
index 04349f4..735a61a 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -9,7 +9,7 @@
-
+
@@ -18,7 +18,7 @@
-
+
@@ -88,6 +88,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
| | [AuthHuaweiRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java) | 参考文档 |
| | [AuthWeChatEnterpriseRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseRequest.java) | 参考文档 |
| | [AuthCsdnRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java) | 无 |
+| | [AuthKujialeRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java) | 参考文档 |
## 快速开始
@@ -97,7 +98,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
me.zhyd.oauth
JustAuth
- 1.10.1
+ 1.11.0
```
- 调用api
@@ -109,7 +110,7 @@ AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
.redirectUri("redirectUri")
.build());
// 生成授权页面
-authRequest.authorize();
+authRequest.authorize("state");
// 授权登录后会返回code(auth_code(仅限支付宝))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的参数
// 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
authRequest.login(callback);
diff --git a/docs/_coverpage.md b/docs/_coverpage.md
index 03062e3..3b3c450 100644
--- a/docs/_coverpage.md
+++ b/docs/_coverpage.md
@@ -1,6 +1,6 @@
![](_media/logo.png)
-# JustAuth 1.10.1
+# JustAuth 1.11.0
史上最全的整合第三方登录的开源库
diff --git a/docs/how-to-use.md b/docs/how-to-use.md
index c83d399..bc0e794 100644
--- a/docs/how-to-use.md
+++ b/docs/how-to-use.md
@@ -14,7 +14,7 @@
me.zhyd.oauth
JustAuth
- 1.10.1
+ 1.11.0
```
- 调用api
@@ -26,7 +26,7 @@ AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
.redirectUri("redirectUri")
.build());
// 生成授权页面
-authRequest.authorize();
+authRequest.authorize("state");
// 授权登录后会返回code(auth_code(仅限支付宝))、state,1.8.0版本后,可以用AuthCallback类作为回调接口的参数
// 注:JustAuth默认保存state的时效为3分钟,3分钟内未使用则会自动清除过期的state
authRequest.login(callback);
diff --git a/docs/update.md b/docs/update.md
index 3d3c690..2a4ace3 100644
--- a/docs/update.md
+++ b/docs/update.md
@@ -1,3 +1,8 @@
+## v1.11.0
+### 2019/09/02
+
+- 集成“酷家乐”授权登录
+
## v1.10.1
### 2019/08/17
diff --git a/pom.xml b/pom.xml
index 7da8895..b1b93f0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,12 +6,13 @@
me.zhyd.oauth
JustAuth
- 1.10.1
+ 1.11.0
JustAuth
https://gitee.com/yadong.zhang/JustAuth
- 史上最全的整合第三方登录的工具,目前已支持Github、Gitee、酷家乐、微博、钉钉、百度、Coding、腾讯云开发者平台、OSChina、支付宝、QQ、微信、淘宝、Google、Facebook、抖音、领英、小米、微软和今日头条等第三方平台的授权登录。
+ 史上最全的整合第三方登录的开源库。目前已支持Github、Gitee、微博、钉钉、百度、Coding、腾讯云开发者平台、OSChina、支付宝、
+ QQ、微信、淘宝、Google、Facebook、抖音、领英、小米、微软、今日头条、Teambition、StackOverflow、Pinterest、人人、华为、企业微信和酷家乐等第三方平台的授权登录。
Login, so easy!
diff --git a/src/main/java/me/zhyd/oauth/config/AuthSource.java b/src/main/java/me/zhyd/oauth/config/AuthSource.java
index 4ba6599..db64121 100644
--- a/src/main/java/me/zhyd/oauth/config/AuthSource.java
+++ b/src/main/java/me/zhyd/oauth/config/AuthSource.java
@@ -571,7 +571,7 @@ public enum AuthSource {
/**
* 酷家乐
*
- * @since 1.10.1
+ * @since 1.11.0
*/
KUJIALE {
@Override
diff --git a/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java b/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
index 446624a..833b7e2 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
@@ -16,9 +16,10 @@ import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder;
/**
+ * 酷家乐授权登录
+ *
* @author shahuang
- * @Date: 2019/8/29 18:50
- * @since 1.10.1
+ * @since 1.11.0
*/
public class AuthKujialeRequest extends AuthDefaultRequest {
@@ -33,9 +34,10 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
/**
* 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state}
* 默认只向用户请求用户信息授权
+ *
* @param state state 验证授权流程的参数,可以防止csrf
* @return 返回授权地址
- * @since 1.10.1
+ * @since 1.11.0
*/
@Override
public String authorize(String state) {
@@ -44,10 +46,11 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
/**
* 请求授权url
- * @param state state 验证授权流程的参数,可以防止csrf
+ *
+ * @param state state 验证授权流程的参数,可以防止csrf
* @param scopeStr 请求用户授权时向用户显示的可进行授权的列表。如果要填写多个接口名称,请用逗号隔开
* 参考https://open.kujiale.com/open/apps/2/docs?doc_id=95#Step1%EF%BC%9A%E8%8E%B7%E5%8F%96Authorization%20Code参数表内的scope字段
- * @return
+ * @return authorize url
*/
public String authorize(String state, String scopeStr) {
UrlBuilder urlBuilder = UrlBuilder.fromBaseUrl(source.authorize())
@@ -68,11 +71,7 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
}
private AuthToken getAuthToken(HttpResponse response) {
- String accessTokenStr = response.body();
- JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
- if (!"0".equals(accessTokenObject.getString("c"))) {
- throw new AuthException(accessTokenObject.getString("m"));
- }
+ JSONObject accessTokenObject = checkResponse(response);
JSONObject resultObject = accessTokenObject.getJSONObject("d");
return AuthToken.builder()
.accessToken(resultObject.getString("accessToken"))
@@ -81,6 +80,15 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
.build();
}
+ private JSONObject checkResponse(HttpResponse response) {
+ String accessTokenStr = response.body();
+ JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
+ if (!"0".equals(accessTokenObject.getString("c"))) {
+ throw new AuthException(accessTokenObject.getString("m"));
+ }
+ return accessTokenObject;
+ }
+
@Override
public AuthUser getUserInfo(AuthToken authToken) {
String openId = this.getOpenId(authToken);
@@ -114,11 +122,7 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
HttpResponse response = HttpRequest.get(UrlBuilder.fromBaseUrl("https://oauth.kujiale.com/oauth2/auth/user")
.queryParam("access_token", authToken.getAccessToken())
.build()).execute();
- String accessTokenStr = response.body();
- JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
- if (!"0".equals(accessTokenObject.getString("c"))) {
- throw new AuthException(accessTokenObject.getString("m"));
- }
+ JSONObject accessTokenObject = checkResponse(response);
return accessTokenObject.getString("d");
}
--
GitLab