yangys
2024-03-27 e48aa2ac8dea1be5db11c63edf0b912c4ad5ce65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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;
    }
}