diff --git a/README.md b/README.md
index dd4fc4b82093302b941d54573ead327b9867d638..7e2576b7b70bdb57ddfcd4fd1af7a9a06901528e 100644
--- a/README.md
+++ b/README.md
@@ -168,6 +168,17 @@ authRequest.login("code");
待续
+# 交流
+
+| 微信(备注:加群) | 公众号 |
+| :------------: | :------------: |
+|
|
|
+
+ **QQ群**
+
+[![](https://images.gitee.com/uploads/images/2019/0129/191256_a40bceba_784199.png)](https://shang.qq.com/wpa/qunwpa?idkey=3571c554a143eff1e15807de033a240196c6b493b25b903d1d37571cfb6040aa)
+
+
## 请喝咖啡
| 支付宝 | 微信 |
diff --git a/src/main/java/me/zhyd/oauth/model/AuthToken.java b/src/main/java/me/zhyd/oauth/model/AuthToken.java
index febb4c3358ad44cf66030e9e8e47e44882948b14..88ad0f38135fbf46fba820844db9e5b766b1bb61 100644
--- a/src/main/java/me/zhyd/oauth/model/AuthToken.java
+++ b/src/main/java/me/zhyd/oauth/model/AuthToken.java
@@ -15,4 +15,9 @@ public class AuthToken {
private String expireIn;
private String refreshToken;
private String uid;
+ private String openId;
+ /**
+ * 针对钉钉
+ */
+ private String accessCode;
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java b/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
index d1a57633c83a2ff64c962ae5168aaa43d4be9d40..d9ce1458740eea28866441a123143a27b684cb6e 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
@@ -11,6 +11,7 @@ import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.consts.ApiUrl;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.utils.StringUtils;
@@ -32,7 +33,7 @@ public class AuthAlipayRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
+ protected AuthToken getAccessToken(String code) {
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
request.setGrantType("authorization_code");
request.setCode(code);
@@ -45,11 +46,14 @@ public class AuthAlipayRequest extends BaseAuthRequest {
if (!response.isSuccess()) {
throw new AuthException(response.getSubMsg());
}
- return response.getAccessToken();
+ return AuthToken.builder()
+ .accessToken(response.getAccessToken())
+ .build();
}
@Override
- protected AuthUser getUserInfo(String accessToken) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest();
AlipayUserInfoShareResponse response = null;
try {
diff --git a/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java b/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
index 204278af86b9aca382ec310da00aa977ab5863c0..79299c6d07c882fd0978f3179ac9bd10bbb778f0 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
@@ -22,7 +22,7 @@ public class AuthBaiduRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
+ protected AuthToken getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getBaiduAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
@@ -30,11 +30,14 @@ public class AuthBaiduRequest extends BaseAuthRequest {
if (!AuthBaiduErrorCode.OK.equals(errorCode)) {
throw new AuthException(errorCode.getDesc());
}
- return accessTokenObject.getString("access_token");
+ return AuthToken.builder()
+ .accessToken(accessTokenObject.getString("access_token"))
+ .build();
}
@Override
- protected AuthUser getUserInfo(String accessToken) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getBaiduUserInfoUrl(accessToken)).execute();
String userInfo = response.body();
JSONObject object = JSONObject.parseObject(userInfo);
@@ -52,7 +55,8 @@ public class AuthBaiduRequest extends BaseAuthRequest {
}
@Override
- public AuthResponse revoke(String accessToken) {
+ public AuthResponse revoke(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getBaiduRevokeUrl(accessToken)).execute();
String userInfo = response.body();
JSONObject object = JSONObject.parseObject(userInfo);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java b/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
index 063e9c8134b475c5e0d1a6f0b63fbc6100183700..6af8bf1e91784f6b67bb6a9c64fb5da31f5864a3 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.utils.UrlBuilder;
@@ -24,18 +25,21 @@ public class AuthCodingRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
+ protected AuthToken getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getCodingAccessTokenUrl(config.getClientId(), config.getClientSecret(), code);
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
if (accessTokenObject.getIntValue("code") != 0) {
throw new AuthException("Unable to get token from coding using code [" + code + "]");
}
- return accessTokenObject.getString("access_token");
+ return AuthToken.builder()
+ .accessToken(accessTokenObject.getString("access_token"))
+ .build();
}
@Override
- protected AuthUser getUserInfo(String accessToken) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getCodingUserInfoUrl(accessToken)).execute();
JSONObject object = JSONObject.parseObject(response.body());
if (object.getIntValue("code") != 0) {
diff --git a/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java b/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
index 1f205c75e32981446e049e3479bd1d455bf7535f..d529e118246626b3d9b2dcad583de2f4d9f8deac 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.UrlBuilder;
@@ -23,18 +24,21 @@ public class AuthCsdnRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
+ protected AuthToken getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getCsdnAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
if (accessTokenObject.containsKey("error_code")) {
throw new AuthException("Unable to get token from csdn using code [" + code + "]");
}
- return accessTokenObject.getString("access_token");
+ return AuthToken.builder()
+ .accessToken(accessTokenObject.getString("access_token"))
+ .build();
}
@Override
- protected AuthUser getUserInfo(String accessToken) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getCsdnUserInfoUrl(accessToken)).execute();
JSONObject object = JSONObject.parseObject(response.body());
if (object.containsKey("error_code")) {
diff --git a/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java b/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
index a35003ce5d6feac244dd126d8d3fbba8c7f98624..a9671e85c58bb073a896cca78654cd02ea8f56cb 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
@@ -6,8 +6,8 @@ import cn.hutool.json.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthDingTalkErrorCode;
-import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.GlobalAuthUtil;
import me.zhyd.oauth.utils.UrlBuilder;
@@ -28,12 +28,15 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
- throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
+ protected AuthToken getAccessToken(String code) {
+ return AuthToken.builder()
+ .accessCode(code)
+ .build();
}
@Override
- protected AuthUser getUserInfo(String code) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String code = authToken.getAccessCode();
// 根据timestamp, appSecret计算签名值
String stringToSign = System.currentTimeMillis() + "";
String urlEncodeSignature = GlobalAuthUtil.generateDingTalkSignature(config.getClientSecret(), stringToSign);
@@ -52,11 +55,4 @@ public class AuthDingTalkRequest extends BaseAuthRequest {
.source(AuthSource.DINGTALK)
.build();
}
-
- @Override
- public AuthResponse login(String code) {
- return AuthResponse.builder()
- .data(this.getUserInfo(code))
- .build();
- }
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java b/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
index 025a70320544c589e229cdd550d9e1e778fca053..557a8e22f69149a64f90707487b7243a41fd4960 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.UrlBuilder;
@@ -23,18 +24,21 @@ public class AuthGiteeRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
+ protected AuthToken getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getGiteeAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
if (accessTokenObject.containsKey("error")) {
throw new AuthException("Unable to get token from gitee using code [" + code + "]");
}
- return accessTokenObject.getString("access_token");
+ return AuthToken.builder()
+ .accessToken(accessTokenObject.getString("access_token"))
+ .build();
}
@Override
- protected AuthUser getUserInfo(String accessToken) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getGiteeUserInfoUrl(accessToken)).execute();
String userInfo = response.body();
JSONObject object = JSONObject.parseObject(userInfo);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java b/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
index 5bed3a00c9bcc9e21b55dba55ffb055e8c477489..3f6b34485033eb3462e161f78d4d4712076e37a7 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.GlobalAuthUtil;
import me.zhyd.oauth.utils.UrlBuilder;
@@ -26,18 +27,21 @@ public class AuthGithubRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
+ protected AuthToken getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
Map res = GlobalAuthUtil.parseStringToMap(response.body());
if (res.containsKey("error")) {
throw new AuthException(res.get("error") + ":" + res.get("error_description"));
}
- return res.get("access_token");
+ return AuthToken.builder()
+ .accessToken(res.get("access_token"))
+ .build();
}
@Override
- protected AuthUser getUserInfo(String accessToken) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getGithubUserInfoUrl(accessToken)).execute();
String userInfo = response.body();
JSONObject object = JSONObject.parseObject(userInfo);
diff --git a/src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java b/src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
index 1cdf67910ace6d2483b7370e706fb46cce4161cb..061310f685146e2f60ab2de6fbe80d3617c57581 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.utils.UrlBuilder;
@@ -24,18 +25,21 @@ public class AuthOschinaRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
+ protected AuthToken getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getOschinaAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
if (accessTokenObject.containsKey("error")) {
throw new AuthException("Unable to get token from oschina using code [" + code + "]");
}
- return accessTokenObject.getString("access_token");
+ return AuthToken.builder()
+ .accessToken(accessTokenObject.getString("access_token"))
+ .build();
}
@Override
- protected AuthUser getUserInfo(String accessToken) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getOschinaUserInfoUrl(accessToken)).execute();
JSONObject object = JSONObject.parseObject(response.body());
if (object.containsKey("error")) {
diff --git a/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java b/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
index 6b470aae0bdaaaf8fe803af36b32324fec41de39..d65a67817b5515cb715deb8e720e529ac0dc9a80 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.utils.StringUtils;
@@ -24,18 +25,21 @@ public class AuthQqRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
+ protected AuthToken getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getQqAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
JSONObject accessTokenObject = JSONObject.parseObject(response.body());
if (!accessTokenObject.containsKey("access_token")) {
throw new AuthException("Unable to get token from qq using code [" + code + "]");
}
- return accessTokenObject.getString("access_token");
+ return AuthToken.builder()
+ .accessToken(accessTokenObject.getString("access_token"))
+ .build();
}
@Override
- protected AuthUser getUserInfo(String accessToken) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
String openId = this.getOpenId(accessToken);
HttpResponse response = HttpRequest.get(UrlBuilder.getQqUserInfoUrl(accessToken, openId)).execute();
JSONObject object = JSONObject.parseObject(response.body());
diff --git a/src/main/java/me/zhyd/oauth/request/AuthRequest.java b/src/main/java/me/zhyd/oauth/request/AuthRequest.java
index bef6ce2c2426902fcb924a8171eec30c17b3fe99..38f3dd54debf3f67e275fcc288c0c4949e6f86c1 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthRequest.java
@@ -2,6 +2,7 @@ package me.zhyd.oauth.request;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponse;
+import me.zhyd.oauth.model.AuthToken;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
@@ -32,20 +33,20 @@ public interface AuthRequest {
/**
* 撤销授权
*
- * @param accessToken 登录成功后返回的accessToken
+ * @param authToken 登录成功后返回的Token信息
* @return AuthResponse
*/
- default AuthResponse revoke(String accessToken) {
+ default AuthResponse revoke(AuthToken authToken) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
}
/**
* 刷新access token (续期)
*
- * @param accessToken 登录成功后返回的accessToken
+ * @param authToken 登录成功后返回的Token信息
* @return AuthResponse
*/
- default AuthResponse refresh(String accessToken) {
+ default AuthResponse refresh(AuthToken authToken) {
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
}
}
diff --git a/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java b/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
index 1a6370cbea6588bd3af0a49f9f5edd90eaccf648..ef3d99e1eaec1880bc7fa196424bb182379ec4cd 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.utils.UrlBuilder;
@@ -24,18 +25,21 @@ public class AuthTencentCloudRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
+ protected AuthToken getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getTencentCloudAccessTokenUrl(config.getClientId(), config.getClientSecret(), code);
HttpResponse response = HttpRequest.get(accessTokenUrl).execute();
JSONObject object = JSONObject.parseObject(response.body());
if (object.getIntValue("code") != 0) {
throw new AuthException("Unable to get token from tencent cloud using code [" + code + "]: " + object.get("msg"));
}
- return object.getString("access_token");
+ return AuthToken.builder()
+ .accessToken(object.getString("access_token"))
+ .build();
}
@Override
- protected AuthUser getUserInfo(String accessToken) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getTencentCloudUserInfoUrl(accessToken)).execute();
JSONObject object = JSONObject.parseObject(response.body());
if (object.getIntValue("code") != 0) {
diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
index 1f120e4f58c542c2c9ec10e4c74990c6bb0e4c94..12d51a2d9dfc9c4a27a8a74f00dbbf5edd648555 100644
--- a/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.model.AuthUserGender;
import me.zhyd.oauth.utils.GlobalAuthUtil;
@@ -28,7 +29,7 @@ public class AuthWeiboRequest extends BaseAuthRequest {
}
@Override
- protected String getAccessToken(String code) {
+ protected AuthToken getAccessToken(String code) {
String accessTokenUrl = UrlBuilder.getWeiboAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
String accessTokenStr = response.body();
@@ -38,11 +39,14 @@ public class AuthWeiboRequest extends BaseAuthRequest {
}
String accessToken = accessTokenObject.getString("access_token");
String uid = accessTokenObject.getString("uid");
- return String.format("uid=%s&access_token=%s", uid, accessToken);
+ return AuthToken.builder()
+ .accessToken(String.format("uid=%s&access_token=%s", uid, accessToken))
+ .build();
}
@Override
- protected AuthUser getUserInfo(String accessToken) {
+ protected AuthUser getUserInfo(AuthToken authToken) {
+ String accessToken = authToken.getAccessToken();
HttpResponse response = HttpRequest.get(UrlBuilder.getWeiboUserInfoUrl(accessToken))
.header("Authorization", "OAuth2 " + accessToken)
.header("API-RemoteIP", IpUtils.getIp())
diff --git a/src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java b/src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
index a661e495b746dd962e2a04854ba28c211926bc53..1d2bb3b1e6ec1128b0f19c4cd32ca36f5d692872 100644
--- a/src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
+++ b/src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
@@ -5,6 +5,7 @@ import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthSource;
+import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthConfigChecker;
import me.zhyd.oauth.utils.UrlBuilder;
@@ -27,9 +28,9 @@ public abstract class BaseAuthRequest implements AuthRequest {
}
}
- protected abstract String getAccessToken(String code);
+ protected abstract AuthToken getAccessToken(String code);
- protected abstract AuthUser getUserInfo(String accessToken);
+ protected abstract AuthUser getUserInfo(AuthToken authToken);
@Override
public AuthResponse login(String code) {