From 65c60a61b32a53bbf2310e1b6a1aa3a8dbd47bd4 Mon Sep 17 00:00:00 2001 From: "yadong.zhang" Date: Tue, 17 Mar 2020 22:57:53 +0800 Subject: [PATCH] =?UTF-8?q?:bookmark:=20=E5=8F=91=E5=B8=831.14.0=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E8=80=A6HTTP=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en-US.md | 9 +-- README.md | 8 +-- bin/version.txt | 2 +- docs/README.md | 4 +- docs/_coverpage.md | 2 +- docs/_sidebar.md | 4 +- docs/contributors.md | 4 ++ docs/oauth/wechat_mp.md | 10 ++++ docs/oauth/wechat_open.md | 2 +- docs/update.md | 7 +++ pom.xml | 2 +- .../zhyd/oauth/config/AuthDefaultSource.java | 6 ++ .../zhyd/oauth/request/AuthFeishuRequest.java | 55 +++++++++++-------- .../java/me/zhyd/oauth/utils/AuthChecker.java | 1 + 14 files changed, 77 insertions(+), 39 deletions(-) create mode 100644 docs/oauth/wechat_mp.md diff --git a/README.en-US.md b/README.en-US.md index d4c51dc..00c3630 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -6,7 +6,7 @@

- + @@ -15,7 +15,7 @@ - + @@ -44,7 +44,7 @@ - + @@ -62,6 +62,7 @@ + @@ -96,7 +97,7 @@ These artifacts are available from Maven Central: me.zhyd.oauth JustAuth - 1.13.2 + 1.14.0 ``` - Using JustAuth diff --git a/README.md b/README.md index 0f95a01..39c1bb3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@

- + @@ -15,7 +15,7 @@ - + @@ -44,7 +44,7 @@ - + @@ -97,7 +97,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具 me.zhyd.oauth JustAuth - 1.13.2 + 1.14.0 ``` - 调用api diff --git a/bin/version.txt b/bin/version.txt index 61ce01b..850e742 100644 --- a/bin/version.txt +++ b/bin/version.txt @@ -1 +1 @@ -1.13.2 +1.14.0 diff --git a/docs/README.md b/docs/README.md index 1ce1f84..9cf6c98 100644 --- a/docs/README.md +++ b/docs/README.md @@ -9,7 +9,7 @@

