diff --git a/README.en-US.md b/README.en-US.md
index e357ed66dde37262e8df24ffd3b5aef52660e06f..7bea0fabc7ea7146e3046662e26b47cd4b37e8c7 100644
--- a/README.en-US.md
+++ b/README.en-US.md
@@ -6,7 +6,7 @@
-
+
@@ -15,7 +15,7 @@
-
+
@@ -97,7 +97,7 @@ These artifacts are available from Maven Central:
me.zhyd.oauth
JustAuth
- 1.15.4-alpha
+ 1.15.5-alpha
```
- Using JustAuth
@@ -182,7 +182,7 @@ Note, that since [v1.14.0](https://gitee.com/yadong.zhang/JustAuth/releases/v1.1
|
| [AuthFacebookRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java) | 参考文档 |
|
| [AuthDouyinRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java) | 参考文档 |
|
| [AuthLinkedinRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java) | 参考文档 |
-|
| [AuthMicrosoftRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java) | 参考文档 |
+|
| [AuthMicrosoftRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java) | 参考文档 |
|
| [AuthMiRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java) | 参考文档 |
|
| [AuthToutiaoRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java) | 参考文档 |
|
| [AuthTeambitionRequest](https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java) | 参考文档 |
diff --git a/README.md b/README.md
index ebcbd0c6bdc032fdd698f0871197dbf77892551e..0e1b0639190e129d681bfca8f561a9d951305d10 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
-
+
@@ -15,7 +15,7 @@
-
+
@@ -96,7 +96,7 @@ JustAuth,如你所见,它仅仅是一个**第三方授权登录**的**工具
me.zhyd.oauth
JustAuth
- 1.15.4-alpha
+ 1.15.5-alpha
```
- 调用api
diff --git a/bin/version.txt b/bin/version.txt
index 819e1039c50d568c24f9ee7ab9a8a0e06dc9d395..a432d3312fcfe5c8b8ff683b544cfdd888f8acfa 100644
--- a/bin/version.txt
+++ b/bin/version.txt
@@ -1 +1 @@
-1.15.4-alpha
+1.15.5-alpha
diff --git a/docs/README.md b/docs/README.md
index 60066f831a712763124b53678ee3852727af48f3..15bd849f47a41983aebf2271f6f4c162b4010eff 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 b02d757ec05a86e1d2cfb7c118564baa766fa018..7de1695808f15edc2cc00a3dc5a22757e4045652 100644
--- a/docs/_coverpage.md
+++ b/docs/_coverpage.md
@@ -1,6 +1,6 @@
![](_media/justauth@0,25x.png)
-# JustAuth 1.15.4-alpha
+# JustAuth 1.15.5-alpha
史上最全的整合第三方登录的开源库
diff --git a/docs/_media/oauth/2f1b9c2c.png b/docs/_media/oauth/2f1b9c2c.png
new file mode 100644
index 0000000000000000000000000000000000000000..d3e734bc1b75534b5b5f801696bcddaa8ab326b3
Binary files /dev/null and b/docs/_media/oauth/2f1b9c2c.png differ
diff --git a/docs/_media/oauth/7fded4b4.png b/docs/_media/oauth/7fded4b4.png
new file mode 100644
index 0000000000000000000000000000000000000000..e1d07afef160adfd9366558e62d0f202a7137515
Binary files /dev/null and b/docs/_media/oauth/7fded4b4.png differ
diff --git a/docs/_media/oauth/ac549f1a.png b/docs/_media/oauth/ac549f1a.png
new file mode 100644
index 0000000000000000000000000000000000000000..0508fbb8b158d8d8da5a6c638a7bee64143fd2be
Binary files /dev/null and b/docs/_media/oauth/ac549f1a.png differ
diff --git a/docs/_media/oauth/ca78b40f.png b/docs/_media/oauth/ca78b40f.png
new file mode 100644
index 0000000000000000000000000000000000000000..81facf84f8efc85e3b9e3244619c8e9e86c0e695
Binary files /dev/null and b/docs/_media/oauth/ca78b40f.png differ
diff --git a/docs/_sidebar.md b/docs/_sidebar.md
index 67d30741d15228264b4eb40f4991ebb326eacc08..e12a4e6f64c6415ea6af78010cdfdb2fec8adec2 100644
--- a/docs/_sidebar.md
+++ b/docs/_sidebar.md
@@ -14,15 +14,14 @@
- [√ 支付宝登录](oauth/alipay.md)
- [√ 酷家乐登录](oauth/kujiale.md)
- [√ 推特登录](oauth/twitter.md)
+ - [√ Coding登录](oauth/coding.md)
- [CSDN登录](oauth/csdn.md)
- [微信企业版登录](oauth/wechatEnterprise.md)
- [微信公众平台登录](oauth/wechat_mp.md)
- [百度登录](oauth/baidu.md)
- - [Coding登录](oauth/coding.md)
- [钉钉登录](oauth/dingtalk.md)
- [开源中国登录](oauth/oschina.md)
- [淘宝登录](oauth/taobao.md)
- - [腾讯云登录](oauth/tencentCloud.md)
- [Google登录](oauth/google.md)
- [Facebook登录](oauth/facebook.md)
- [抖音登录](oauth/douyin.md)
diff --git a/docs/oauth/alipay.md b/docs/oauth/alipay.md
index a14e545a796d56431a3bd486c2c63be6c1673454..deca4e05afc14ce953ab6bbf1aec0df4660986a8 100644
--- a/docs/oauth/alipay.md
+++ b/docs/oauth/alipay.md
@@ -95,6 +95,14 @@ c. 回到应用详情页面,点击【接口加签方式】后面的【设置
```
+```
+
+ com.alipay.sdk
+ alipay-sdk-java
+ 3.7.4.ALL
+
+```
+
`${latest.version}`表示当前最新的版本,可以在[这儿](https://github.com/justauth/JustAuth/releases)获取最新的版本信息。
### 2.2 创建Request
diff --git a/docs/oauth/coding.md b/docs/oauth/coding.md
new file mode 100644
index 0000000000000000000000000000000000000000..49e6399bd50c747dbc6c3d87f19b1f86fe08464f
--- /dev/null
+++ b/docs/oauth/coding.md
@@ -0,0 +1,151 @@
+## 1. 申请应用
+
+## 创建 CODING 应用
+1. 点击【个人设置】->【开放生态】->【创建应用】,注册需要接入 CODING 的应用。
+
+![](../_media/oauth/7fded4b4.png)
+
+2. 在创建应用页面,填写接入的应用信息:
+
+- 应用名称、应用主页及回调地址为必填项;
+- 其中回调地址是用户授权后,CODING 回调到应用,并且回传授权码的地址;
+- 如果没有上传图标将自动生成应用图标。
+
+填写完毕后,点击【创建应用】。
+
+![](../_media/oauth/ca78b40f.png)
+
+注意:回调地址不支持 `127.0.0.1`、`localhost` 等配置
+
+3. 应用创建完成后,在应用详情页,会生成 Client ID 和 Client Secret ,保存以便后续认证使用。
+
+![](../_media/oauth/ac549f1a.png)
+
+## 2. 集成JustAuth
+
+### 2.1 引入依赖
+
+```xml
+
+ me.zhyd.oauth
+ JustAuth
+ ${latest.version}
+
+```
+
+`${latest.version}`表示当前最新的版本,可以在[这儿](https://github.com/justauth/JustAuth/releases)获取最新的版本信息。
+
+### 2.2 创建Request
+
+```java
+AuthRequest authRequest = new AuthTencentCloudRequest(AuthConfig.builder()
+ .clientId("App Key")
+ .clientSecret("App Secret")
+ .redirectUri("授权回调页")
+ .build());
+```
+
+### 2.3 生成授权地址
+
+我们可以直接使用以下方式生成第三方平台的授权链接:
+```java
+String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
+```
+这个链接我们可以直接后台重定向跳转,也可以返回到前端后,前端控制跳转。前端控制的好处就是,可以将第三方的授权页嵌入到iframe中,适配网站设计。
+
+
+### 2.4 以上完整代码如下
+
+```java
+import me.zhyd.oauth.config.AuthConfig;
+import me.zhyd.oauth.request.AuthWeiboRequest;
+import me.zhyd.oauth.model.AuthCallback;
+import me.zhyd.oauth.model.AuthToken;
+import me.zhyd.oauth.request.AuthRequest;
+import me.zhyd.oauth.utils.AuthStateUtils;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+
+@RestController
+@RequestMapping("/oauth")
+public class RestAuthController {
+
+ @RequestMapping("/render")
+ public void renderAuth(HttpServletResponse response) throws IOException {
+ AuthRequest authRequest = getAuthRequest();
+ response.sendRedirect(authRequest.authorize(AuthStateUtils.createState()));
+ }
+
+ @RequestMapping("/callback")
+ public Object login(AuthCallback callback) {
+ AuthRequest authRequest = getAuthRequest();
+ return authRequest.login(callback);
+ }
+
+ @RequestMapping("/revoke/{token}")
+ public Object revokeAuth(@PathVariable("token") String token) throws IOException {
+ AuthRequest authRequest = getAuthRequest();
+ return authRequest.revoke(AuthToken.builder().accessToken(token).build());
+ }
+
+ private AuthRequest getAuthRequest() {
+ return new AuthTencentCloudRequest(AuthConfig.builder()
+ .clientId("App Key")
+ .clientSecret("App Secret")
+ .redirectUri("授权回调页")
+ // 比如以“ https://justauth.coding.net/ ”为例,codingGroupName = justauth
+ .codingGroupName("团队名")
+ .build());
+ }
+}
+```
+授权链接访问成功后会看到以下页面内容:
+
+![](../_media/oauth/2f1b9c2c.png)
+
+## 3. 授权结果
+
+```json
+{
+ "code": 2000,
+ "msg": null,
+ "data": {
+ "uuid": "xxx",
+ "username": "yadong.zhang",
+ "nickname": "yadong.zhang",
+ "avatar": "https://coding.net/static/fruit_avatar/Fruit-6.png",
+ "blog": "https://coding.net/u/HNMxPTOFRd",
+ "company": "",
+ "location": "",
+ "email": null,
+ "remark": "",
+ "gender": "FEMALE",
+ "source": "CODING",
+ "token": {
+ "accessToken": "xx",
+ "expireIn": 858292,
+ "refreshToken": "xx",
+ "uid": null,
+ "openId": null,
+ "accessCode": null,
+ "unionId": null,
+ "scope": null,
+ "tokenType": null,
+ "idToken": null,
+ "macAlgorithm": null,
+ "macKey": null,
+ "code": null,
+ "oauthToken": null,
+ "oauthTokenSecret": null,
+ "userId": null,
+ "screenName": null,
+ "oauthCallbackConfirmed": null
+ }
+ }
+}
+```
\ No newline at end of file
diff --git a/docs/update.md b/docs/update.md
index 9537642e3624f5524a2708cbe75772482217a570..f3478f4d3a604cc9ac5497c8c638fb2c580b41de 100644
--- a/docs/update.md
+++ b/docs/update.md
@@ -1,3 +1,31 @@
+## 1.15.5-alpha
+### 2020/06/07
+- 修复
+ - 解决 `Microsoft` 授权失败的 BUG
+ - 解决 `Coding` 个人账号授权失败的 BUG(目前只能使用团队模式进行授权,需要传入团队名,参考`AuthConfig#codingGroupName`)
+- 新增
+ - 支持 Http 级的代理配置,使用方式:
+```java
+new AuthGoogleRequest(AuthConfig.builder()
+ .clientId("")
+ .clientSecret("")
+ .redirectUri("http://127.0.0.1:8443/oauth/callback/google")
+ // 针对国外平台配置代理
+ .httpConfig(HttpConfig.builder()
+ .timeout(15000)
+ .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10080)))
+ .build())
+ .build());
+```
+- 删除
+ - 删除**腾讯云登录**。coding 已并入 腾讯云,因此只保留 coding 登录
+- 文档
+ - 新增 [Coding登录](oauth/coding.md)文档
+ - 完善 [支付宝登录](oauth/alipay.md)文档
+- PR
+ - 合并 [Gitee!17](https://gitee.com/yadong.zhang/JustAuth/pulls/17)
+ - 合并 [Gitee!15](https://gitee.com/yadong.zhang/JustAuth/pulls/15)
+
## 1.15.4-alpha
### 2020/05/13
- 修复
diff --git a/pom.xml b/pom.xml
index 031abdaac6d09984d1a6e6294d99e2aa104d1f60..de883886eec77438be69f5e386ad44c16eeb7594 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.zhyd.oauth
JustAuth
- 1.15.4-alpha
+ 1.15.5-alpha
JustAuth
https://gitee.com/yadong.zhang/JustAuth
@@ -60,7 +60,7 @@
2.20
1.6
false
- 1.0.1
+ 1.0.2-SNAPSHOT
1.18.10
4.11
1.2.69
diff --git a/src/main/java/me/zhyd/oauth/config/AuthConfig.java b/src/main/java/me/zhyd/oauth/config/AuthConfig.java
index 3a64aeafb13838e55397bab532d9270354cffff2..e17bcd89a5aba83ccac8faefb4244f2087ea6710 100644
--- a/src/main/java/me/zhyd/oauth/config/AuthConfig.java
+++ b/src/main/java/me/zhyd/oauth/config/AuthConfig.java
@@ -1,5 +1,6 @@
package me.zhyd.oauth.config;
+import com.xkcoding.http.config.HttpConfig;
import lombok.*;
/**
@@ -59,4 +60,23 @@ public class AuthConfig {
* @since 1.10.0
*/
private String agentId;
+
+ /**
+ * 使用 Coding 登录时,需要传该值。
+ *
+ * 团队域名前缀,比如以“ https://justauth.coding.net/ ”为例,{@code codingGroupName} = justauth
+ *
+ * @since 1.15.5
+ */
+ private String codingGroupName;
+
+ /**
+ * 针对国外服务可以单独设置代理
+ * HttpConfig config = new HttpConfig();
+ * config.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10080)));
+ * config.setTimeout(15000);
+ *
+ * @since 1.15.5
+ */
+ private HttpConfig httpConfig;
}
diff --git a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
index 8ed7488bdc7e3eb7f5ab05903713df40e42405d5..1a02e736a3ccc6df8aa016277c21f89fca77ac6e 100644
--- a/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
+++ b/src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
@@ -140,41 +140,25 @@ public enum AuthDefaultSource implements AuthSource {
}
},
/**
- * Coding
+ * Coding,
+ *
+ * 参考 https://help.coding.net/docs/project/open/oauth.html#%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83 中的说明,
+ * 新版的 coding API 地址需要传入用户团队名,这儿使用动态参数,方便在 request 中使用
*/
CODING {
@Override
public String authorize() {
- return "https://coding.net/oauth_authorize.html";
- }
-
- @Override
- public String accessToken() {
- return "https://coding.net/api/oauth/access_token";
- }
-
- @Override
- public String userInfo() {
- return "https://coding.net/api/account/current_user";
- }
- },
- /**
- * 腾讯云开发者平台(coding升级后就变成腾讯云开发者平台了)
- */
- TENCENT_CLOUD {
- @Override
- public String authorize() {
- return "https://dev.tencent.com/oauth_authorize.html";
+ return "https://%s.coding.net/oauth_authorize.html";
}
@Override
public String accessToken() {
- return "https://dev.tencent.com/api/oauth/access_token";
+ return "https://%s.coding.net/api/oauth/access_token";
}
@Override
public String userInfo() {
- return "https://dev.tencent.com/api/account/current_user";
+ return "https://%s.coding.net/api/account/current_user";
}
},
/**
diff --git a/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java b/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
index e21f9233afcf7f786917a06d1191e7e06c21ac55..0ad7fad9f5499139eb0cad5d20013f534c2c607a 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -37,13 +37,20 @@ public class AuthBaiduRequest extends AuthDefaultRequest {
return getAuthToken(response);
}
+ /**
+ * https://openapi.baidu.com/rest/2.0/passport/users/getInfo?access_token=121.c86e87cc0828cc1dabb8faee540531d4.YsUIAWvYbgqVni1VhkgKgyLh8nEyELbDOEZs_OA.OgDgmA
+ * https://openapi.baidu.com/rest/2.0/passport/users/getInfo?access_token=121.2907d9facf9fb97adf7287fa75496eda.Y3NSjR3-3HKt1RgT0HEl7GgxRXT5gOOVdngXezY.OcC_7g
+ * 新旧应用返回的用户信息不一致
+ * @param authToken token信息
+ * @return AuthUser
+ */
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String userInfo = doGetUserInfo(authToken);
JSONObject object = JSONObject.parseObject(userInfo);
this.checkResponse(object);
return AuthUser.builder()
- .uuid(object.getString("userid"))
+ .uuid(object.containsKey("userid") ? object.getString("userid") : object.getString("openid"))
.username(object.getString("username"))
.nickname(object.getString("username"))
.avatar(getAvatar(object))
@@ -77,7 +84,7 @@ public class AuthBaiduRequest extends AuthDefaultRequest {
.queryParam("client_id", this.config.getClientId())
.queryParam("client_secret", this.config.getClientSecret())
.build();
- String response = HttpUtil.get(refreshUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(refreshUrl);
return AuthResponse.builder()
.code(AuthResponseStatus.SUCCESS.getCode())
.data(this.getAuthToken(response))
diff --git a/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java b/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
index 3285203df23587704ed5554355da8bc4b1d2ede1..ca974a505c991a96acce5853bcef5527ccdcc88c 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
@@ -49,8 +49,8 @@ public class AuthCodingRequest extends AuthDefaultRequest {
return AuthUser.builder()
.uuid(object.getString("id"))
.username(object.getString("name"))
- .avatar("https://coding.net/" + object.getString("avatar"))
- .blog("https://coding.net/" + object.getString("path"))
+ .avatar("https://coding.net" + object.getString("avatar"))
+ .blog("https://coding.net" + object.getString("path"))
.nickname(object.getString("name"))
.company(object.getString("company"))
.location(object.getString("location"))
@@ -82,7 +82,7 @@ public class AuthCodingRequest extends AuthDefaultRequest {
*/
@Override
public String authorize(String state) {
- return UrlBuilder.fromBaseUrl(source.authorize())
+ return UrlBuilder.fromBaseUrl(String.format(source.authorize(), config.getCodingGroupName()))
.queryParam("response_type", "code")
.queryParam("client_id", config.getClientId())
.queryParam("redirect_uri", config.getRedirectUri())
@@ -90,4 +90,33 @@ public class AuthCodingRequest extends AuthDefaultRequest {
.queryParam("state", getRealState(state))
.build();
}
+ /**
+ * 返回获取accessToken的url
+ *
+ * @param code 授权码
+ * @return 返回获取accessToken的url
+ */
+ @Override
+ public String accessTokenUrl(String code) {
+ return UrlBuilder.fromBaseUrl(String.format(source.accessToken(), config.getCodingGroupName()))
+ .queryParam("code", code)
+ .queryParam("client_id", config.getClientId())
+ .queryParam("client_secret", config.getClientSecret())
+ .queryParam("grant_type", "authorization_code")
+ .queryParam("redirect_uri", config.getRedirectUri())
+ .build();
+ }
+
+ /**
+ * 返回获取userInfo的url
+ *
+ * @param authToken token
+ * @return 返回获取userInfo的url
+ */
+ @Override
+ public String userInfoUrl(AuthToken authToken) {
+ return UrlBuilder.fromBaseUrl(String.format(source.userInfo(), config.getCodingGroupName()))
+ .queryParam("access_token", authToken.getAccessToken())
+ .build();
+ }
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java b/src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
index b4e431dba442228dc72ae23daa198491c7e4af6f..fe17868858a78efbf16a16f74fc1f0f5ee188ed0 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
@@ -1,6 +1,6 @@
package me.zhyd.oauth.request;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthDefaultStateCache;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
@@ -210,7 +210,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
* @return Response
*/
protected String doPostAuthorizationCode(String code) {
- return HttpUtil.post(accessTokenUrl(code));
+ return new HttpUtils(config.getHttpConfig()).post(accessTokenUrl(code));
}
/**
@@ -220,7 +220,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
* @return Response
*/
protected String doGetAuthorizationCode(String code) {
- return HttpUtil.get(accessTokenUrl(code));
+ return new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(code));
}
/**
@@ -231,7 +231,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
*/
@Deprecated
protected String doPostUserInfo(AuthToken authToken) {
- return HttpUtil.post(userInfoUrl(authToken));
+ return new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken));
}
/**
@@ -241,7 +241,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
* @return Response
*/
protected String doGetUserInfo(AuthToken authToken) {
- return HttpUtil.get(userInfoUrl(authToken));
+ return new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken));
}
/**
@@ -252,7 +252,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
*/
@Deprecated
protected String doPostRevoke(AuthToken authToken) {
- return HttpUtil.post(revokeUrl(authToken));
+ return new HttpUtils(config.getHttpConfig()).post(revokeUrl(authToken));
}
/**
@@ -262,7 +262,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
* @return Response
*/
protected String doGetRevoke(AuthToken authToken) {
- return HttpUtil.get(revokeUrl(authToken));
+ return new HttpUtils(config.getHttpConfig()).get(revokeUrl(authToken));
}
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java b/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
index af10d9a64f4439e9dd6fcb618aed78f12655ad53..1332e995c4d836f84f89c39edbd3693247f67088 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
@@ -2,7 +2,7 @@ package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -40,7 +40,7 @@ public class AuthDingTalkRequest extends AuthDefaultRequest {
String code = authToken.getAccessCode();
JSONObject param = new JSONObject();
param.put("tmp_auth_code", code);
- String response = HttpUtil.post(userInfoUrl(authToken), param.toJSONString());
+ String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), param.toJSONString());
JSONObject object = JSON.parseObject(response);
if (object.getIntValue("errcode") != 0) {
throw new AuthException(object.getString("errmsg"));
diff --git a/src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java b/src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
index 86461b05f84feab357050cd50f6e4a802fc6819c..6529829c2be134c4f900d4ddd281a0c2ec2805b1 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -84,7 +84,7 @@ public class AuthDouyinRequest extends AuthDefaultRequest {
* @return token对象
*/
private AuthToken getToken(String accessTokenUrl) {
- String response = HttpUtil.post(accessTokenUrl);
+ String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
JSONObject dataObj = object.getJSONObject("data");
diff --git a/src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java b/src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java
index 7ecdb935a9b89de23a3d34afdf9d7b1aa62208f7..579d4411a7e3b1897b8d435b7f1f9f0f332b47a4 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.constants.Constants;
import com.xkcoding.http.support.HttpHeader;
import me.zhyd.oauth.cache.AuthStateCache;
@@ -52,7 +52,7 @@ public class AuthElemeRequest extends AuthDefaultRequest {
form.put("grant_type", "authorization_code");
HttpHeader httpHeader = this.buildHeader(CONTENT_TYPE_FORM, this.getRequestId(), true);
- String response = HttpUtil.post(source.accessToken(), form, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -91,7 +91,7 @@ public class AuthElemeRequest extends AuthDefaultRequest {
paramsMap.put("signature", signature);
HttpHeader httpHeader = this.buildHeader(CONTENT_TYPE_JSON, requestId, false);
- String response = HttpUtil.post(source.userInfo(), JSONObject.toJSONString(paramsMap), httpHeader);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), JSONObject.toJSONString(paramsMap), httpHeader);
JSONObject object = JSONObject.parseObject(response);
@@ -122,7 +122,7 @@ public class AuthElemeRequest extends AuthDefaultRequest {
form.put("grant_type", "refresh_token");
HttpHeader httpHeader = this.buildHeader(CONTENT_TYPE_FORM, this.getRequestId(), true);
- String response = HttpUtil.post(source.refresh(), form, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, httpHeader, false);
JSONObject object = JSONObject.parseObject(response);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java b/src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java
index 67b3aaf9cf5e1ebd7af5e25dc13a7e4b9b71266f..93689edd9fe4fb706e7f696e75319c8ac2d062fa 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java
@@ -2,7 +2,6 @@ package me.zhyd.oauth.request;
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;
@@ -13,6 +12,7 @@ import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.GlobalAuthUtils;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder;
/**
@@ -36,7 +36,7 @@ public class AuthFeishuRequest extends AuthDefaultRequest {
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()
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), requestObject.toJSONString(), new HttpHeader()
.add("Content-Type", "application/json"));
JSONObject jsonObject = JSON.parseObject(response);
this.checkResponse(jsonObject);
@@ -53,7 +53,7 @@ public class AuthFeishuRequest extends AuthDefaultRequest {
@Override
protected AuthUser getUserInfo(AuthToken authToken) {
String accessToken = authToken.getAccessToken();
- String response = HttpUtil.get(source.userInfo(), null, new HttpHeader()
+ String response = new HttpUtils(config.getHttpConfig()).get(source.userInfo(), null, new HttpHeader()
.add("Content-Type", "application/json")
.add("Authorization", "Bearer " + accessToken), false);
JSONObject jsonObject = JSON.parseObject(response);
@@ -72,7 +72,7 @@ public class AuthFeishuRequest extends AuthDefaultRequest {
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()
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), requestObject.toJSONString(), new HttpHeader()
.add("Content-Type", "application/json"));
JSONObject jsonObject = JSON.parseObject(response);
this.checkResponse(jsonObject);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java b/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
index 242db08554a8096ec16f2703cd4f9b42d553c6e8..e3e9c6332c5824876015f2cfc216337d12725088 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.support.HttpHeader;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
@@ -47,7 +47,7 @@ public class AuthGoogleRequest extends AuthDefaultRequest {
protected AuthUser getUserInfo(AuthToken authToken) {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Authorization", "Bearer " + authToken.getAccessToken());
- String userInfo = HttpUtil.post(userInfoUrl(authToken), null, httpHeader);
+ String userInfo = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, httpHeader);
JSONObject object = JSONObject.parseObject(userInfo);
this.checkResponse(object);
return AuthUser.builder()
diff --git a/src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java b/src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java
index 4544a92b0898320f2c50324e0d38b75ced2286ef..5fbeec3d213877ca394e7d3daccf3f72c052d33b 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -52,7 +52,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
form.put("client_secret", config.getClientSecret());
form.put("redirect_uri", config.getRedirectUri());
- String response = HttpUtil.post(source.accessToken(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false);
return getAuthToken(response);
}
@@ -71,7 +71,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
form.put("nsp_fmt", "JS");
form.put("nsp_svc", "OpenUP.User.getInfo");
- String response = HttpUtil.post(source.userInfo(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -103,7 +103,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
form.put("refresh_token", authToken.getRefreshToken());
form.put("grant_type", "refresh_token");
- String response = HttpUtil.post(source.refresh(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
return AuthResponse.builder().code(SUCCESS.getCode()).data(getAuthToken(response)).build();
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthJdRequest.java b/src/main/java/me/zhyd/oauth/request/AuthJdRequest.java
index 0bc9a980981393cad3f0ab8a28df18d300e90e30..7fd18d46c544696db038a1f55380d8a96629f8a2 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthJdRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthJdRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -44,7 +44,7 @@ public class AuthJdRequest extends AuthDefaultRequest {
params.put("app_secret", config.getClientSecret());
params.put("grant_type", "authorization_code");
params.put("code", authCallback.getCode());
- String response = HttpUtil.post(source.accessToken(), params, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -68,7 +68,7 @@ public class AuthJdRequest extends AuthDefaultRequest {
.queryParam("timestamp", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
.queryParam("v", "2.0");
urlBuilder.queryParam("sign", GlobalAuthUtils.generateJdSignature(config.getClientSecret(), urlBuilder.getReadOnlyParams()));
- String response = HttpUtil.post(urlBuilder.build(true));
+ String response = new HttpUtils(config.getHttpConfig()).post(urlBuilder.build(true));
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -106,7 +106,7 @@ public class AuthJdRequest extends AuthDefaultRequest {
params.put("app_secret", config.getClientSecret());
params.put("grant_type", "refresh_token");
params.put("refresh_token", oldToken.getRefreshToken());
- String response = HttpUtil.post(source.refresh(), params, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), params, false);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java b/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
index d15786f63ec5d415cf5ed0c6013d6d4a24883496..2c9caa9b5585e202f05824fbb4f31a1d6710af3d 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -90,7 +90,7 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
@Override
public AuthUser getUserInfo(AuthToken authToken) {
String openId = this.getOpenId(authToken);
- String response = HttpUtil.get(UrlBuilder.fromBaseUrl(source.userInfo())
+ String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl(source.userInfo())
.queryParam("access_token", authToken.getAccessToken())
.queryParam("open_id", openId)
.build());
@@ -117,7 +117,7 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
* @return openId
*/
private String getOpenId(AuthToken authToken) {
- String response = HttpUtil.get(UrlBuilder.fromBaseUrl("https://oauth.kujiale.com/oauth2/auth/user")
+ String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl("https://oauth.kujiale.com/oauth2/auth/user")
.queryParam("access_token", authToken.getAccessToken())
.build());
JSONObject accessTokenObject = checkResponse(response);
@@ -126,7 +126,7 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
@Override
public AuthResponse refresh(AuthToken authToken) {
- String response = HttpUtil.post(refreshTokenUrl(authToken.getRefreshToken()));
+ String response = new HttpUtils(config.getHttpConfig()).post(refreshTokenUrl(authToken.getRefreshToken()));
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(getAuthToken(response)).build();
}
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java b/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
index 88acfff22b0d736244bf88d113b025dc79c081b9..ba255cdccaec95045d93fd87b56ec2cd3438304e 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
@@ -3,7 +3,7 @@ package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.constants.Constants;
import com.xkcoding.http.support.HttpHeader;
import me.zhyd.oauth.cache.AuthStateCache;
@@ -49,7 +49,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
httpHeader.add("Connection", "Keep-Alive");
httpHeader.add("Authorization", "Bearer " + accessToken);
- String response = HttpUtil.get(userInfoUrl(authToken), null, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
JSONObject userInfoObject = JSONObject.parseObject(response);
this.checkResponse(userInfoObject);
@@ -128,7 +128,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
httpHeader.add("Connection", "Keep-Alive");
httpHeader.add("Authorization", "Bearer " + accessToken);
- String emailResponse = HttpUtil.get("https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))", null, httpHeader, false);
+ String emailResponse = new HttpUtils(config.getHttpConfig()).get("https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))", null, httpHeader, false);
JSONObject emailObj = JSONObject.parseObject(emailResponse);
this.checkResponse(emailObj);
@@ -181,7 +181,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
httpHeader.add("Host", "www.linkedin.com");
httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded");
- String response = HttpUtil.post(accessTokenUrl, null, httpHeader);
+ String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, null, httpHeader);
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthMeituanRequest.java b/src/main/java/me/zhyd/oauth/request/AuthMeituanRequest.java
index d4e2e917f1a11891393965d5e0987b727f1e535a..6ebff5789d2dcd73223e56f96594dd83b8d8d5fc 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthMeituanRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthMeituanRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -41,7 +41,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
form.put("code", authCallback.getCode());
form.put("grant_type", "authorization_code");
- String response = HttpUtil.post(source.accessToken(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -60,7 +60,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
form.put("secret", config.getClientSecret());
form.put("access_token", authToken.getAccessToken());
- String response = HttpUtil.post(source.userInfo(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -84,7 +84,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
form.put("refresh_token", oldToken.getRefreshToken());
form.put("grant_type", "refresh_token");
- String response = HttpUtil.post(source.refresh(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java b/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
index ee85c51dbd1a2ce25272514c1f6811628f9812d8..878083f4a0eaebc959a828794c052abae3934613 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.constants.Constants;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
@@ -41,7 +41,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
}
private AuthToken getToken(String accessTokenUrl) {
- String response = HttpUtil.get(accessTokenUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl);
String jsonStr = response.replace(PREFIX, Constants.EMPTY);
JSONObject accessTokenObject = JSONObject.parseObject(jsonStr);
@@ -88,7 +88,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
String emailPhoneUrl = MessageFormat.format("{0}?clientId={1}&token={2}", "https://open.account.xiaomi.com/user/phoneAndEmail", config
.getClientId(), authToken.getAccessToken());
- String emailResponse = HttpUtil.get(emailPhoneUrl);
+ String emailResponse = new HttpUtils(config.getHttpConfig()).get(emailPhoneUrl);
JSONObject userEmailPhone = JSONObject.parseObject(emailResponse);
if (!"error".equalsIgnoreCase(userEmailPhone.getString("result"))) {
JSONObject emailPhone = userEmailPhone.getJSONObject("data");
diff --git a/src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java b/src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
index c8a132d74db91aec1d935f1452bbb162406630ba..61390fbce82db96fdf5ba3db467bbeee787b09ba 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.constants.Constants;
import com.xkcoding.http.support.HttpHeader;
import com.xkcoding.http.util.MapUtil;
@@ -47,12 +47,10 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
*/
private AuthToken getToken(String accessTokenUrl) {
HttpHeader httpHeader = new HttpHeader();
- httpHeader.add("Host", "https://login.microsoftonline.com");
- httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded");
Map form = MapUtil.parseStringToMap(accessTokenUrl, false);
- String response = HttpUtil.post(accessTokenUrl, form, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false);
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
@@ -86,7 +84,7 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Authorization", jwt);
- String userInfo = HttpUtil.get(userInfoUrl(authToken), null, httpHeader, false);
+ String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
JSONObject object = JSONObject.parseObject(userInfo);
this.checkResponse(object);
return AuthUser.builder()
@@ -129,7 +127,7 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
.queryParam("client_id", config.getClientId())
.queryParam("redirect_uri", config.getRedirectUri())
.queryParam("response_mode", "query")
- .queryParam("scope", "offline_access%20user.read%20mail.read")
+ .queryParam("scope", "offline_access user.read mail.read")
.queryParam("state", getRealState(state))
.build();
}
@@ -147,7 +145,7 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
.queryParam("client_id", config.getClientId())
.queryParam("client_secret", config.getClientSecret())
.queryParam("grant_type", "authorization_code")
- .queryParam("scope", "user.read%20mail.read")
+ .queryParam("scope", "offline_access user.read mail.read")
.queryParam("redirect_uri", config.getRedirectUri())
.build();
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java b/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
index 6efadd55ee59d975f2a55e9293162cd714108f58..c3fd0b5f60bbbd3ba51f232e925b687d9c49bc57 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.enums.AuthUserGender;
@@ -48,7 +48,7 @@ public class AuthPinterestRequest extends AuthDefaultRequest {
protected AuthUser getUserInfo(AuthToken authToken) {
String userinfoUrl = userInfoUrl(authToken);
// TODO: 是否需要 .setFollowRedirects(true)
- String response = HttpUtil.get(userinfoUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(userinfoUrl);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
JSONObject userObj = object.getJSONObject("data");
diff --git a/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java b/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
index 010734554d95e6bd0e2b4d2e78dd742850e7e6af..f2c1b777f9e0bfdc0e03d5f0fdaf0e3e965adee7 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -42,7 +42,7 @@ public class AuthQqRequest extends AuthDefaultRequest {
@Override
public AuthResponse refresh(AuthToken authToken) {
- String response = HttpUtil.get(refreshTokenUrl(authToken.getRefreshToken()));
+ String response = new HttpUtils(config.getHttpConfig()).get(refreshTokenUrl(authToken.getRefreshToken()));
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(getAuthToken(response)).build();
}
@@ -80,7 +80,7 @@ public class AuthQqRequest extends AuthDefaultRequest {
* @return openId
*/
private String getOpenId(AuthToken authToken) {
- String response = HttpUtil.get(UrlBuilder.fromBaseUrl("https://graph.qq.com/oauth2.0/me")
+ String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl("https://graph.qq.com/oauth2.0/me")
.queryParam("access_token", authToken.getAccessToken())
.queryParam("unionid", config.isUnionId() ? 1 : 0)
.build());
diff --git a/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java b/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
index 889a418e99f00c89c329a087fd45612287cc8f97..e900f79bdaeaf7ff176936d7bdf4a7ee8c699b7e 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
@@ -2,7 +2,7 @@ package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.enums.AuthUserGender;
@@ -64,7 +64,7 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
}
private AuthToken getToken(String url) {
- String response = HttpUtil.post(url);
+ String response = new HttpUtils(config.getHttpConfig()).post(url);
JSONObject jsonObject = JSONObject.parseObject(response);
if (jsonObject.containsKey("error")) {
throw new AuthException("Failed to get token from Renren: " + jsonObject);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java b/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
index c98be60da06767b9d647ddf45be4ab88739f91e6..27c3f2812716a468e27bea408f67e17e76512ed7 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.constants.Constants;
import com.xkcoding.http.support.HttpHeader;
import com.xkcoding.http.util.MapUtil;
@@ -40,7 +40,7 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest {
Map form = MapUtil.parseStringToMap(accessTokenUrl, false);
HttpHeader httpHeader = new HttpHeader();
httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded");
- String response = HttpUtil.post(accessTokenUrl, form, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false);
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
@@ -58,7 +58,7 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest {
.queryParam("site", "stackoverflow")
.queryParam("key", this.config.getStackOverflowKey())
.build();
- String response = HttpUtil.get(userInfoUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
JSONObject userObj = object.getJSONArray("items").getJSONObject(0);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java b/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
index ebfd2a2fe8e575be97e3c96315bf64710661ed29..cb6a743cfa04e6b6566308046cd5c46c0369af62 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.support.HttpHeader;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
@@ -45,7 +45,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
form.put("code", authCallback.getCode());
form.put("grant_type", "code");
- String response = HttpUtil.post(source.accessToken(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false);
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
@@ -63,7 +63,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Authorization", "OAuth2 " + accessToken);
- String response = HttpUtil.get(source.userInfo(), null, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).get(source.userInfo(), null, httpHeader, false);
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -92,7 +92,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
Map form = new HashMap<>(2);
form.put("_userId", uid);
form.put("refresh_token", refreshToken);
- String response = HttpUtil.post(source.refresh(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
JSONObject refreshTokenObject = JSONObject.parseObject(response);
this.checkResponse(refreshTokenObject);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java b/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
deleted file mode 100644
index 1f5ea310acee32e27f4fccf3d764074380f02055..0000000000000000000000000000000000000000
--- a/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package me.zhyd.oauth.request;
-
-import com.alibaba.fastjson.JSONObject;
-import me.zhyd.oauth.cache.AuthStateCache;
-import me.zhyd.oauth.config.AuthConfig;
-import me.zhyd.oauth.config.AuthDefaultSource;
-import me.zhyd.oauth.enums.AuthUserGender;
-import me.zhyd.oauth.exception.AuthException;
-import me.zhyd.oauth.model.AuthCallback;
-import me.zhyd.oauth.model.AuthToken;
-import me.zhyd.oauth.model.AuthUser;
-import me.zhyd.oauth.utils.UrlBuilder;
-
-/**
- * 腾讯云登录
- *
- * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
- * @since 1.0.0
- */
-public class AuthTencentCloudRequest extends AuthDefaultRequest {
-
- public AuthTencentCloudRequest(AuthConfig config) {
- super(config, AuthDefaultSource.TENCENT_CLOUD);
- }
-
- public AuthTencentCloudRequest(AuthConfig config, AuthStateCache authStateCache) {
- super(config, AuthDefaultSource.TENCENT_CLOUD, authStateCache);
- }
-
- @Override
- protected AuthToken getAccessToken(AuthCallback authCallback) {
- String response = doGetAuthorizationCode(authCallback.getCode());
- JSONObject accessTokenObject = JSONObject.parseObject(response);
- this.checkResponse(accessTokenObject);
- return AuthToken.builder()
- .accessToken(accessTokenObject.getString("access_token"))
- .expireIn(accessTokenObject.getIntValue("expires_in"))
- .refreshToken(accessTokenObject.getString("refresh_token"))
- .build();
- }
-
- @Override
- protected AuthUser getUserInfo(AuthToken authToken) {
- String response = doGetUserInfo(authToken);
- JSONObject object = JSONObject.parseObject(response);
- this.checkResponse(object);
-
- object = object.getJSONObject("data");
- return AuthUser.builder()
- .uuid(object.getString("id"))
- .username(object.getString("name"))
- .avatar("https://dev.tencent.com/" + object.getString("avatar"))
- .blog("https://dev.tencent.com/" + object.getString("path"))
- .nickname(object.getString("name"))
- .company(object.getString("company"))
- .location(object.getString("location"))
- .gender(AuthUserGender.getRealGender(object.getString("sex")))
- .email(object.getString("email"))
- .remark(object.getString("slogan"))
- .token(authToken)
- .source(source.toString())
- .build();
- }
-
- /**
- * 检查响应内容是否正确
- *
- * @param object 请求响应内容
- */
- private void checkResponse(JSONObject object) {
- if (object.getIntValue("code") != 0) {
- throw new AuthException(object.getString("msg"));
- }
- }
-
- /**
- * 返回带{@code state}参数的授权url,授权回调时会带上这个{@code state}
- *
- * @param state state 验证授权流程的参数,可以防止csrf
- * @return 返回授权地址
- * @since 1.9.3
- */
- @Override
- public String authorize(String state) {
- return UrlBuilder.fromBaseUrl(source.authorize())
- .queryParam("response_type", "code")
- .queryParam("client_id", config.getClientId())
- .queryParam("redirect_uri", config.getRedirectUri())
- .queryParam("scope", "user")
- .queryParam("state", getRealState(state))
- .build();
- }
-}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java b/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java
index 3b29800897c36738f86b93ea1e81ba67912c0ff9..65ba5cac84d5f6722fbb65f538a673c96fb6fcb3 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.constants.Constants;
import com.xkcoding.http.support.HttpHeader;
import com.xkcoding.http.util.MapUtil;
@@ -72,7 +72,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
httpHeader.add("User-Agent", "themattharris' HTTP Client");
httpHeader.add("Host", "api.twitter.com");
httpHeader.add("Accept", "*/*");
- String requestToken = HttpUtil.post(baseUrl, null, httpHeader);
+ String requestToken = new HttpUtils(config.getHttpConfig()).post(baseUrl, null, httpHeader);
Map res = MapUtil.parseStringToMap(requestToken, false);
@@ -104,7 +104,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
Map form = new HashMap<>(1);
form.put("oauth_verifier", authCallback.getOauth_verifier());
- String response = HttpUtil.post(source.accessToken(), form, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false);
Map requestToken = MapUtil.parseStringToMap(response, false);
@@ -134,7 +134,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Authorization", header);
- String response = HttpUtil.get(userInfoUrl(authToken), null, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
JSONObject userInfo = JSONObject.parseObject(response);
return AuthUser.builder()
diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseRequest.java
index 93fdaded3dc97ac84b5d73ea21dcbae111fec71b..389be7a24fc59506a69157dd7f353c6afea235d2 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -148,7 +148,7 @@ public class AuthWeChatEnterpriseRequest extends AuthDefaultRequest {
.queryParam("access_token", accessToken)
.queryParam("userid", userId)
.build();
- return HttpUtil.get(userDetailUrl);
+ return new HttpUtils(config.getHttpConfig()).get(userDetailUrl);
}
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java
index 29ab5ec6b5beae5a276851fae49c6b53e87edabd..8b78bd100bb5562a73020aaa8ddd64a7676d9534 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -94,7 +94,7 @@ public class AuthWeChatMpRequest extends AuthDefaultRequest {
* @return token对象
*/
private AuthToken getToken(String accessTokenUrl) {
- String response = HttpUtil.get(accessTokenUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl);
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeChatOpenRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeChatOpenRequest.java
index 241b9c0b0a012bb9b0305e1662cc83ea44058c09..e04bda9d271e3e86ce13c71f8b4192313e40ecdc 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeChatOpenRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeChatOpenRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
@@ -93,7 +93,7 @@ public class AuthWeChatOpenRequest extends AuthDefaultRequest {
* @return token对象
*/
private AuthToken getToken(String accessTokenUrl) {
- String response = HttpUtil.get(accessTokenUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl);
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
index ecc3401c5058945da4d453f08ee9d13783eeb8aa..362645bc7407800dd6f3350156494f8dcbcb920a 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
@@ -1,7 +1,7 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
-import com.xkcoding.http.HttpUtil;
+import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.support.HttpHeader;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
@@ -58,7 +58,7 @@ public class AuthWeiboRequest extends AuthDefaultRequest {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Authorization", "OAuth2 " + oauthParam);
httpHeader.add("API-RemoteIP", IpUtils.getLocalIp());
- String userInfo = HttpUtil.get(userInfoUrl(authToken), null, httpHeader, false);
+ String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
JSONObject object = JSONObject.parseObject(userInfo);
if (object.containsKey("error")) {
throw new AuthException(object.getString("error"));
diff --git a/src/main/java/me/zhyd/oauth/utils/AuthChecker.java b/src/main/java/me/zhyd/oauth/utils/AuthChecker.java
index 4761d2ce3c1f500fae14b5dd44a5e6f1eb08e540..703729ed7439d11176fed4c05ab1eb7e04d7a155 100644
--- a/src/main/java/me/zhyd/oauth/utils/AuthChecker.java
+++ b/src/main/java/me/zhyd/oauth/utils/AuthChecker.java
@@ -35,6 +35,9 @@ public class AuthChecker {
if (isSupported && AuthDefaultSource.WECHAT_ENTERPRISE == source) {
isSupported = StringUtils.isNotEmpty(config.getAgentId());
}
+ if (isSupported && AuthDefaultSource.CODING == source) {
+ isSupported = StringUtils.isNotEmpty(config.getCodingGroupName());
+ }
return isSupported;
}
diff --git a/src/main/java/me/zhyd/oauth/utils/HttpUtils.java b/src/main/java/me/zhyd/oauth/utils/HttpUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..f5414908e58c0b8dc0f83c01e8f148adfc13b143
--- /dev/null
+++ b/src/main/java/me/zhyd/oauth/utils/HttpUtils.java
@@ -0,0 +1,105 @@
+package me.zhyd.oauth.utils;
+
+import com.xkcoding.http.HttpUtil;
+import com.xkcoding.http.config.HttpConfig;
+import com.xkcoding.http.support.HttpHeader;
+
+import java.util.Map;
+
+/**
+ * HttpUtil 工具,统一处理 http 请求,方便对 simple-http 做定制
+ * @author yadong.zhang (yadong.zhang0415(a)gmail.com)
+ * @version 1.0.0
+ * @since 1.0.0
+ */
+public class HttpUtils {
+
+ public HttpUtils(HttpConfig config) {
+ HttpUtil.setConfig(config);
+ }
+
+ public HttpUtils() {
+ }
+
+
+ /**
+ * GET 请求
+ *
+ * @param url URL
+ * @return 结果
+ */
+ public String get(String url) {
+ return HttpUtil.get(url);
+ }
+
+ /**
+ * GET 请求
+ *
+ * @param url URL
+ * @param params 参数
+ * @param header 请求头
+ * @param encode 是否需要 url encode
+ * @return 结果
+ */
+ public String get(String url, Map params, HttpHeader header, boolean encode) {
+ return HttpUtil.get(url, params, header, encode);
+ }
+
+ /**
+ * POST 请求
+ *
+ * @param url URL
+ * @return 结果
+ */
+ public String post(String url) {
+ return HttpUtil.post(url);
+ }
+
+ /**
+ * POST 请求
+ *
+ * @param url URL
+ * @param data JSON 参数
+ * @return 结果
+ */
+ public String post(String url, String data) {
+ return HttpUtil.post(url, data);
+ }
+
+ /**
+ * POST 请求
+ *
+ * @param url URL
+ * @param data JSON 参数
+ * @param header 请求头
+ * @return 结果
+ */
+ public String post(String url, String data, HttpHeader header) {
+ return HttpUtil.post(url, data, header);
+ }
+
+ /**
+ * POST 请求
+ *
+ * @param url URL
+ * @param params form 参数
+ * @param encode 是否需要 url encode
+ * @return 结果
+ */
+ public String post(String url, Map params, boolean encode) {
+ return HttpUtil.post(url, params, encode);
+ }
+
+ /**
+ * POST 请求
+ *
+ * @param url URL
+ * @param params form 参数
+ * @param header 请求头
+ * @param encode 是否需要 url encode
+ * @return 结果
+ */
+ public String post(String url, Map params, HttpHeader header, boolean encode) {
+ return HttpUtil.post(url, params, header, encode);
+ }
+}