1
0
mirror of synced 2025-12-11 00:18:07 +08:00

支持外部自定义 Cache 缓存 state

This commit is contained in:
Yangkai.Shen
2019-08-02 15:03:09 +08:00
parent f921f55cc0
commit 1ea5001700
3 changed files with 39 additions and 28 deletions

View File

@@ -6,7 +6,7 @@
<groupId>com.xkcoding</groupId> <groupId>com.xkcoding</groupId>
<artifactId>justauth-spring-boot-starter</artifactId> <artifactId>justauth-spring-boot-starter</artifactId>
<version>0.0.2</version> <version>0.0.3-SNAPSHOT</version>
<name>justauth-spring-boot-starter</name> <name>justauth-spring-boot-starter</name>
<url>https://github.com/xkcoding/justauth-spring-boot-starter</url> <url>https://github.com/xkcoding/justauth-spring-boot-starter</url>
@@ -50,7 +50,7 @@
<!--SpringBoot版本--> <!--SpringBoot版本-->
<spring-boot.version>2.1.6.RELEASE</spring-boot.version> <spring-boot.version>2.1.6.RELEASE</spring-boot.version>
<!--JustAuth版本--> <!--JustAuth版本-->
<justauth.version>1.9.5</justauth.version> <justauth.version>1.9.6-SNAPSHOT</justauth.version>
</properties> </properties>
<dependencies> <dependencies>

View File

@@ -2,6 +2,7 @@ package com.xkcoding.justauth;
import com.xkcoding.justauth.properties.JustAuthProperties; import com.xkcoding.justauth.properties.JustAuthProperties;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
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.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
@@ -19,6 +20,7 @@ import me.zhyd.oauth.request.*;
@RequiredArgsConstructor @RequiredArgsConstructor
public class AuthRequestFactory { public class AuthRequestFactory {
private final JustAuthProperties properties; private final JustAuthProperties properties;
private final AuthStateCache authStateCache;
/** /**
* 返回AuthRequest对象 * 返回AuthRequest对象
@@ -30,53 +32,53 @@ public class AuthRequestFactory {
AuthConfig config = properties.getType().get(source); AuthConfig config = properties.getType().get(source);
switch (source) { switch (source) {
case GITHUB: case GITHUB:
return new AuthGithubRequest(config); return new AuthGithubRequest(config, authStateCache);
case WEIBO: case WEIBO:
return new AuthWeiboRequest(config); return new AuthWeiboRequest(config, authStateCache);
case GITEE: case GITEE:
return new AuthGiteeRequest(config); return new AuthGiteeRequest(config, authStateCache);
case DINGTALK: case DINGTALK:
return new AuthDingTalkRequest(config); return new AuthDingTalkRequest(config, authStateCache);
case BAIDU: case BAIDU:
return new AuthBaiduRequest(config); return new AuthBaiduRequest(config, authStateCache);
case CSDN: case CSDN:
return new AuthCsdnRequest(config); return new AuthCsdnRequest(config, authStateCache);
case CODING: case CODING:
return new AuthCodingRequest(config); return new AuthCodingRequest(config, authStateCache);
case TENCENT_CLOUD: case TENCENT_CLOUD:
return new AuthTencentCloudRequest(config); return new AuthTencentCloudRequest(config, authStateCache);
case OSCHINA: case OSCHINA:
return new AuthOschinaRequest(config); return new AuthOschinaRequest(config, authStateCache);
case ALIPAY: case ALIPAY:
return new AuthAlipayRequest(config); return new AuthAlipayRequest(config, authStateCache);
case QQ: case QQ:
return new AuthQqRequest(config); return new AuthQqRequest(config, authStateCache);
case WECHAT: case WECHAT:
return new AuthWeChatRequest(config); return new AuthWeChatRequest(config, authStateCache);
case TAOBAO: case TAOBAO:
return new AuthTaobaoRequest(config); return new AuthTaobaoRequest(config, authStateCache);
case GOOGLE: case GOOGLE:
return new AuthGoogleRequest(config); return new AuthGoogleRequest(config, authStateCache);
case FACEBOOK: case FACEBOOK:
return new AuthFacebookRequest(config); return new AuthFacebookRequest(config, authStateCache);
case DOUYIN: case DOUYIN:
return new AuthDouyinRequest(config); return new AuthDouyinRequest(config, authStateCache);
case LINKEDIN: case LINKEDIN:
return new AuthLinkedinRequest(config); return new AuthLinkedinRequest(config, authStateCache);
case MICROSOFT: case MICROSOFT:
return new AuthMicrosoftRequest(config); return new AuthMicrosoftRequest(config, authStateCache);
case MI: case MI:
return new AuthMiRequest(config); return new AuthMiRequest(config, authStateCache);
case TOUTIAO: case TOUTIAO:
return new AuthToutiaoRequest(config); return new AuthToutiaoRequest(config, authStateCache);
case TEAMBITION: case TEAMBITION:
return new AuthTeambitionRequest(config); return new AuthTeambitionRequest(config, authStateCache);
case RENREN: case RENREN:
return new AuthRenrenRequest(config); return new AuthRenrenRequest(config, authStateCache);
case PINTEREST: case PINTEREST:
return new AuthPinterestRequest(config); return new AuthPinterestRequest(config, authStateCache);
case STACK_OVERFLOW: case STACK_OVERFLOW:
return new AuthStackOverflowRequest(config); return new AuthStackOverflowRequest(config, authStateCache);
default: default:
throw new AuthException(AuthResponseStatus.UNSUPPORTED); throw new AuthException(AuthResponseStatus.UNSUPPORTED);
} }

View File

@@ -1,6 +1,9 @@
package com.xkcoding.justauth; package com.xkcoding.justauth;
import com.xkcoding.justauth.properties.JustAuthProperties; 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.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@@ -20,8 +23,14 @@ public class JustAuthAutoConfiguration {
@Bean @Bean
@ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true) @ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true)
public AuthRequestFactory authRequestFactory(JustAuthProperties properties) { public AuthRequestFactory authRequestFactory(JustAuthProperties properties, AuthStateCache authStateCache) {
return new AuthRequestFactory(properties); return new AuthRequestFactory(properties, authStateCache);
}
@Bean
@ConditionalOnBean(AuthStateCache.class)
public AuthStateCache authStateCache() {
return AuthDefaultStateCache.INSTANCE;
} }
} }