mirror of
https://gitee.com/yadong.zhang/JustAuth.git
synced 2025-12-07 01:08:24 +08:00
企业微信网页登录增加AgentId参数,对重定向地址UrlEncode,获取用户敏感信息
This commit is contained in:
parent
571466f079
commit
f3a8cf675c
@ -3,7 +3,6 @@ package me.zhyd.oauth.request;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.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.AuthDefaultSource;
|
|
||||||
import me.zhyd.oauth.config.AuthSource;
|
import me.zhyd.oauth.config.AuthSource;
|
||||||
import me.zhyd.oauth.enums.AuthResponseStatus;
|
import me.zhyd.oauth.enums.AuthResponseStatus;
|
||||||
import me.zhyd.oauth.enums.AuthUserGender;
|
import me.zhyd.oauth.enums.AuthUserGender;
|
||||||
@ -12,6 +11,7 @@ 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.HttpUtils;
|
import me.zhyd.oauth.utils.HttpUtils;
|
||||||
|
import me.zhyd.oauth.utils.StringUtils;
|
||||||
import me.zhyd.oauth.utils.UrlBuilder;
|
import me.zhyd.oauth.utils.UrlBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,8 +56,8 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
|
|||||||
throw new AuthException(AuthResponseStatus.UNIDENTIFIED_PLATFORM, source);
|
throw new AuthException(AuthResponseStatus.UNIDENTIFIED_PLATFORM, source);
|
||||||
}
|
}
|
||||||
String userId = object.getString("UserId");
|
String userId = object.getString("UserId");
|
||||||
String userDetailResponse = getUserDetail(authToken.getAccessToken(), userId);
|
String userTicket = object.getString("user_ticket");
|
||||||
JSONObject userDetail = this.checkResponse(userDetailResponse);
|
JSONObject userDetail = getUserDetail(authToken.getAccessToken(), userId, userTicket);
|
||||||
|
|
||||||
return AuthUser.builder()
|
return AuthUser.builder()
|
||||||
.rawUserInfo(userDetail)
|
.rawUserInfo(userDetail)
|
||||||
@ -123,14 +123,31 @@ public abstract class AbstractAuthWeChatEnterpriseRequest extends AuthDefaultReq
|
|||||||
*
|
*
|
||||||
* @param accessToken accessToken
|
* @param accessToken accessToken
|
||||||
* @param userId 企业内用户id
|
* @param userId 企业内用户id
|
||||||
|
* @param userTicket 成员票据,用于获取用户信息或敏感信息
|
||||||
* @return 用户详情
|
* @return 用户详情
|
||||||
*/
|
*/
|
||||||
private String getUserDetail(String accessToken, String userId) {
|
private JSONObject getUserDetail(String accessToken, String userId, String userTicket) {
|
||||||
String userDetailUrl = 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("access_token", accessToken)
|
||||||
.queryParam("userid", userId)
|
.queryParam("userid", userId)
|
||||||
.build();
|
.build();
|
||||||
return new HttpUtils(config.getHttpConfig()).get(userDetailUrl).getBody();
|
String userInfoResponse = new HttpUtils(config.getHttpConfig()).get(userInfoUrl).getBody();
|
||||||
|
JSONObject userInfo = checkResponse(userInfoResponse);
|
||||||
|
|
||||||
|
// 用户敏感信息
|
||||||
|
if (StringUtils.isNotEmpty(userTicket)) {
|
||||||
|
String userDetailUrl = UrlBuilder.fromBaseUrl("https://qyapi.weixin.qq.com/cgi-bin/auth/getuserdetail")
|
||||||
|
.queryParam("access_token", accessToken)
|
||||||
|
.build();
|
||||||
|
JSONObject param = new JSONObject();
|
||||||
|
param.put("user_ticket", userTicket);
|
||||||
|
String userDetailResponse = new HttpUtils(config.getHttpConfig()).post(userDetailUrl, param.toJSONString()).getBody();
|
||||||
|
JSONObject userDetail = checkResponse(userDetailResponse);
|
||||||
|
|
||||||
|
userInfo.putAll(userDetail);
|
||||||
|
}
|
||||||
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import me.zhyd.oauth.config.AuthConfig;
|
|||||||
import me.zhyd.oauth.config.AuthDefaultSource;
|
import me.zhyd.oauth.config.AuthDefaultSource;
|
||||||
import me.zhyd.oauth.enums.scope.AuthWeChatEnterpriseWebScope;
|
import me.zhyd.oauth.enums.scope.AuthWeChatEnterpriseWebScope;
|
||||||
import me.zhyd.oauth.utils.AuthScopeUtils;
|
import me.zhyd.oauth.utils.AuthScopeUtils;
|
||||||
|
import me.zhyd.oauth.utils.GlobalAuthUtils;
|
||||||
import me.zhyd.oauth.utils.UrlBuilder;
|
import me.zhyd.oauth.utils.UrlBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +29,8 @@ public class AuthWeChatEnterpriseWebRequest extends AbstractAuthWeChatEnterprise
|
|||||||
public String authorize(String state) {
|
public String authorize(String state) {
|
||||||
return UrlBuilder.fromBaseUrl(source.authorize())
|
return UrlBuilder.fromBaseUrl(source.authorize())
|
||||||
.queryParam("appid", config.getClientId())
|
.queryParam("appid", config.getClientId())
|
||||||
.queryParam("redirect_uri", config.getRedirectUri())
|
.queryParam("agentid", config.getAgentId())
|
||||||
|
.queryParam("redirect_uri", GlobalAuthUtils.urlEncode(config.getRedirectUri()))
|
||||||
.queryParam("response_type", "code")
|
.queryParam("response_type", "code")
|
||||||
.queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthWeChatEnterpriseWebScope.values())))
|
.queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthWeChatEnterpriseWebScope.values())))
|
||||||
.queryParam("state", getRealState(state).concat("#wechat_redirect"))
|
.queryParam("state", getRealState(state).concat("#wechat_redirect"))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user