diff --git a/pom.xml b/pom.xml
index 1e004a663..698f641b2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,7 +36,7 @@
1.45.0
- 1.16.7
+ 2.0.0
1.85
@@ -396,7 +396,7 @@
- me.zhyd.oauth
+ cn.herodotus.opensteward
JustAuth
${justauth.version}
diff --git a/ruoyi-common/ruoyi-common-social/pom.xml b/ruoyi-common/ruoyi-common-social/pom.xml
index 8b73d0cfc..ca13e2212 100644
--- a/ruoyi-common/ruoyi-common-social/pom.xml
+++ b/ruoyi-common/ruoyi-common-social/pom.xml
@@ -18,10 +18,17 @@
- me.zhyd.oauth
+ cn.herodotus.opensteward
JustAuth
+
+
+ com.alibaba.fastjson2
+ fastjson2
+ 2.0.60
+
+
org.dromara
diff --git a/ruoyi-common/ruoyi-common-social/src/main/java/me/zhyd/oauth/request/AbstractAuthWeChatEnterpriseRequest.java b/ruoyi-common/ruoyi-common-social/src/main/java/me/zhyd/oauth/request/AbstractAuthWeChatEnterpriseRequest.java
index 268d7a923..8d0a56fee 100644
--- a/ruoyi-common/ruoyi-common-social/src/main/java/me/zhyd/oauth/request/AbstractAuthWeChatEnterpriseRequest.java
+++ b/ruoyi-common/ruoyi-common-social/src/main/java/me/zhyd/oauth/request/AbstractAuthWeChatEnterpriseRequest.java
@@ -1,9 +1,10 @@
package me.zhyd.oauth.request;
-import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSONObject;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
+import me.zhyd.oauth.constant.Keys;
import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.exception.AuthException;
@@ -59,8 +60,8 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
JSONObject object = this.checkResponse(response);
return AuthToken.builder()
- .accessToken(object.getString("access_token"))
- .expireIn(object.getIntValue("expires_in"))
+ .accessToken(object.getString(Keys.OAUTH2_ACCESS_TOKEN))
+ .expireIn(object.getIntValue(Keys.OAUTH2_EXPIRES_IN))
.code(authCallback.getCode())
.build();
}
@@ -87,13 +88,13 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
return AuthUser.builder()
.rawUserInfo(userDetail)
- .username(userDetail.getString("name"))
+ .username(userDetail.getString(Keys.NAME))
.nickname(userDetail.getString("alias"))
- .avatar(userDetail.getString("avatar"))
- .location(userDetail.getString("address"))
- .email(userDetail.getString("email"))
+ .avatar(userDetail.getString(Keys.AVATAR))
+ .location(userDetail.getString(Keys.OAUTH2_SCOPE__ADDRESS))
+ .email(userDetail.getString(Keys.OAUTH2_SCOPE__EMAIL))
.uuid(userId)
- .gender(AuthUserGender.getWechatRealGender(userDetail.getString("gender")))
+ .gender(AuthUserGender.getWechatRealGender(userDetail.getString(Keys.GENDER)))
.token(authToken)
.source(source.toString())
.build();
@@ -108,8 +109,8 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
private JSONObject checkResponse(String response) {
JSONObject object = JSONObject.parseObject(response);
- if (object.containsKey("errcode") && object.getIntValue("errcode") != 0) {
- throw new AuthException(object.getString("errmsg"), source);
+ if (object.containsKey(Keys.VARIANT__ERRCODE) && object.getIntValue(Keys.VARIANT__ERRCODE) != 0) {
+ throw new AuthException(object.getString(Keys.VARIANT__ERRMSG), source);
}
return object;
@@ -139,8 +140,8 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
@Override
protected String userInfoUrl(AuthToken authToken) {
return UrlBuilder.fromBaseUrl(source.userInfo())
- .queryParam("access_token", authToken.getAccessToken())
- .queryParam("code", authToken.getCode())
+ .queryParam(Keys.OAUTH2_ACCESS_TOKEN, authToken.getAccessToken())
+ .queryParam(Keys.OAUTH2_CODE, authToken.getCode())
.build();
}
@@ -155,8 +156,8 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
private JSONObject getUserDetail(String accessToken, String userId, String userTicket) {
// 用户基础信息
String userInfoUrl = UrlBuilder.fromBaseUrl("https://qyapi.weixin.qq.com/cgi-bin/user/get")
- .queryParam("access_token", accessToken)
- .queryParam("userid", userId)
+ .queryParam(Keys.OAUTH2_ACCESS_TOKEN, accessToken)
+ .queryParam(Keys.USERID, userId)
.build();
String userInfoResponse = new HttpUtils(config.getHttpConfig()).get(userInfoUrl).getBody();
JSONObject userInfo = checkResponse(userInfoResponse);
@@ -164,7 +165,7 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
// 用户敏感信息
if (StringUtils.isNotEmpty(userTicket)) {
String userDetailUrl = UrlBuilder.fromBaseUrl("https://qyapi.weixin.qq.com/cgi-bin/auth/getuserdetail")
- .queryParam("access_token", accessToken)
+ .queryParam(Keys.OAUTH2_ACCESS_TOKEN, accessToken)
.build();
JSONObject param = new JSONObject();
param.put("user_ticket", userTicket);
diff --git a/ruoyi-common/ruoyi-common-social/src/main/java/me/zhyd/oauth/request/AuthDingTalkV2Request.java b/ruoyi-common/ruoyi-common-social/src/main/java/me/zhyd/oauth/request/AuthDingTalkV2Request.java
index 798e8b38c..8a29e48bd 100644
--- a/ruoyi-common/ruoyi-common-social/src/main/java/me/zhyd/oauth/request/AuthDingTalkV2Request.java
+++ b/ruoyi-common/ruoyi-common-social/src/main/java/me/zhyd/oauth/request/AuthDingTalkV2Request.java
@@ -1,17 +1,17 @@
package me.zhyd.oauth.request;
-import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSONObject;
import com.xkcoding.http.support.HttpHeader;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
+import me.zhyd.oauth.constant.Keys;
import me.zhyd.oauth.enums.scope.AuthDingTalkScope;
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.AuthScopeUtils;
-import me.zhyd.oauth.utils.GlobalAuthUtils;
import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder;
@@ -54,16 +54,16 @@ public class AuthDingTalkV2Request extends AuthDefaultRequest {
@Override
public String authorize(String state) {
return UrlBuilder.fromBaseUrl(source.authorize())
- .queryParam("response_type", "code")
- .queryParam("client_id", config.getClientId())
- .queryParam("scope", this.getScopes(",", true, AuthScopeUtils.getDefaultScopes(AuthDingTalkScope.values())))
- .queryParam("redirect_uri", GlobalAuthUtils.urlEncode(config.getRedirectUri()))
+ .queryParam(Keys.OAUTH2_RESPONSE_TYPE, Keys.OAUTH2_CODE)
+ .queryParam(Keys.OAUTH2_CLIENT_ID, config.getClientId())
+ .queryParam(Keys.OAUTH2_SCOPE, this.getScopes(",", true, AuthScopeUtils.getDefaultScopes(AuthDingTalkScope.values())))
+ .queryParam(Keys.OAUTH2_REDIRECT_URI, config.getRedirectUri())
.queryParam("prompt", "consent")
.queryParam("org_type", config.getDingTalkOrgType())
.queryParam("corpId", config.getDingTalkCorpId())
.queryParam("exclusiveLogin", config.isDingTalkExclusiveLogin())
.queryParam("exclusiveCorpId", config.getDingTalkExclusiveCorpId())
- .queryParam("state", getRealState(state))
+ .queryParam(Keys.OAUTH2_STATE, getRealState(state))
.build();
}
@@ -76,10 +76,10 @@ public class AuthDingTalkV2Request extends AuthDefaultRequest {
@Override
public AuthToken getAccessToken(AuthCallback authCallback) {
Map params = new HashMap<>();
- params.put("grantType", "authorization_code");
+ params.put("grantType", Keys.OAUTH2_GRANT_TYPE__AUTHORIZATION_CODE);
params.put("clientId", config.getClientId());
params.put("clientSecret", config.getClientSecret());
- params.put("code", authCallback.getCode());
+ params.put(Keys.OAUTH2_CODE, authCallback.getCode());
String response = new HttpUtils(config.getHttpConfig()).post(this.source.accessToken(), JSONObject.toJSONString(params)).getBody();
JSONObject accessTokenObject = JSONObject.parseObject(response);
if (!accessTokenObject.containsKey("accessToken")) {
@@ -129,10 +129,10 @@ public class AuthDingTalkV2Request extends AuthDefaultRequest {
*/
protected String accessTokenUrl(String code) {
return UrlBuilder.fromBaseUrl(source.accessToken())
- .queryParam("code", code)
+ .queryParam(Keys.OAUTH2_CODE, code)
.queryParam("clientId", config.getClientId())
.queryParam("clientSecret", config.getClientSecret())
- .queryParam("grantType", "authorization_code")
+ .queryParam("grantType", Keys.OAUTH2_GRANT_TYPE__AUTHORIZATION_CODE)
.build();
}
}