Skip to content

Commit

Permalink
🔖 发布1.14.0,解耦HTTP工具
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyd-c committed Mar 17, 2020
1 parent d5a8ffc commit 65c60a6
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 39 deletions.
9 changes: 5 additions & 4 deletions README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</p>
<p align="center">
<a target="_blank" href="https://search.maven.org/search?q=JustAuth">
<img src="https://img.shields.io/badge/Maven Central-1.13.2-blue.svg" ></img>
<img src="https://img.shields.io/badge/Maven Central-1.14.0-blue.svg" ></img>
</a>
<a target="_blank" href="https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE">
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" ></img>
Expand All @@ -15,7 +15,7 @@
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
</a>
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/" title="API文档">
<img src="https://img.shields.io/badge/Api Docs-1.13.2-orange.svg" ></img>
<img src="https://img.shields.io/badge/Api Docs-1.14.0-orange.svg" ></img>
</a>
<a target="_blank" href="https://docs.justauth.whnb.wang" title="参考文档">
<img src="https://img.shields.io/badge/Docs-latest-blueviolet.svg" ></img>
Expand Down Expand Up @@ -44,7 +44,7 @@
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschina.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/alipay.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20" title="微信开放平台、微信公众平台和微信企业版"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20" title="微信开放平台"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/taobao.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/google.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/facebook.png" width="20"></td>
Expand All @@ -62,6 +62,7 @@
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/pinterest.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/stackoverflow.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/huawei.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20" title="微信企业版"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/kujiale.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/gitlab.png" width="20"></td>
Expand Down Expand Up @@ -96,7 +97,7 @@ These artifacts are available from Maven Central:
<dependency>
<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
<version>1.13.2</version>
<version>1.14.0</version>
</dependency>
```
- Using JustAuth
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</p>
<p align="center">
<a target="_blank" href="https://search.maven.org/search?q=JustAuth">
<img src="https://img.shields.io/badge/Maven Central-1.13.2-blue.svg" ></img>
<img src="https://img.shields.io/badge/Maven Central-1.14.0-blue.svg" ></img>
</a>
<a target="_blank" href="https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE">
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" ></img>
Expand All @@ -15,7 +15,7 @@
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
</a>
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/" title="API文档">
<img src="https://img.shields.io/badge/Api Docs-1.13.2-orange.svg" ></img>
<img src="https://img.shields.io/badge/Api Docs-1.14.0-orange.svg" ></img>
</a>
<a target="_blank" href="https://docs.justauth.whnb.wang" title="参考文档">
<img src="https://img.shields.io/badge/Docs-latest-blueviolet.svg" ></img>
Expand Down Expand Up @@ -44,7 +44,7 @@
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschina.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/alipay.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechat.png" width="20" title="微信开放平台"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/taobao.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/google.png" width="20"></td>
<td align="center" width="200"><img src="https://gitee.com/yadong.zhang/static/raw/master/JustAuth/facebook.png" width="20"></td>
Expand Down Expand Up @@ -97,7 +97,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
<dependency>
<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
<version>1.13.2</version>
<version>1.14.0</version>
</dependency>
```
- 调用api
Expand Down
2 changes: 1 addition & 1 deletion bin/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.13.2
1.14.0
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</p>
<p align="center">
<a target="_blank" href="https://search.maven.org/search?q=JustAuth">
<img src="https://img.shields.io/badge/Maven Central-1.13.2-blue.svg" ></img>
<img src="https://img.shields.io/badge/Maven Central-1.14.0-blue.svg" ></img>
</a>
<a target="_blank" href="https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE">
<img src="https://img.shields.io/apm/l/vim-mode.svg?color=yellow" ></img>
Expand All @@ -18,7 +18,7 @@
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" ></img>
</a>
<a target="_blank" href="https://apidoc.gitee.com/yadong.zhang/JustAuth/" title="API文档">
<img src="https://img.shields.io/badge/Api Docs-1.13.2-orange.svg" ></img>
<img src="https://img.shields.io/badge/Api Docs-1.14.0-orange.svg" ></img>
</a>
<a target="_blank" href="https://docs.justauth.whnb.wang" title="参考文档">
<img src="https://img.shields.io/badge/Docs-latest-blueviolet.svg" ></img>
Expand Down
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

![](_media/logo.png)
# JustAuth <small>1.13.2</small>
# JustAuth <small>1.14.0</small>

<strong>史上最全的整合第三方登录的开源库</strong>

Expand Down
4 changes: 3 additions & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions docs/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
- 添加测试用例:UrlBuilder 、GlobalAuthUtil
- <img src="https://avatars0.githubusercontent.com/u/283483?s=180&v=4" width="20"> · Chris Smowton : <a href="https://github.com/smowton" target="_blank">[Github]</a>
- 添加测试用例:StringUtils
- <img src="https://avatars1.githubusercontent.com/u/31759178?s=88&v=4" width="20"> · githubeacon : <a href="https://github.com/githubeacon" target="_blank">[Github]</a>
- 增加飞书授权登录
- <img src="https://avatars3.githubusercontent.com/u/20242284?s=88&u=2aeb7576bd61392e9fd94227d2b3048a9aea6f73&v=4" width="20"> · runningzyp : <a href="https://github.com/runningzyp" target="_blank">[Github]</a>
- 修改文案错误
- 千年等一回,我只为等你...

ps: 如有遗漏,请告知
10 changes: 10 additions & 0 deletions docs/oauth/wechat_mp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(敬请期待...)

### 声明:
此文档适用于**微信公众平台**

## 1. 申请应用

## 2. 集成JustAuth

## 3. 授权结果
2 changes: 1 addition & 1 deletion docs/oauth/wechat_open.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### 声明:
此文档适用于**微信开放平台****微信开放平台****微信开放平台**,不是**微信公众平台**
此文档适用于**微信开放平台**

## 1. 申请应用

Expand Down
7 changes: 7 additions & 0 deletions docs/update.md
Original file line number Diff line number Diff line change
@@ -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
- 新增
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
<version>1.14.0-SNAPSHOT</version>
<version>1.14.0</version>

<name>JustAuth</name>
<url>https://gitee.com/yadong.zhang/JustAuth</url>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,12 @@ public String userInfo() {
}
},

/**
* 飞书
* 注意:该平台暂时存在问题,请不要使用。待修复完成后会重新发版
*
* @since 1.14.0
*/
FEISHU{
@Override
public String authorize() {
Expand Down
55 changes: 31 additions & 24 deletions src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,28 +12,33 @@
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"))
Expand All @@ -48,8 +53,10 @@ protected AuthToken getAccessToken(AuthCallback authCallback) {
@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"))
Expand All @@ -61,14 +68,13 @@ protected AuthUser getUserInfo(AuthToken authToken) {
@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())
Expand All @@ -86,19 +92,20 @@ public AuthResponse refresh(AuthToken authToken) {
@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"));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/me/zhyd/oauth/utils/AuthChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static void checkCode(AuthSource source, AuthCallback callback) {
* 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) {
Expand Down

0 comments on commit 65c60a6

Please sign in to comment.