✨ 支持外部自定义 Cache 缓存 state
This commit is contained in:
@@ -2,6 +2,7 @@ package com.xkcoding.justauth;
|
||||
|
||||
import com.xkcoding.justauth.properties.JustAuthProperties;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhyd.oauth.cache.AuthStateCache;
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.config.AuthSource;
|
||||
import me.zhyd.oauth.enums.AuthResponseStatus;
|
||||
@@ -19,6 +20,7 @@ import me.zhyd.oauth.request.*;
|
||||
@RequiredArgsConstructor
|
||||
public class AuthRequestFactory {
|
||||
private final JustAuthProperties properties;
|
||||
private final AuthStateCache authStateCache;
|
||||
|
||||
/**
|
||||
* 返回AuthRequest对象
|
||||
@@ -30,53 +32,53 @@ public class AuthRequestFactory {
|
||||
AuthConfig config = properties.getType().get(source);
|
||||
switch (source) {
|
||||
case GITHUB:
|
||||
return new AuthGithubRequest(config);
|
||||
return new AuthGithubRequest(config, authStateCache);
|
||||
case WEIBO:
|
||||
return new AuthWeiboRequest(config);
|
||||
return new AuthWeiboRequest(config, authStateCache);
|
||||
case GITEE:
|
||||
return new AuthGiteeRequest(config);
|
||||
return new AuthGiteeRequest(config, authStateCache);
|
||||
case DINGTALK:
|
||||
return new AuthDingTalkRequest(config);
|
||||
return new AuthDingTalkRequest(config, authStateCache);
|
||||
case BAIDU:
|
||||
return new AuthBaiduRequest(config);
|
||||
return new AuthBaiduRequest(config, authStateCache);
|
||||
case CSDN:
|
||||
return new AuthCsdnRequest(config);
|
||||
return new AuthCsdnRequest(config, authStateCache);
|
||||
case CODING:
|
||||
return new AuthCodingRequest(config);
|
||||
return new AuthCodingRequest(config, authStateCache);
|
||||
case TENCENT_CLOUD:
|
||||
return new AuthTencentCloudRequest(config);
|
||||
return new AuthTencentCloudRequest(config, authStateCache);
|
||||
case OSCHINA:
|
||||
return new AuthOschinaRequest(config);
|
||||
return new AuthOschinaRequest(config, authStateCache);
|
||||
case ALIPAY:
|
||||
return new AuthAlipayRequest(config);
|
||||
return new AuthAlipayRequest(config, authStateCache);
|
||||
case QQ:
|
||||
return new AuthQqRequest(config);
|
||||
return new AuthQqRequest(config, authStateCache);
|
||||
case WECHAT:
|
||||
return new AuthWeChatRequest(config);
|
||||
return new AuthWeChatRequest(config, authStateCache);
|
||||
case TAOBAO:
|
||||
return new AuthTaobaoRequest(config);
|
||||
return new AuthTaobaoRequest(config, authStateCache);
|
||||
case GOOGLE:
|
||||
return new AuthGoogleRequest(config);
|
||||
return new AuthGoogleRequest(config, authStateCache);
|
||||
case FACEBOOK:
|
||||
return new AuthFacebookRequest(config);
|
||||
return new AuthFacebookRequest(config, authStateCache);
|
||||
case DOUYIN:
|
||||
return new AuthDouyinRequest(config);
|
||||
return new AuthDouyinRequest(config, authStateCache);
|
||||
case LINKEDIN:
|
||||
return new AuthLinkedinRequest(config);
|
||||
return new AuthLinkedinRequest(config, authStateCache);
|
||||
case MICROSOFT:
|
||||
return new AuthMicrosoftRequest(config);
|
||||
return new AuthMicrosoftRequest(config, authStateCache);
|
||||
case MI:
|
||||
return new AuthMiRequest(config);
|
||||
return new AuthMiRequest(config, authStateCache);
|
||||
case TOUTIAO:
|
||||
return new AuthToutiaoRequest(config);
|
||||
return new AuthToutiaoRequest(config, authStateCache);
|
||||
case TEAMBITION:
|
||||
return new AuthTeambitionRequest(config);
|
||||
return new AuthTeambitionRequest(config, authStateCache);
|
||||
case RENREN:
|
||||
return new AuthRenrenRequest(config);
|
||||
return new AuthRenrenRequest(config, authStateCache);
|
||||
case PINTEREST:
|
||||
return new AuthPinterestRequest(config);
|
||||
return new AuthPinterestRequest(config, authStateCache);
|
||||
case STACK_OVERFLOW:
|
||||
return new AuthStackOverflowRequest(config);
|
||||
return new AuthStackOverflowRequest(config, authStateCache);
|
||||
default:
|
||||
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.xkcoding.justauth;
|
||||
|
||||
import com.xkcoding.justauth.properties.JustAuthProperties;
|
||||
import me.zhyd.oauth.cache.AuthDefaultStateCache;
|
||||
import me.zhyd.oauth.cache.AuthStateCache;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -20,8 +23,14 @@ public class JustAuthAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
public AuthRequestFactory authRequestFactory(JustAuthProperties properties) {
|
||||
return new AuthRequestFactory(properties);
|
||||
public AuthRequestFactory authRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) {
|
||||
return new AuthRequestFactory(properties, authStateCache);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(AuthStateCache.class)
|
||||
public AuthStateCache authStateCache() {
|
||||
return AuthDefaultStateCache.INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user