diff --git a/CHANGELOGS.md b/CHANGELOGS.md
index d716c09f18ebbd0084d63ed937915f6fe5d4b408..2d6aa9034c914bb1c81e97c735f1a59c965aeef7 100644
--- a/CHANGELOGS.md
+++ b/CHANGELOGS.md
@@ -1,3 +1,7 @@
+## 1.16.4
+
+### 2021/9/**
+
## 1.16.3
### 2021/8/15
diff --git a/bin/version.txt b/bin/version.txt
index c807441cfed775b6a380f89e94839114a6632b54..a23207367c39c3f8d7065ce4c05e795540b590cb 100644
--- a/bin/version.txt
+++ b/bin/version.txt
@@ -1 +1 @@
-1.16.3
+1.16.4
diff --git a/pom.xml b/pom.xml
index 9b058ab14ca08eb7f2b731c47f05e668b30aa66e..3e6d4199500d875e591de0e679c91f1d0e0f8917 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.zhyd.oauth
JustAuth
- 1.16.3
+ 1.16.4
JustAuth
https://gitee.com/yadong.zhang/JustAuth
@@ -57,7 +57,7 @@
2.20
1.6
false
- 1.0.3
+ 1.0.5
1.18.10
4.13.1
1.2.76
diff --git a/src/main/java/me/zhyd/oauth/request/AbstractAuthDingtalkRequest.java b/src/main/java/me/zhyd/oauth/request/AbstractAuthDingtalkRequest.java
index 9e5de29eef98c97df5ccf7904ebaea6e0881cf4d..b331e786725c9a0fae560207e6e5c7852b0fa158 100644
--- a/src/main/java/me/zhyd/oauth/request/AbstractAuthDingtalkRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AbstractAuthDingtalkRequest.java
@@ -43,7 +43,7 @@ public abstract class AbstractAuthDingtalkRequest extends AuthDefaultRequest {
String code = authToken.getAccessCode();
JSONObject param = new JSONObject();
param.put("tmp_auth_code", code);
- String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), param.toJSONString());
+ String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), param.toJSONString()).getBody();
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/AbstractAuthMicrosoftRequest.java b/src/main/java/me/zhyd/oauth/request/AbstractAuthMicrosoftRequest.java
index f3810e29e83dd680e2024c953259977a0b2992cf..2195d5e6572939cd36369d2392aaf9fe3d7f1197 100644
--- a/src/main/java/me/zhyd/oauth/request/AbstractAuthMicrosoftRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AbstractAuthMicrosoftRequest.java
@@ -53,7 +53,7 @@ public abstract class AbstractAuthMicrosoftRequest extends AuthDefaultRequest {
Map form = MapUtil.parseStringToMap(accessTokenUrl, false);
- String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
@@ -87,7 +87,7 @@ public abstract class AbstractAuthMicrosoftRequest extends AuthDefaultRequest {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Authorization", jwt);
- String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
+ String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false).getBody();
JSONObject object = JSONObject.parseObject(userInfo);
this.checkResponse(object);
return AuthUser.builder()
diff --git a/src/main/java/me/zhyd/oauth/request/AbstractAuthWeChatEnterpriseRequest.java b/src/main/java/me/zhyd/oauth/request/AbstractAuthWeChatEnterpriseRequest.java
index dfce4523458f19ec5d7507b7e0084f48d8976a63..16ff639abcb9adddeab94f2432c0a06a6e27d100 100644
--- a/src/main/java/me/zhyd/oauth/request/AbstractAuthWeChatEnterpriseRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AbstractAuthWeChatEnterpriseRequest.java
@@ -130,7 +130,7 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
.queryParam("access_token", accessToken)
.queryParam("userid", userId)
.build();
- return new HttpUtils(config.getHttpConfig()).get(userDetailUrl);
+ return new HttpUtils(config.getHttpConfig()).get(userDetailUrl).getBody();
}
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthAmazonRequest.java b/src/main/java/me/zhyd/oauth/request/AuthAmazonRequest.java
index bd91e0b42164fbaf975f6d3411d6a7633260aebc..99652cb255c3a56b9f25d72b5f3227bfa05a53e1 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthAmazonRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthAmazonRequest.java
@@ -111,7 +111,7 @@ public class AuthAmazonRequest extends AuthDefaultRequest {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Host", "api.amazon.com");
httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded;charset=UTF-8");
- String response = new HttpUtils(config.getHttpConfig()).post(url, param, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(url, param, httpHeader, false).getBody();
JSONObject jsonObject = JSONObject.parseObject(response);
this.checkResponse(jsonObject);
return AuthToken.builder()
@@ -147,7 +147,7 @@ public class AuthAmazonRequest extends AuthDefaultRequest {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Host", "api.amazon.com");
httpHeader.add("Authorization", "bearer " + accessToken);
- String userInfo = new HttpUtils(config.getHttpConfig()).get(this.source.userInfo(), new HashMap<>(0), httpHeader, false);
+ String userInfo = new HttpUtils(config.getHttpConfig()).get(this.source.userInfo(), new HashMap<>(0), httpHeader, false).getBody();
JSONObject jsonObject = JSONObject.parseObject(userInfo);
this.checkResponse(jsonObject);
@@ -164,7 +164,7 @@ public class AuthAmazonRequest extends AuthDefaultRequest {
}
private void checkToken(String accessToken) {
- String tokenInfo = new HttpUtils(config.getHttpConfig()).get("https://api.amazon.com/auth/o2/tokeninfo?access_token=" + UrlUtil.urlEncode(accessToken));
+ String tokenInfo = new HttpUtils(config.getHttpConfig()).get("https://api.amazon.com/auth/o2/tokeninfo?access_token=" + UrlUtil.urlEncode(accessToken)).getBody();
JSONObject jsonObject = JSONObject.parseObject(tokenInfo);
if (!config.getClientId().equals(jsonObject.getString("aud"))) {
throw new AuthException(AuthResponseStatus.ILLEGAL_TOKEN);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java b/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
index 30b9967434dbc02b8c787920decb02e3829b2918..99be903b296f780d1c0e74cb613dcd3d73ebc981 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
@@ -88,7 +88,7 @@ public class AuthBaiduRequest extends AuthDefaultRequest {
.queryParam("client_id", this.config.getClientId())
.queryParam("client_secret", this.config.getClientSecret())
.build();
- String response = new HttpUtils(config.getHttpConfig()).get(refreshUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(refreshUrl).getBody();
return AuthResponse.builder()
.code(AuthResponseStatus.SUCCESS.getCode())
.data(this.getAuthToken(response))
diff --git a/src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java b/src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
index 8a949faee054902ede6c84d93a25e31a06fd5c5d..8c0b4d85ab5174759826d7d57a563e864da702c9 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthDefaultRequest.java
@@ -211,7 +211,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
* @return Response
*/
protected String doPostAuthorizationCode(String code) {
- return new HttpUtils(config.getHttpConfig()).post(accessTokenUrl(code));
+ return new HttpUtils(config.getHttpConfig()).post(accessTokenUrl(code)).getBody();
}
/**
@@ -221,7 +221,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
* @return Response
*/
protected String doGetAuthorizationCode(String code) {
- return new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(code));
+ return new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(code)).getBody();
}
/**
@@ -232,7 +232,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
*/
@Deprecated
protected String doPostUserInfo(AuthToken authToken) {
- return new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken));
+ return new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken)).getBody();
}
/**
@@ -242,7 +242,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
* @return Response
*/
protected String doGetUserInfo(AuthToken authToken) {
- return new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken));
+ return new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken)).getBody();
}
/**
@@ -253,7 +253,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
*/
@Deprecated
protected String doPostRevoke(AuthToken authToken) {
- return new HttpUtils(config.getHttpConfig()).post(revokeUrl(authToken));
+ return new HttpUtils(config.getHttpConfig()).post(revokeUrl(authToken)).getBody();
}
/**
@@ -263,7 +263,7 @@ public abstract class AuthDefaultRequest implements AuthRequest {
* @return Response
*/
protected String doGetRevoke(AuthToken authToken) {
- return new HttpUtils(config.getHttpConfig()).get(revokeUrl(authToken));
+ return new HttpUtils(config.getHttpConfig()).get(revokeUrl(authToken)).getBody();
}
/**
diff --git a/src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java b/src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
index d46563518ae5dc008a78d7ce5b4e5cd4dedcb088..fcd7485ad1dea62a0f890fb45e54f07058d0dbc7 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
@@ -87,7 +87,7 @@ public class AuthDouyinRequest extends AuthDefaultRequest {
* @return token对象
*/
private AuthToken getToken(String accessTokenUrl) {
- String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl);
+ String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl).getBody();
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 64715919e09b941195979e1a68365945fac6c856..701101142c644765d61986bc937ca4cb780fe4be 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java
@@ -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 = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false).getBody();
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 = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), JSONObject.toJSONString(paramsMap), httpHeader);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), JSONObject.toJSONString(paramsMap), httpHeader).getBody();
JSONObject object = JSONObject.parseObject(response);
@@ -123,7 +123,7 @@ public class AuthElemeRequest extends AuthDefaultRequest {
form.put("grant_type", "refresh_token");
HttpHeader httpHeader = this.buildHeader(CONTENT_TYPE_FORM, this.getRequestId(), true);
- String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, httpHeader, false).getBody();
JSONObject object = JSONObject.parseObject(response);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java b/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
index cc77eb6b89fc66f01f1c4d91b876f74fdf927887..2023162819b4f4bf8da4de963b1c5b288b502031 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
@@ -52,7 +52,7 @@ public class AuthGithubRequest extends AuthDefaultRequest {
protected AuthUser getUserInfo(AuthToken authToken) {
HttpHeader header = new HttpHeader();
header.add("Authorization", "token " + authToken.getAccessToken());
- String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl(source.userInfo()).build(), null, header, false);
+ String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl(source.userInfo()).build(), null, header, false).getBody();
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object.containsKey("error"), object.getString("error_description"));
diff --git a/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java b/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
index 4139b626d6c31a95fbdf94e6e0c4ef2605d6d92c..04d7493b2f40fbb55e09981f8ba3ddad48c89a37 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
@@ -50,7 +50,7 @@ public class AuthGoogleRequest extends AuthDefaultRequest {
protected AuthUser getUserInfo(AuthToken authToken) {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Authorization", "Bearer " + authToken.getAccessToken());
- String userInfo = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, httpHeader);
+ String userInfo = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, httpHeader).getBody();
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 4a9c31bafbd5d682e38775fb7beb6dbe7eb44532..e2e9067efa8ded0be73ae2b44fbfde6f3a540f2f 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java
@@ -54,7 +54,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
form.put("client_secret", config.getClientSecret());
form.put("redirect_uri", config.getRedirectUri());
- String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false).getBody();
return getAuthToken(response);
}
@@ -73,7 +73,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
form.put("nsp_fmt", "JS");
form.put("nsp_svc", "OpenUP.User.getInfo");
- String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false).getBody();
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -106,7 +106,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
form.put("refresh_token", authToken.getRefreshToken());
form.put("grant_type", "refresh_token");
- String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false).getBody();
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 265d23c9b136a139e6301d8ecf33db6ee4292b2e..bb543751a7bd49d53200b8d47c7ff9e8e9169509 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthJdRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthJdRequest.java
@@ -46,7 +46,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 = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false).getBody();
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -70,7 +70,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 = new HttpUtils(config.getHttpConfig()).post(urlBuilder.build(true));
+ String response = new HttpUtils(config.getHttpConfig()).post(urlBuilder.build(true)).getBody();
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -109,7 +109,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 = new HttpUtils(config.getHttpConfig()).post(source.refresh(), params, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), params, false).getBody();
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 2392e70a880a5c18613290262b23f76b2aa9fcfa..aac5ec147cbb973b88d2e645d733d2c9cbf61457 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
@@ -76,7 +76,7 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl(source.userInfo())
.queryParam("access_token", authToken.getAccessToken())
.queryParam("open_id", openId)
- .build());
+ .build()).getBody();
JSONObject object = JSONObject.parseObject(response);
if (!"0".equals(object.getString("c"))) {
throw new AuthException(object.getString("m"));
@@ -103,14 +103,14 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
private String getOpenId(AuthToken authToken) {
String response = new HttpUtils(config.getHttpConfig()).get(UrlBuilder.fromBaseUrl("https://oauth.kujiale.com/oauth2/auth/user")
.queryParam("access_token", authToken.getAccessToken())
- .build());
+ .build()).getBody();
JSONObject accessTokenObject = checkResponse(response);
return accessTokenObject.getString("d");
}
@Override
public AuthResponse refresh(AuthToken authToken) {
- String response = new HttpUtils(config.getHttpConfig()).post(refreshTokenUrl(authToken.getRefreshToken()));
+ String response = new HttpUtils(config.getHttpConfig()).post(refreshTokenUrl(authToken.getRefreshToken())).getBody();
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(getAuthToken(response)).build();
}
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthLineRequest.java b/src/main/java/me/zhyd/oauth/request/AuthLineRequest.java
index 7cbb2e82fcd279c62859e7c6d612aac6940f0ced..18db7a845bf20a7f8e0fd849acde6e38707fe70b 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthLineRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthLineRequest.java
@@ -43,7 +43,7 @@ public class AuthLineRequest extends AuthDefaultRequest {
params.put("redirect_uri", config.getRedirectUri());
params.put("client_id", config.getClientId());
params.put("client_secret", config.getClientSecret());
- String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
return AuthToken.builder()
.accessToken(accessTokenObject.getString("access_token"))
@@ -59,7 +59,7 @@ public class AuthLineRequest extends AuthDefaultRequest {
protected AuthUser getUserInfo(AuthToken authToken) {
String userInfo = new HttpUtils(config.getHttpConfig()).get(source.userInfo(), null, new HttpHeader()
.add("Content-Type", "application/x-www-form-urlencoded")
- .add("Authorization", "Bearer ".concat(authToken.getAccessToken())), false);
+ .add("Authorization", "Bearer ".concat(authToken.getAccessToken())), false).getBody();
JSONObject object = JSONObject.parseObject(userInfo);
return AuthUser.builder()
.rawUserInfo(object)
@@ -80,7 +80,7 @@ public class AuthLineRequest extends AuthDefaultRequest {
params.put("access_token", authToken.getAccessToken());
params.put("client_id", config.getClientId());
params.put("client_secret", config.getClientSecret());
- String userInfo = new HttpUtils(config.getHttpConfig()).post(source.revoke(), params, false);
+ String userInfo = new HttpUtils(config.getHttpConfig()).post(source.revoke(), params, false).getBody();
JSONObject object = JSONObject.parseObject(userInfo);
// 返回1表示取消授权成功,否则失败
AuthResponseStatus status = object.getBooleanValue("revoked") ? AuthResponseStatus.SUCCESS : AuthResponseStatus.FAILURE;
@@ -94,7 +94,7 @@ public class AuthLineRequest extends AuthDefaultRequest {
params.put("refresh_token", oldToken.getRefreshToken());
params.put("client_id", config.getClientId());
params.put("client_secret", config.getClientSecret());
- String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), params, false).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
return AuthResponse.builder()
.code(AuthResponseStatus.SUCCESS.getCode())
diff --git a/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java b/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
index 9773fecbf36c9b0f0330e672eed6dcd54602bfdd..40598c85c9523bb8a9557d1a80193ee815c74828 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
@@ -48,7 +48,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
httpHeader.add("Connection", "Keep-Alive");
httpHeader.add("Authorization", "Bearer " + accessToken);
- String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false).getBody();
JSONObject userInfoObject = JSONObject.parseObject(response);
this.checkResponse(userInfoObject);
@@ -138,7 +138,9 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
httpHeader.add("Connection", "Keep-Alive");
httpHeader.add("Authorization", "Bearer " + accessToken);
- String emailResponse = new HttpUtils(config.getHttpConfig()).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)
+ .getBody();
JSONObject emailObj = JSONObject.parseObject(emailResponse);
this.checkResponse(emailObj);
@@ -178,7 +180,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
httpHeader.add("Host", "www.linkedin.com");
httpHeader.add(Constants.CONTENT_TYPE, "application/x-www-form-urlencoded");
- String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, null, httpHeader);
+ String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, null, httpHeader).getBody();
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 4f58a8d29f813eba3d52baebe92c0f03ca06801e..63b64b40e718435e4e8023e7ea3a0b968fdd9bc5 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthMeituanRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthMeituanRequest.java
@@ -41,7 +41,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
form.put("code", authCallback.getCode());
form.put("grant_type", "authorization_code");
- String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false).getBody();
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 = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.userInfo(), form, false).getBody();
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -85,7 +85,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
form.put("refresh_token", oldToken.getRefreshToken());
form.put("grant_type", "refresh_token");
- String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false).getBody();
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 6abe1e12ff559042e5ccdeb0aef4954fa90b989f..7d473ca101467f84a087ac4e57b9964af1d03f4c 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
@@ -43,7 +43,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
}
private AuthToken getToken(String accessTokenUrl) {
- String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl).getBody();
String jsonStr = response.replace(PREFIX, Constants.EMPTY);
JSONObject accessTokenObject = JSONObject.parseObject(jsonStr);
@@ -91,7 +91,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 = new HttpUtils(config.getHttpConfig()).get(emailPhoneUrl);
+ String emailResponse = new HttpUtils(config.getHttpConfig()).get(emailPhoneUrl).getBody();
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/AuthOktaRequest.java b/src/main/java/me/zhyd/oauth/request/AuthOktaRequest.java
index 7c1e8101e0e0631bdf01785a862a8c6807472724..5f35430f8f017acf19be7c06a26d86c320d84f9d 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthOktaRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthOktaRequest.java
@@ -50,7 +50,7 @@ public class AuthOktaRequest extends AuthDefaultRequest {
.add("accept", "application/json")
.add("content-type", "application/x-www-form-urlencoded")
.add("Authorization", "Basic " + Base64Utils.encode(config.getClientId().concat(":").concat(config.getClientSecret())));
- String response = new HttpUtils(config.getHttpConfig()).post(tokenUrl, null, header, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(tokenUrl, null, header, false).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
return AuthToken.builder()
@@ -82,7 +82,7 @@ public class AuthOktaRequest extends AuthDefaultRequest {
protected AuthUser getUserInfo(AuthToken authToken) {
HttpHeader header = new HttpHeader()
.add("Authorization", "Bearer " + authToken.getAccessToken());
- String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, header, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(userInfoUrl(authToken), null, header, false).getBody();
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
JSONObject address = object.getJSONObject("address");
diff --git a/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java b/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
index 75928df3870e674c8aa3008d2e0ebcea2e500f32..989587694863e0ea1938489922ccfbd81fdcfe34 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
@@ -50,7 +50,7 @@ public class AuthPinterestRequest extends AuthDefaultRequest {
protected AuthUser getUserInfo(AuthToken authToken) {
String userinfoUrl = userInfoUrl(authToken);
// TODO: 是否需要 .setFollowRedirects(true)
- String response = new HttpUtils(config.getHttpConfig()).get(userinfoUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(userinfoUrl).getBody();
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
JSONObject userObj = object.getJSONObject("data");
diff --git a/src/main/java/me/zhyd/oauth/request/AuthProginnRequest.java b/src/main/java/me/zhyd/oauth/request/AuthProginnRequest.java
index 1fcd0acaf65ca9a90ecdcdf744ae22113c7884ac..03a56be82c23f796880b7028787bf4037c4570f1 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthProginnRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthProginnRequest.java
@@ -41,7 +41,7 @@ public class AuthProginnRequest extends AuthDefaultRequest {
params.put("client_secret", config.getClientSecret());
params.put("grant_type", "authorization_code");
params.put("redirect_uri", config.getRedirectUri());
- String response = new HttpUtils(config.getHttpConfig()).post(AuthDefaultSource.PROGINN.accessToken(), params, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(AuthDefaultSource.PROGINN.accessToken(), params, false).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
return AuthToken.builder()
diff --git a/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java b/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
index 0882c641a259bec4c3fe4ee4531991832c7825ae..c750695163df8a06df48dc39462105d523d60352 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
@@ -40,7 +40,7 @@ public class AuthQqRequest extends AuthDefaultRequest {
@Override
public AuthResponse refresh(AuthToken authToken) {
- String response = new HttpUtils(config.getHttpConfig()).get(refreshTokenUrl(authToken.getRefreshToken()));
+ String response = new HttpUtils(config.getHttpConfig()).get(refreshTokenUrl(authToken.getRefreshToken())).getBody();
return AuthResponse.builder().code(AuthResponseStatus.SUCCESS.getCode()).data(getAuthToken(response)).build();
}
@@ -82,7 +82,7 @@ public class AuthQqRequest extends AuthDefaultRequest {
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());
+ .build()).getBody();
String removePrefix = response.replace("callback(", "");
String removeSuffix = removePrefix.replace(");", "");
String openId = removeSuffix.trim();
diff --git a/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java b/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
index f2a337fc2b01922f7795e74085497f051ee7dafa..2de6cc5eebf8b8864acb7a541250fbc24ff30a07 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
@@ -68,7 +68,7 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
}
private AuthToken getToken(String url) {
- String response = new HttpUtils(config.getHttpConfig()).post(url);
+ String response = new HttpUtils(config.getHttpConfig()).post(url).getBody();
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/AuthSlackRequest.java b/src/main/java/me/zhyd/oauth/request/AuthSlackRequest.java
index e48b20bbcb5732db406d7f4b898700ea7a0c2367..b1e1e30ada42146619587ac1104c72f573921f01 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthSlackRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthSlackRequest.java
@@ -38,7 +38,8 @@ public class AuthSlackRequest extends AuthDefaultRequest {
protected AuthToken getAccessToken(AuthCallback authCallback) {
HttpHeader header = new HttpHeader()
.add("Content-Type", "application/x-www-form-urlencoded");
- String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl(authCallback.getCode()), null, header, false);
+ String response = new HttpUtils(config.getHttpConfig())
+ .get(accessTokenUrl(authCallback.getCode()), null, header, false).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
return AuthToken.builder()
@@ -54,7 +55,8 @@ public class AuthSlackRequest extends AuthDefaultRequest {
HttpHeader header = new HttpHeader()
.add("Content-Type", "application/x-www-form-urlencoded")
.add("Authorization", "Bearer ".concat(authToken.getAccessToken()));
- String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, header, false);
+ String userInfo = new HttpUtils(config.getHttpConfig())
+ .get(userInfoUrl(authToken), null, header, false).getBody();
JSONObject object = JSONObject.parseObject(userInfo);
this.checkResponse(object);
JSONObject user = object.getJSONObject("user");
@@ -77,7 +79,8 @@ public class AuthSlackRequest extends AuthDefaultRequest {
HttpHeader header = new HttpHeader()
.add("Content-Type", "application/x-www-form-urlencoded")
.add("Authorization", "Bearer ".concat(authToken.getAccessToken()));
- String userInfo = new HttpUtils(config.getHttpConfig()).get(source.revoke(), null, header, false);
+ String userInfo = new HttpUtils(config.getHttpConfig())
+ .get(source.revoke(), null, header, false).getBody();
JSONObject object = JSONObject.parseObject(userInfo);
this.checkResponse(object);
// 返回1表示取消授权成功,否则失败
diff --git a/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java b/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
index e8f8c3e83ef0026c4ff2cda12bf2c0fd61ef5b93..969b45646ceabfe6155474f38b8f2bbf80209567 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
@@ -42,7 +42,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 = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(accessTokenUrl, form, httpHeader, false).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
@@ -60,7 +60,7 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest {
.queryParam("site", "stackoverflow")
.queryParam("key", this.config.getStackOverflowKey())
.build();
- String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl).getBody();
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/AuthTaobaoRequest.java b/src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
index dc65a5496e69a5469726f409f7da2c6fa345af3d..f1df52beda580f68bc7790452935d3c80ee717b2 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
@@ -81,7 +81,7 @@ public class AuthTaobaoRequest extends AuthDefaultRequest {
@Override
public AuthResponse refresh(AuthToken oldToken) {
String tokenUrl = refreshTokenUrl(oldToken.getRefreshToken());
- String response = new HttpUtils(config.getHttpConfig()).post(tokenUrl);
+ String response = new HttpUtils(config.getHttpConfig()).post(tokenUrl).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
return AuthResponse.builder()
.code(AuthResponseStatus.SUCCESS.getCode())
diff --git a/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java b/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
index 63da04a06217ab113c9d14a6d027955b9b982a33..d5293796e626ea8de10a3895a624e322d8543e86 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
@@ -45,7 +45,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
form.put("code", authCallback.getCode());
form.put("grant_type", "code");
- String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, false).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
@@ -63,7 +63,8 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Authorization", "OAuth2 " + accessToken);
- String response = new HttpUtils(config.getHttpConfig()).get(source.userInfo(), null, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig())
+ .get(source.userInfo(), null, httpHeader, false).getBody();
JSONObject object = JSONObject.parseObject(response);
this.checkResponse(object);
@@ -93,7 +94,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
Map form = new HashMap<>(4);
form.put("_userId", uid);
form.put("refresh_token", refreshToken);
- String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.refresh(), form, false).getBody();
JSONObject refreshTokenObject = JSONObject.parseObject(response);
this.checkResponse(refreshTokenObject);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java b/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java
index 5968a077aee05659c58db2f1fbbf78a745cf79a5..3ef9403082a993d327a9df580ad32beedac98992 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthTwitterRequest.java
@@ -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 = new HttpUtils(config.getHttpConfig()).post(baseUrl, null, httpHeader);
+ String requestToken = new HttpUtils(config.getHttpConfig()).post(baseUrl, null, httpHeader).getBody();
Map res = MapUtil.parseStringToMap(requestToken, false);
@@ -104,7 +104,7 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
Map form = new HashMap<>(3);
form.put("oauth_verifier", authCallback.getOauth_verifier());
- String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig()).post(source.accessToken(), form, httpHeader, false).getBody();
Map requestToken = MapUtil.parseStringToMap(response, false);
@@ -132,7 +132,8 @@ public class AuthTwitterRequest extends AuthDefaultRequest {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Authorization", header);
- String response = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
+ String response = new HttpUtils(config.getHttpConfig())
+ .get(userInfoUrl(authToken), null, httpHeader, false).getBody();
JSONObject userInfo = JSONObject.parseObject(response);
return AuthUser.builder()
diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseThirdQrcodeRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseThirdQrcodeRequest.java
index 4715bb88bdb4133fc099bc5dbd3921b7f70f9b95..ed2519658e754976ed0b2091aa0ae6d998c1bb2e 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseThirdQrcodeRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseThirdQrcodeRequest.java
@@ -75,7 +75,7 @@ public class AuthWeChatEnterpriseThirdQrcodeRequest extends AbstractAuthWeChatEn
JSONObject data = new JSONObject();
data.put("corpid", config.getClientId());
data.put("provider_secret", config.getClientSecret());
- return new HttpUtils(config.getHttpConfig()).post(accessTokenUrl(code), data.toJSONString());
+ return new HttpUtils(config.getHttpConfig()).post(accessTokenUrl(code), data.toJSONString()).getBody();
}
/**
@@ -96,13 +96,15 @@ public class AuthWeChatEnterpriseThirdQrcodeRequest extends AbstractAuthWeChatEn
.build();
}
+ @Override
protected String doGetUserInfo(AuthToken authToken) {
JSONObject data = new JSONObject();
data.put("auth_code", authToken.getCode());
return new HttpUtils(config.getHttpConfig())
- .post(userInfoUrl(authToken), data.toJSONString());
+ .post(userInfoUrl(authToken), data.toJSONString()).getBody();
}
+ @Override
protected String userInfoUrl(AuthToken authToken) {
return UrlBuilder.fromBaseUrl(source.userInfo())
.queryParam("access_token", authToken.getAccessToken()).
diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java
index 2a9f2cfde0f38359076c27e84a5737782aadb1c2..94fcba8bc4dcfa43d3277593d24d39d12bb28da7 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java
@@ -97,7 +97,7 @@ public class AuthWeChatMpRequest extends AuthDefaultRequest {
* @return token对象
*/
private AuthToken getToken(String accessTokenUrl) {
- String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl).getBody();
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 bc8a26363cf88a9f92b0d4d1dcdd94c18c8b2e1d..7198887d8ec5e49c327b8d054c4802ea3962c39c 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeChatOpenRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeChatOpenRequest.java
@@ -94,7 +94,7 @@ public class AuthWeChatOpenRequest extends AuthDefaultRequest {
* @return token对象
*/
private AuthToken getToken(String accessTokenUrl) {
- String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl);
+ String response = new HttpUtils(config.getHttpConfig()).get(accessTokenUrl).getBody();
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 313a844ca58f54ed19edb0b387c0ef36ca717f2f..5f6024aaeef5c5898eac0e5e45a960e5ac07289e 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
@@ -56,7 +56,8 @@ public class AuthWeiboRequest extends AuthDefaultRequest {
HttpHeader httpHeader = new HttpHeader();
httpHeader.add("Authorization", "OAuth2 " + oauthParam);
httpHeader.add("API-RemoteIP", IpUtils.getLocalIp());
- String userInfo = new HttpUtils(config.getHttpConfig()).get(userInfoUrl(authToken), null, httpHeader, false);
+ String userInfo = new HttpUtils(config.getHttpConfig())
+ .get(userInfoUrl(authToken), null, httpHeader, false).getBody();
JSONObject object = JSONObject.parseObject(userInfo);
if (object.containsKey("error")) {
throw new AuthException(object.getString("error"));
diff --git a/src/main/java/me/zhyd/oauth/request/AuthXmlyRequest.java b/src/main/java/me/zhyd/oauth/request/AuthXmlyRequest.java
index 023375dcde4e341308056cb9d032b025bb1dc829..2430aa21ae4a2c7ad2ec88e55501da7b5e77fe43 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthXmlyRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthXmlyRequest.java
@@ -50,7 +50,7 @@ public class AuthXmlyRequest extends AuthDefaultRequest {
map.put("device_id", config.getDeviceId());
map.put("grant_type", "authorization_code");
map.put("redirect_uri", config.getRedirectUri());
- String response = HttpUtil.post(source.accessToken(), map, true);
+ String response = HttpUtil.post(source.accessToken(), map, true).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
this.checkResponse(accessTokenObject);
@@ -97,7 +97,7 @@ public class AuthXmlyRequest extends AuthDefaultRequest {
map.put("pack_id", config.getPackId());
map.put("access_token", authToken.getAccessToken());
map.put("sig", GlobalAuthUtils.generateXmlySignature(map, config.getClientSecret()));
- String rawUserInfo = HttpUtil.get(source.userInfo(), map, false);
+ String rawUserInfo = HttpUtil.get(source.userInfo(), map, false).getBody();
JSONObject object = JSONObject.parseObject(rawUserInfo);
checkResponse(object);
return AuthUser.builder()
diff --git a/src/main/java/me/zhyd/oauth/utils/HttpUtils.java b/src/main/java/me/zhyd/oauth/utils/HttpUtils.java
index f5414908e58c0b8dc0f83c01e8f148adfc13b143..426b61e5c2fe1608835809a17eed22c091e1ed91 100644
--- a/src/main/java/me/zhyd/oauth/utils/HttpUtils.java
+++ b/src/main/java/me/zhyd/oauth/utils/HttpUtils.java
@@ -3,17 +3,22 @@ package me.zhyd.oauth.utils;
import com.xkcoding.http.HttpUtil;
import com.xkcoding.http.config.HttpConfig;
import com.xkcoding.http.support.HttpHeader;
+import com.xkcoding.http.support.SimpleHttpResponse;
+import me.zhyd.oauth.exception.AuthException;
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 {
+ private SimpleHttpResponse httpResponse;
+
public HttpUtils(HttpConfig config) {
HttpUtil.setConfig(config);
}
@@ -26,10 +31,11 @@ public class HttpUtils {
* GET 请求
*
* @param url URL
- * @return 结果
+ * @return HttpUtils
*/
- public String get(String url) {
- return HttpUtil.get(url);
+ public HttpUtils get(String url) {
+ this.httpResponse = HttpUtil.get(url, null, null, false);
+ return this;
}
/**
@@ -39,20 +45,22 @@ public class HttpUtils {
* @param params 参数
* @param header 请求头
* @param encode 是否需要 url encode
- * @return 结果
+ * @return HttpUtils
*/
- public String get(String url, Map params, HttpHeader header, boolean encode) {
- return HttpUtil.get(url, params, header, encode);
+ public HttpUtils get(String url, Map params, HttpHeader header, boolean encode) {
+ this.httpResponse = HttpUtil.get(url, params, header, encode);
+ return this;
}
/**
* POST 请求
*
* @param url URL
- * @return 结果
+ * @return HttpUtils
*/
- public String post(String url) {
- return HttpUtil.post(url);
+ public HttpUtils post(String url) {
+ this.httpResponse = HttpUtil.post(url);
+ return this;
}
/**
@@ -60,10 +68,11 @@ public class HttpUtils {
*
* @param url URL
* @param data JSON 参数
- * @return 结果
+ * @return HttpUtils
*/
- public String post(String url, String data) {
- return HttpUtil.post(url, data);
+ public HttpUtils post(String url, String data) {
+ this.httpResponse = HttpUtil.post(url, data);
+ return this;
}
/**
@@ -72,10 +81,11 @@ public class HttpUtils {
* @param url URL
* @param data JSON 参数
* @param header 请求头
- * @return 结果
+ * @return HttpUtils
*/
- public String post(String url, String data, HttpHeader header) {
- return HttpUtil.post(url, data, header);
+ public HttpUtils post(String url, String data, HttpHeader header) {
+ this.httpResponse = HttpUtil.post(url, data, header);
+ return this;
}
/**
@@ -84,10 +94,11 @@ public class HttpUtils {
* @param url URL
* @param params form 参数
* @param encode 是否需要 url encode
- * @return 结果
+ * @return HttpUtils
*/
- public String post(String url, Map params, boolean encode) {
- return HttpUtil.post(url, params, encode);
+ public HttpUtils post(String url, Map params, boolean encode) {
+ this.httpResponse = HttpUtil.post(url, params, encode);
+ return this;
}
/**
@@ -97,9 +108,28 @@ public class HttpUtils {
* @param params form 参数
* @param header 请求头
* @param encode 是否需要 url encode
- * @return 结果
+ * @return HttpUtils
*/
- public String post(String url, Map params, HttpHeader header, boolean encode) {
- return HttpUtil.post(url, params, header, encode);
+ public HttpUtils post(String url, Map params, HttpHeader header, boolean encode) {
+ this.httpResponse = HttpUtil.post(url, params, header, encode);
+ return this;
+ }
+
+ private HttpUtils check() {
+ if (null == httpResponse) {
+ throw new AuthException("Invalid SimpleHttpResponse.");
+ }
+ if (!httpResponse.isSuccess()) {
+ throw new AuthException(httpResponse.getError());
+ }
+ return this;
+ }
+
+ public String getBody() {
+ return this.check().getHttpResponse().getBody();
+ }
+
+ public SimpleHttpResponse getHttpResponse() {
+ return httpResponse;
}
}