- + @@ -18,7 +18,7 @@ - + diff --git a/docs/_coverpage.md b/docs/_coverpage.md index 582d69a..3c880a2 100644 --- a/docs/_coverpage.md +++ b/docs/_coverpage.md @@ -1,6 +1,6 @@ ![](_media/logo.png) -# JustAuth 1.13.2 +# JustAuth 1.14.0 史上最全的整合第三方登录的开源库 diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 62f9f21..b91467d 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -10,6 +10,8 @@ - [√ Github登录](oauth/github.md) - [√ qq登录](oauth/qq.md) - [√ 微信开放平台登录](oauth/wechat_open.md) + - [微信企业版登录](oauth/wechatEnterprise.md) + - [微信公众平台登录](oauth/wechat_mp.md) - [√ 微博登录](oauth/weibo.md) - [√ 支付宝登录](oauth/alipay.md) - [百度登录](oauth/baidu.md) @@ -30,12 +32,12 @@ - [Pinterest登录](oauth/pinterest.md) - [Stackoverflow登录](oauth/stackoverflow.md) - [华为登录](oauth/huawei.md) - - [微信企业版登录](oauth/wechatEnterprise.md) - [√ 酷家乐登录](oauth/kujiale.md) - [Gitlab登录](oauth/gitlab.md) - [美团登录](oauth/meituan.md) - [饿了么登录](oauth/eleme.md) - [CSDN登录](oauth/csdn.md) + - [飞书登录](oauth/feishu.md) - 高级特性 - [使用State](using-state.md) - [自定义state缓存](customize-the-state-cache.md) diff --git a/docs/contributors.md b/docs/contributors.md index ad11a9e..41d7022 100644 --- a/docs/contributors.md +++ b/docs/contributors.md @@ -26,6 +26,10 @@ - 添加测试用例:UrlBuilder 、GlobalAuthUtil - · Chris Smowton : [Github] - 添加测试用例:StringUtils +- · githubeacon : [Github] + - 增加飞书授权登录 +- · runningzyp : [Github] + - 修改文案错误 - 千年等一回,我只为等你... ps: 如有遗漏,请告知 diff --git a/docs/oauth/wechat_mp.md b/docs/oauth/wechat_mp.md new file mode 100644 index 0000000..ff4be0a --- /dev/null +++ b/docs/oauth/wechat_mp.md @@ -0,0 +1,10 @@ +(敬请期待...) + +### 声明: +此文档适用于**微信公众平台**! + +## 1. 申请应用 + +## 2. 集成JustAuth + +## 3. 授权结果 \ No newline at end of file diff --git a/docs/oauth/wechat_open.md b/docs/oauth/wechat_open.md index 9dd2bd1..18283b1 100644 --- a/docs/oauth/wechat_open.md +++ b/docs/oauth/wechat_open.md @@ -1,5 +1,5 @@ ### 声明: -此文档适用于**微信开放平台**、**微信开放平台**、**微信开放平台**,不是**微信公众平台**! +此文档适用于**微信开放平台**! ## 1. 申请应用 diff --git a/docs/update.md b/docs/update.md index dae31bd..8512a4c 100644 --- a/docs/update.md +++ b/docs/update.md @@ -1,3 +1,10 @@ +## v1.14.0 +### 2020/03/17 +- 修改 + - 合并[PR-59](https://github.com/justauth/JustAuth/pull/59),抽取HTTP,具体实现交给开发者,解耦 hutool-http,开发者可以视自己项目的依赖决定使用何种HTTP方式。详情请参考:https://github.com/xkcoding/simple-http + - 合并[PR-65](https://github.com/justauth/JustAuth/pull/65),修改错误文案 + - 修复其他一些问题 + ## v1.13.2 ### 2019/12/24 - 新增 diff --git a/pom.xml b/pom.xml index 81f188e..af082ed 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.zhyd.oauth JustAuth - 1.14.0-SNAPSHOT + 1.14.0 JustAuth https://gitee.com/yadong.zhang/JustAuth diff --git a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java index 7446802..3a48641 100644 --- a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java +++ b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java @@ -725,6 +725,12 @@ public enum AuthDefaultSource implements AuthSource { } }, + /** + * 飞书 + * 注意:该平台暂时存在问题,请不要使用。待修复完成后会重新发版 + * + * @since 1.14.0 + */ FEISHU{ @Override public String authorize() { diff --git a/src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java b/src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java index 61cddd6..67b3aaf 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java @@ -1,9 +1,9 @@ package me.zhyd.oauth.request; -import cn.hutool.http.HttpRequest; -import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.xkcoding.http.HttpUtil; +import com.xkcoding.http.support.HttpHeader; import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthDefaultSource; import me.zhyd.oauth.enums.AuthResponseStatus; @@ -12,28 +12,33 @@ import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthUser; -import me.zhyd.oauth.utils.GlobalAuthUtil; +import me.zhyd.oauth.utils.GlobalAuthUtils; import me.zhyd.oauth.utils.UrlBuilder; /** + * 注意:该平台暂时存在问题,请不要使用。待修复完成后会重新发版by yadong.zhang + * * @author beacon * @since 1.14.0 */ +@Deprecated public class AuthFeishuRequest extends AuthDefaultRequest { public AuthFeishuRequest(AuthConfig config) { super(config, AuthDefaultSource.FEISHU); + throw new AuthException(AuthResponseStatus.FAILURE); } @Override protected AuthToken getAccessToken(AuthCallback authCallback) { JSONObject requestObject = new JSONObject(); - requestObject.put("app_id",config.getClientId()); - requestObject.put("app_secret",config.getClientSecret()); - requestObject.put("grant_type","authorization_code"); - requestObject.put("code",authCallback.getCode()); - HttpResponse httpResponse = HttpRequest.post(source.accessToken()).body(requestObject.toJSONString(), "application/json").execute(); - JSONObject jsonObject = JSON.parseObject(httpResponse.body()); + requestObject.put("app_id", config.getClientId()); + requestObject.put("app_secret", config.getClientSecret()); + requestObject.put("grant_type", "authorization_code"); + requestObject.put("code", authCallback.getCode()); + String response = HttpUtil.post(source.accessToken(), requestObject.toJSONString(), new HttpHeader() + .add("Content-Type", "application/json")); + JSONObject jsonObject = JSON.parseObject(response); this.checkResponse(jsonObject); return AuthToken.builder() .accessToken(jsonObject.getString("access_token")) @@ -48,8 +53,10 @@ public class AuthFeishuRequest extends AuthDefaultRequest { @Override protected AuthUser getUserInfo(AuthToken authToken) { String accessToken = authToken.getAccessToken(); - HttpResponse userInfoResponse = HttpRequest.get(source.userInfo()).header("Authorization", "Bearer " + accessToken).execute(); - JSONObject jsonObject = JSON.parseObject(userInfoResponse.body()); + String response = HttpUtil.get(source.userInfo(), null, new HttpHeader() + .add("Content-Type", "application/json") + .add("Authorization", "Bearer " + accessToken), false); + JSONObject jsonObject = JSON.parseObject(response); return AuthUser.builder() .avatar(jsonObject.getString("AvatarUrl")) .username(jsonObject.getString("Mobile")) @@ -61,14 +68,13 @@ public class AuthFeishuRequest extends AuthDefaultRequest { @Override public AuthResponse refresh(AuthToken authToken) { JSONObject requestObject = new JSONObject(); - requestObject.put("app_id",config.getClientId()); - requestObject.put("app_secret",config.getClientSecret()); - requestObject.put("grant_type","refresh_token"); - requestObject.put("refresh_token",authToken.getRefreshToken()); - HttpResponse httpResponse = HttpRequest.post(source.refresh()) - .body(requestObject.toJSONString(), "application/json") - .execute(); - JSONObject jsonObject = JSON.parseObject(httpResponse.body()); + requestObject.put("app_id", config.getClientId()); + requestObject.put("app_secret", config.getClientSecret()); + requestObject.put("grant_type", "refresh_token"); + requestObject.put("refresh_token", authToken.getRefreshToken()); + String response = HttpUtil.post(source.refresh(), requestObject.toJSONString(), new HttpHeader() + .add("Content-Type", "application/json")); + JSONObject jsonObject = JSON.parseObject(response); this.checkResponse(jsonObject); return AuthResponse.builder() .code(AuthResponseStatus.SUCCESS.getCode()) @@ -86,19 +92,20 @@ public class AuthFeishuRequest extends AuthDefaultRequest { @Override public String authorize(String state) { return UrlBuilder.fromBaseUrl(source.authorize()) - .queryParam("app_id",config.getClientId()) - .queryParam("redirect_uri", GlobalAuthUtil.urlEncode(config.getRedirectUri())) - .queryParam("state",getRealState(state)) + .queryParam("app_id", config.getClientId()) + .queryParam("redirect_uri", GlobalAuthUtils.urlEncode(config.getRedirectUri())) + .queryParam("state", getRealState(state)) .build(); } /** * 校验响应内容是否正确 + * * @param jsonObject 响应内容 */ - private void checkResponse(JSONObject jsonObject){ - if(jsonObject.getIntValue("code") != 0){ + private void checkResponse(JSONObject jsonObject) { + if (jsonObject.getIntValue("code") != 0) { throw new AuthException(jsonObject.getString("message")); } } diff --git a/src/main/java/me/zhyd/oauth/utils/AuthChecker.java b/src/main/java/me/zhyd/oauth/utils/AuthChecker.java index 178614c..be24a5c 100644 --- a/src/main/java/me/zhyd/oauth/utils/AuthChecker.java +++ b/src/main/java/me/zhyd/oauth/utils/AuthChecker.java @@ -91,6 +91,7 @@ public class AuthChecker { * 2. {@code state}为前端伪造,本身就不存在 * * @param state {@code state}一定不为空 + * @param source {@code source}当前授权平台 * @param authStateCache {@code authStateCache} state缓存实现 */ public static void checkState(String state, AuthSource source, AuthStateCache authStateCache) { -- GitLab