update 优化 使用三方修改的justauth版本 去掉fastjson
This commit is contained in:
@@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
<!-- 安全认证与加密相关依赖版本 -->
|
<!-- 安全认证与加密相关依赖版本 -->
|
||||||
<satoken.version>1.45.0</satoken.version>
|
<satoken.version>1.45.0</satoken.version>
|
||||||
<justauth.version>1.16.7</justauth.version>
|
<justauth.version>2.0.0</justauth.version>
|
||||||
<bouncycastle.version>1.85</bouncycastle.version>
|
<bouncycastle.version>1.85</bouncycastle.version>
|
||||||
|
|
||||||
<!-- 缓存、锁与任务调度相关依赖版本 -->
|
<!-- 缓存、锁与任务调度相关依赖版本 -->
|
||||||
@@ -396,7 +396,7 @@
|
|||||||
|
|
||||||
<!-- JustAuth 的依赖配置-->
|
<!-- JustAuth 的依赖配置-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.zhyd.oauth</groupId>
|
<groupId>cn.herodotus.opensteward</groupId>
|
||||||
<artifactId>JustAuth</artifactId>
|
<artifactId>JustAuth</artifactId>
|
||||||
<version>${justauth.version}</version>
|
<version>${justauth.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
@@ -18,10 +18,17 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- 授权认证 -->
|
<!-- 授权认证 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.zhyd.oauth</groupId>
|
<groupId>cn.herodotus.opensteward</groupId>
|
||||||
<artifactId>JustAuth</artifactId>
|
<artifactId>JustAuth</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 仅供 justauth 内部解析参数使用 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
<version>2.0.60</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 序列化模块 -->
|
<!-- 序列化模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara</groupId>
|
<groupId>org.dromara</groupId>
|
||||||
|
|||||||
+16
-15
@@ -1,9 +1,10 @@
|
|||||||
package me.zhyd.oauth.request;
|
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.cache.AuthStateCache;
|
||||||
import me.zhyd.oauth.config.AuthConfig;
|
import me.zhyd.oauth.config.AuthConfig;
|
||||||
import me.zhyd.oauth.config.AuthSource;
|
import me.zhyd.oauth.config.AuthSource;
|
||||||
|
import me.zhyd.oauth.constant.Keys;
|
||||||
import me.zhyd.oauth.enums.AuthResponseStatus;
|
import me.zhyd.oauth.enums.AuthResponseStatus;
|
||||||
import me.zhyd.oauth.enums.AuthUserGender;
|
import me.zhyd.oauth.enums.AuthUserGender;
|
||||||
import me.zhyd.oauth.exception.AuthException;
|
import me.zhyd.oauth.exception.AuthException;
|
||||||
@@ -59,8 +60,8 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
|
|||||||
JSONObject object = this.checkResponse(response);
|
JSONObject object = this.checkResponse(response);
|
||||||
|
|
||||||
return AuthToken.builder()
|
return AuthToken.builder()
|
||||||
.accessToken(object.getString("access_token"))
|
.accessToken(object.getString(Keys.OAUTH2_ACCESS_TOKEN))
|
||||||
.expireIn(object.getIntValue("expires_in"))
|
.expireIn(object.getIntValue(Keys.OAUTH2_EXPIRES_IN))
|
||||||
.code(authCallback.getCode())
|
.code(authCallback.getCode())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@@ -87,13 +88,13 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
|
|||||||
|
|
||||||
return AuthUser.builder()
|
return AuthUser.builder()
|
||||||
.rawUserInfo(userDetail)
|
.rawUserInfo(userDetail)
|
||||||
.username(userDetail.getString("name"))
|
.username(userDetail.getString(Keys.NAME))
|
||||||
.nickname(userDetail.getString("alias"))
|
.nickname(userDetail.getString("alias"))
|
||||||
.avatar(userDetail.getString("avatar"))
|
.avatar(userDetail.getString(Keys.AVATAR))
|
||||||
.location(userDetail.getString("address"))
|
.location(userDetail.getString(Keys.OAUTH2_SCOPE__ADDRESS))
|
||||||
.email(userDetail.getString("email"))
|
.email(userDetail.getString(Keys.OAUTH2_SCOPE__EMAIL))
|
||||||
.uuid(userId)
|
.uuid(userId)
|
||||||
.gender(AuthUserGender.getWechatRealGender(userDetail.getString("gender")))
|
.gender(AuthUserGender.getWechatRealGender(userDetail.getString(Keys.GENDER)))
|
||||||
.token(authToken)
|
.token(authToken)
|
||||||
.source(source.toString())
|
.source(source.toString())
|
||||||
.build();
|
.build();
|
||||||
@@ -108,8 +109,8 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
|
|||||||
private JSONObject checkResponse(String response) {
|
private JSONObject checkResponse(String response) {
|
||||||
JSONObject object = JSONObject.parseObject(response);
|
JSONObject object = JSONObject.parseObject(response);
|
||||||
|
|
||||||
if (object.containsKey("errcode") && object.getIntValue("errcode") != 0) {
|
if (object.containsKey(Keys.VARIANT__ERRCODE) && object.getIntValue(Keys.VARIANT__ERRCODE) != 0) {
|
||||||
throw new AuthException(object.getString("errmsg"), source);
|
throw new AuthException(object.getString(Keys.VARIANT__ERRMSG), source);
|
||||||
}
|
}
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
@@ -139,8 +140,8 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
|
|||||||
@Override
|
@Override
|
||||||
protected String userInfoUrl(AuthToken authToken) {
|
protected String userInfoUrl(AuthToken authToken) {
|
||||||
return UrlBuilder.fromBaseUrl(source.userInfo())
|
return UrlBuilder.fromBaseUrl(source.userInfo())
|
||||||
.queryParam("access_token", authToken.getAccessToken())
|
.queryParam(Keys.OAUTH2_ACCESS_TOKEN, authToken.getAccessToken())
|
||||||
.queryParam("code", authToken.getCode())
|
.queryParam(Keys.OAUTH2_CODE, authToken.getCode())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,8 +156,8 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
|
|||||||
private JSONObject getUserDetail(String accessToken, String userId, String userTicket) {
|
private JSONObject getUserDetail(String accessToken, String userId, String userTicket) {
|
||||||
// 用户基础信息
|
// 用户基础信息
|
||||||
String userInfoUrl = UrlBuilder.fromBaseUrl("https://qyapi.weixin.qq.com/cgi-bin/user/get")
|
String userInfoUrl = UrlBuilder.fromBaseUrl("https://qyapi.weixin.qq.com/cgi-bin/user/get")
|
||||||
.queryParam("access_token", accessToken)
|
.queryParam(Keys.OAUTH2_ACCESS_TOKEN, accessToken)
|
||||||
.queryParam("userid", userId)
|
.queryParam(Keys.USERID, userId)
|
||||||
.build();
|
.build();
|
||||||
String userInfoResponse = new HttpUtils(config.getHttpConfig()).get(userInfoUrl).getBody();
|
String userInfoResponse = new HttpUtils(config.getHttpConfig()).get(userInfoUrl).getBody();
|
||||||
JSONObject userInfo = checkResponse(userInfoResponse);
|
JSONObject userInfo = checkResponse(userInfoResponse);
|
||||||
@@ -164,7 +165,7 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
|
|||||||
// 用户敏感信息
|
// 用户敏感信息
|
||||||
if (StringUtils.isNotEmpty(userTicket)) {
|
if (StringUtils.isNotEmpty(userTicket)) {
|
||||||
String userDetailUrl = UrlBuilder.fromBaseUrl("https://qyapi.weixin.qq.com/cgi-bin/auth/getuserdetail")
|
String userDetailUrl = UrlBuilder.fromBaseUrl("https://qyapi.weixin.qq.com/cgi-bin/auth/getuserdetail")
|
||||||
.queryParam("access_token", accessToken)
|
.queryParam(Keys.OAUTH2_ACCESS_TOKEN, accessToken)
|
||||||
.build();
|
.build();
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("user_ticket", userTicket);
|
param.put("user_ticket", userTicket);
|
||||||
|
|||||||
+11
-11
@@ -1,17 +1,17 @@
|
|||||||
package me.zhyd.oauth.request;
|
package me.zhyd.oauth.request;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.xkcoding.http.support.HttpHeader;
|
import com.xkcoding.http.support.HttpHeader;
|
||||||
import me.zhyd.oauth.cache.AuthStateCache;
|
import me.zhyd.oauth.cache.AuthStateCache;
|
||||||
import me.zhyd.oauth.config.AuthConfig;
|
import me.zhyd.oauth.config.AuthConfig;
|
||||||
import me.zhyd.oauth.config.AuthDefaultSource;
|
import me.zhyd.oauth.config.AuthDefaultSource;
|
||||||
|
import me.zhyd.oauth.constant.Keys;
|
||||||
import me.zhyd.oauth.enums.scope.AuthDingTalkScope;
|
import me.zhyd.oauth.enums.scope.AuthDingTalkScope;
|
||||||
import me.zhyd.oauth.exception.AuthException;
|
import me.zhyd.oauth.exception.AuthException;
|
||||||
import me.zhyd.oauth.model.AuthCallback;
|
import me.zhyd.oauth.model.AuthCallback;
|
||||||
import me.zhyd.oauth.model.AuthToken;
|
import me.zhyd.oauth.model.AuthToken;
|
||||||
import me.zhyd.oauth.model.AuthUser;
|
import me.zhyd.oauth.model.AuthUser;
|
||||||
import me.zhyd.oauth.utils.AuthScopeUtils;
|
import me.zhyd.oauth.utils.AuthScopeUtils;
|
||||||
import me.zhyd.oauth.utils.GlobalAuthUtils;
|
|
||||||
import me.zhyd.oauth.utils.HttpUtils;
|
import me.zhyd.oauth.utils.HttpUtils;
|
||||||
import me.zhyd.oauth.utils.UrlBuilder;
|
import me.zhyd.oauth.utils.UrlBuilder;
|
||||||
|
|
||||||
@@ -54,16 +54,16 @@ public class AuthDingTalkV2Request extends AuthDefaultRequest {
|
|||||||
@Override
|
@Override
|
||||||
public String authorize(String state) {
|
public String authorize(String state) {
|
||||||
return UrlBuilder.fromBaseUrl(source.authorize())
|
return UrlBuilder.fromBaseUrl(source.authorize())
|
||||||
.queryParam("response_type", "code")
|
.queryParam(Keys.OAUTH2_RESPONSE_TYPE, Keys.OAUTH2_CODE)
|
||||||
.queryParam("client_id", config.getClientId())
|
.queryParam(Keys.OAUTH2_CLIENT_ID, config.getClientId())
|
||||||
.queryParam("scope", this.getScopes(",", true, AuthScopeUtils.getDefaultScopes(AuthDingTalkScope.values())))
|
.queryParam(Keys.OAUTH2_SCOPE, this.getScopes(",", true, AuthScopeUtils.getDefaultScopes(AuthDingTalkScope.values())))
|
||||||
.queryParam("redirect_uri", GlobalAuthUtils.urlEncode(config.getRedirectUri()))
|
.queryParam(Keys.OAUTH2_REDIRECT_URI, config.getRedirectUri())
|
||||||
.queryParam("prompt", "consent")
|
.queryParam("prompt", "consent")
|
||||||
.queryParam("org_type", config.getDingTalkOrgType())
|
.queryParam("org_type", config.getDingTalkOrgType())
|
||||||
.queryParam("corpId", config.getDingTalkCorpId())
|
.queryParam("corpId", config.getDingTalkCorpId())
|
||||||
.queryParam("exclusiveLogin", config.isDingTalkExclusiveLogin())
|
.queryParam("exclusiveLogin", config.isDingTalkExclusiveLogin())
|
||||||
.queryParam("exclusiveCorpId", config.getDingTalkExclusiveCorpId())
|
.queryParam("exclusiveCorpId", config.getDingTalkExclusiveCorpId())
|
||||||
.queryParam("state", getRealState(state))
|
.queryParam(Keys.OAUTH2_STATE, getRealState(state))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,10 +76,10 @@ public class AuthDingTalkV2Request extends AuthDefaultRequest {
|
|||||||
@Override
|
@Override
|
||||||
public AuthToken getAccessToken(AuthCallback authCallback) {
|
public AuthToken getAccessToken(AuthCallback authCallback) {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put("grantType", "authorization_code");
|
params.put("grantType", Keys.OAUTH2_GRANT_TYPE__AUTHORIZATION_CODE);
|
||||||
params.put("clientId", config.getClientId());
|
params.put("clientId", config.getClientId());
|
||||||
params.put("clientSecret", config.getClientSecret());
|
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();
|
String response = new HttpUtils(config.getHttpConfig()).post(this.source.accessToken(), JSONObject.toJSONString(params)).getBody();
|
||||||
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
JSONObject accessTokenObject = JSONObject.parseObject(response);
|
||||||
if (!accessTokenObject.containsKey("accessToken")) {
|
if (!accessTokenObject.containsKey("accessToken")) {
|
||||||
@@ -129,10 +129,10 @@ public class AuthDingTalkV2Request extends AuthDefaultRequest {
|
|||||||
*/
|
*/
|
||||||
protected String accessTokenUrl(String code) {
|
protected String accessTokenUrl(String code) {
|
||||||
return UrlBuilder.fromBaseUrl(source.accessToken())
|
return UrlBuilder.fromBaseUrl(source.accessToken())
|
||||||
.queryParam("code", code)
|
.queryParam(Keys.OAUTH2_CODE, code)
|
||||||
.queryParam("clientId", config.getClientId())
|
.queryParam("clientId", config.getClientId())
|
||||||
.queryParam("clientSecret", config.getClientSecret())
|
.queryParam("clientSecret", config.getClientSecret())
|
||||||
.queryParam("grantType", "authorization_code")
|
.queryParam("grantType", Keys.OAUTH2_GRANT_TYPE__AUTHORIZATION_CODE)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user