package com.qianwen.core.social.utils;
|
|
import me.zhyd.oauth.cache.AuthStateCache;
|
import me.zhyd.oauth.config.AuthConfig;
|
import me.zhyd.oauth.exception.AuthException;
|
import me.zhyd.oauth.request.AuthDefaultRequest;
|
import me.zhyd.oauth.request.AuthRequest;
|
import com.qianwen.core.social.props.BladeAuthSource;
|
import com.qianwen.core.social.props.ISocialProperties;
|
import com.qianwen.core.tool.utils.SpringUtil;
|
|
/* loaded from: blade-starter-social-9.3.2.0-SNAPSHOT.jar:org/springblade/core/social/utils/SocialUtil.class */
|
public class SocialUtil {
|
private static AuthStateCache authStateCache;
|
|
public static AuthStateCache getAuthStateCache() {
|
if (authStateCache == null) {
|
authStateCache = (AuthStateCache) SpringUtil.getBean(AuthStateCache.class);
|
}
|
return authStateCache;
|
}
|
|
|
public static <T extends me.zhyd.oauth.request.AuthDefaultRequest> T getAuthRequest(BladeAuthSource authSource) {
|
return (T)getAuthRequest(authSource.getName());
|
}
|
|
|
public static AuthRequest getAuthRequest(String source) {
|
ISocialProperties socialProperties = (ISocialProperties) SpringUtil.getBean(ISocialProperties.class);
|
AuthConfig authConfig = socialProperties.getOauth().get(source.toUpperCase());
|
authConfig.setIgnoreCheckRedirectUri(true);
|
return getAuthRequest(source, authConfig);
|
}
|
|
public static AuthRequest getAuthRequest(String source, AuthConfig authConfig) {
|
if (authConfig == null) {
|
throw new AuthException("未获取到有效的Auth配置");
|
}
|
AuthRequest authRequest = AuthBuilder.builder().authConfig(authConfig).authStateCache(getAuthStateCache()).source(source).extendSource(BladeAuthSource.DINGTALK_WEB, BladeAuthSource.WECHAT_ENTERPRISE_WEB).build();
|
if (null == authRequest) {
|
throw new AuthException("未获取到有效的Auth配置");
|
}
|
return authRequest;
|
}
|
}
|