diff --git a/continew-starter-auth/continew-starter-auth-justauth/pom.xml b/continew-starter-auth/continew-starter-auth-justauth/pom.xml
index db2199a7..fcdeaf81 100644
--- a/continew-starter-auth/continew-starter-auth-justauth/pom.xml
+++ b/continew-starter-auth/continew-starter-auth-justauth/pom.xml
@@ -28,10 +28,5 @@
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *
+ * http://www.gnu.org/licenses/lgpl.html + *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.auth.justauth;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.EnumUtil;
+import cn.hutool.core.util.ReflectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.xkcoding.http.config.HttpConfig;
+import me.zhyd.oauth.AuthRequestBuilder;
+import me.zhyd.oauth.cache.AuthStateCache;
+import me.zhyd.oauth.config.AuthConfig;
+import me.zhyd.oauth.config.AuthDefaultSource;
+import me.zhyd.oauth.config.AuthSource;
+import me.zhyd.oauth.enums.AuthResponseStatus;
+import me.zhyd.oauth.exception.AuthException;
+import me.zhyd.oauth.request.*;
+import top.continew.starter.auth.justauth.autoconfigure.JustAuthExtendProperties;
+import top.continew.starter.auth.justauth.autoconfigure.JustAuthHttpProperties;
+import top.continew.starter.auth.justauth.autoconfigure.JustAuthProperties;
+
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * AuthRequest 工厂类
+ *
+ * @author yangkai.shen
+ * @author Charles7c
+ * @since 2.15.0
+ */
+public class AuthRequestFactory {
+
+ private final JustAuthProperties properties;
+ private final AuthStateCache stateCache;
+
+ public AuthRequestFactory(JustAuthProperties properties, AuthStateCache stateCache) {
+ this.properties = properties;
+ this.stateCache = stateCache;
+ }
+
+ /**
+ * 获取 AuthRequest
+ *
+ * @param source {@link AuthSource}
+ * @return {@link AuthRequest}
+ */
+ public AuthRequest getAuthRequest(String source) {
+ if (StrUtil.isBlank(source)) {
+ throw new AuthException(AuthResponseStatus.NO_AUTH_SOURCE);
+ }
+
+ // 获取内置 AuthRequest
+ AuthRequest authRequest = this.getDefaultAuthRequest(source);
+
+ // 获取自定义 AuthRequest
+ if (authRequest == null) {
+ authRequest = this.getExtendAuthRequest(properties.getExtend().getEnumClass(), source);
+ }
+
+ if (authRequest == null) {
+ throw new AuthException(AuthResponseStatus.UNSUPPORTED);
+ }
+ return authRequest;
+ }
+
+ /**
+ * 获取自定义 AuthRequest
+ *
+ * @param clazz 枚举类 {@link AuthSource}
+ * @param source {@link AuthSource}
+ * @return {@link AuthRequest}
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private AuthRequest getExtendAuthRequest(Class clazz, String source) {
+ String upperSource = source.toUpperCase();
+ try {
+ EnumUtil.fromString(clazz, upperSource);
+ } catch (IllegalArgumentException e) {
+ // 无自定义匹配
+ return null;
+ }
+
+ Map
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.auth.justauth.autoconfigure;
+
+import java.time.Duration;
+
+/**
+ * JustAuth 缓存配置属性
+ *
+ * @author yangkai.shen
+ * @author Charles7c
+ * @since 2.15.0
+ */
+public class JustAuthCacheProperties {
+
+ /**
+ * 缓存类型
+ */
+ private CacheType type = CacheType.DEFAULT;
+
+ /**
+ * 缓存前缀
+ *
+ * 目前仅 {@link #type CacheType.REDIS} 缓存生效(默认:{@code JUSTAUTH::STATE::})
+ *
+ * 目前仅 {@link #type CacheType.REDIS} 缓存生效(默认:3分钟)
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.auth.justauth.autoconfigure;
+
+import me.zhyd.oauth.config.AuthConfig;
+import me.zhyd.oauth.config.AuthSource;
+import me.zhyd.oauth.request.AuthRequest;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * JustAuth 扩展配置属性
+ *
+ * @author yangkai.shen
+ * @author Charles7c
+ * @since 2.15.0
+ */
+public class JustAuthExtendProperties {
+
+ /**
+ * 枚举类全路径
+ */
+ private Class extends AuthSource> enumClass;
+
+ /**
+ * 扩展请求配置
+ */
+ private Map
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.auth.justauth.autoconfigure;
+
+import java.net.Proxy;
+import java.util.Map;
+
+/**
+ * JustAuth HTTP 配置属性
+ *
+ * @author yangkai.shen
+ * @author Charles7c
+ * @since 2.15.0
+ */
+public class JustAuthHttpProperties {
+
+ /**
+ * 超时时间(单位:毫秒)
+ */
+ private int timeout;
+
+ /**
+ * 代理配置
+ */
+ private Map
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.auth.justauth.autoconfigure;
+
+import me.zhyd.oauth.config.AuthConfig;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
+import top.continew.starter.core.constant.PropertiesConstants;
+
+import java.util.Map;
+
+/**
+ * JustAuth 配置属性
+ *
+ * @author yangkai.shen
+ * @author Charles7c
+ * @since 2.15.0
+ */
+@ConfigurationProperties(PropertiesConstants.AUTH_JUSTAUTH)
+public class JustAuthProperties {
+
+ /**
+ * 是否启用
+ */
+ private boolean enabled = true;
+
+ /**
+ * 第三方平台配置
+ */
+ private Map
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package top.continew.starter.auth.justauth.autoconfigure;
+
+import me.zhyd.oauth.cache.AuthDefaultStateCache;
+import me.zhyd.oauth.cache.AuthStateCache;
+import org.redisson.client.RedisClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.ResolvableType;
+import top.continew.starter.auth.justauth.state.RedisAuthStateCache;
+import top.continew.starter.core.constant.PropertiesConstants;
+
+/**
+ * JustAuth 缓存配置
+ *
+ * @author yangkai.shen
+ * @author Charles7c
+ * @since 2.15.0
+ */
+abstract class JustAuthStateCacheConfiguration {
+
+ private static final Logger log = LoggerFactory.getLogger(JustAuthStateCacheConfiguration.class);
+
+ /**
+ * Redis 缓存
+ */
+ @ConditionalOnClass(RedisClient.class)
+ @ConditionalOnMissingBean(AuthStateCache.class)
+ @ConditionalOnProperty(prefix = PropertiesConstants.AUTH_JUSTAUTH, name = "cache.type", havingValue = "redis")
+ static class Redis {
+ static {
+ log.debug("[ContiNew Starter] - Auto Configuration 'JustAuth-AuthStateCache-Redis' completed initialization.");
+ }
+
+ @Bean
+ public AuthStateCache authStateCache(JustAuthProperties properties) {
+ return new RedisAuthStateCache(properties.getCache());
+ }
+ }
+
+ /**
+ * 默认缓存
+ */
+ @ConditionalOnMissingBean(AuthStateCache.class)
+ @ConditionalOnProperty(prefix = PropertiesConstants.AUTH_JUSTAUTH, name = "cache.type", havingValue = "default", matchIfMissing = true)
+ static class Default {
+ static {
+ log.debug("[ContiNew Starter] - Auto Configuration 'JustAuth-AuthStateCache-Default' completed initialization.");
+ }
+
+ @Bean
+ public AuthStateCache authStateCache() {
+ return AuthDefaultStateCache.INSTANCE;
+ }
+ }
+
+ /**
+ * 自定义缓存
+ */
+ @ConditionalOnProperty(prefix = PropertiesConstants.AUTH_JUSTAUTH, name = "cache.type", havingValue = "custom")
+ static class Custom {
+ static {
+ log.debug("[ContiNew Starter] - Auto Configuration 'JustAuth-AuthStateCache-Custom' completed initialization.");
+ }
+
+ @Bean
+ @ConditionalOnMissingBean(AuthStateCache.class)
+ public AuthStateCache authStateCache() {
+ if (log.isErrorEnabled()) {
+ log.error("Consider defining a bean of type '{}' in your configuration.", ResolvableType
+ .forClass(AuthStateCache.class));
+ }
+ throw new NoSuchBeanDefinitionException(AuthStateCache.class);
+ }
+ }
+}
diff --git a/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/continew/starter/auth/justauth/core/AuthStateCacheRedisDefaultImpl.java b/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/continew/starter/auth/justauth/state/RedisAuthStateCache.java
similarity index 68%
rename from continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/continew/starter/auth/justauth/core/AuthStateCacheRedisDefaultImpl.java
rename to continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/continew/starter/auth/justauth/state/RedisAuthStateCache.java
index 632f4583..3d40ce1f 100644
--- a/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/continew/starter/auth/justauth/core/AuthStateCacheRedisDefaultImpl.java
+++ b/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/continew/starter/auth/justauth/state/RedisAuthStateCache.java
@@ -14,22 +14,27 @@
* limitations under the License.
*/
-package top.continew.starter.auth.justauth.core;
+package top.continew.starter.auth.justauth.state;
import me.zhyd.oauth.cache.AuthStateCache;
+import top.continew.starter.auth.justauth.autoconfigure.JustAuthCacheProperties;
import top.continew.starter.cache.redisson.util.RedisUtils;
import java.time.Duration;
/**
- * 默认 State 缓存 Redis 实现
+ * Redis State 缓存实现
*
* @author Charles7c
* @since 1.0.0
*/
-public class AuthStateCacheRedisDefaultImpl implements AuthStateCache {
+public class RedisAuthStateCache implements AuthStateCache {
- private static final String KEY_PREFIX = "SOCIAL_AUTH_STATE";
+ public final JustAuthCacheProperties cacheProperties;
+
+ public RedisAuthStateCache(JustAuthCacheProperties cacheProperties) {
+ this.cacheProperties = cacheProperties;
+ }
/**
* 存入缓存
@@ -39,8 +44,7 @@ public class AuthStateCacheRedisDefaultImpl implements AuthStateCache {
*/
@Override
public void cache(String key, String value) {
- // 参考:在 JustAuth 中,内置了一个基于 map 的 state 缓存器,默认缓存有效期为 3 分钟
- RedisUtils.set(RedisUtils.formatKey(KEY_PREFIX, key), value, Duration.ofMinutes(3));
+ this.cache(key, value, cacheProperties.getTimeout().toMillis());
}
/**
@@ -52,7 +56,7 @@ public class AuthStateCacheRedisDefaultImpl implements AuthStateCache {
*/
@Override
public void cache(String key, String value, long timeout) {
- RedisUtils.set(RedisUtils.formatKey(KEY_PREFIX, key), value, Duration.ofMillis(timeout));
+ RedisUtils.set(RedisUtils.formatKey(cacheProperties.getPrefix(), key), value, Duration.ofMillis(timeout));
}
/**
@@ -63,7 +67,7 @@ public class AuthStateCacheRedisDefaultImpl implements AuthStateCache {
*/
@Override
public String get(String key) {
- return RedisUtils.get(RedisUtils.formatKey(KEY_PREFIX, key));
+ return RedisUtils.get(RedisUtils.formatKey(cacheProperties.getPrefix(), key));
}
/**
@@ -74,6 +78,6 @@ public class AuthStateCacheRedisDefaultImpl implements AuthStateCache {
*/
@Override
public boolean containsKey(String key) {
- return RedisUtils.exists(RedisUtils.formatKey(KEY_PREFIX, key));
+ return RedisUtils.exists(RedisUtils.formatKey(cacheProperties.getPrefix(), key));
}
}
\ No newline at end of file
diff --git a/continew-starter-auth/continew-starter-auth-justauth/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/continew-starter-auth/continew-starter-auth-justauth/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
index 48a9ed1d..ae821c93 100644
--- a/continew-starter-auth/continew-starter-auth-justauth/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+++ b/continew-starter-auth/continew-starter-auth-justauth/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -1,2 +1 @@
-top.continew.starter.auth.justauth.autoconfigure.JustAuthAutoConfiguration
-com.xkcoding.justauth.autoconfigure.JustAuthAutoConfiguration
\ No newline at end of file
+top.continew.starter.auth.justauth.autoconfigure.JustAuthAutoConfiguration
\ No newline at end of file
diff --git a/continew-starter-core/src/main/java/top/continew/starter/core/constant/PropertiesConstants.java b/continew-starter-core/src/main/java/top/continew/starter/core/constant/PropertiesConstants.java
index 5eb3f7cf..5b2b6c6f 100644
--- a/continew-starter-core/src/main/java/top/continew/starter/core/constant/PropertiesConstants.java
+++ b/continew-starter-core/src/main/java/top/continew/starter/core/constant/PropertiesConstants.java
@@ -49,6 +49,11 @@ public class PropertiesConstants {
*/
public static final String WEB_RESPONSE = WEB + StringConstants.DOT + "response";
+ /**
+ * 认证-JustAuth 配置
+ */
+ public static final String AUTH_JUSTAUTH = CONTINEW_STARTER + StringConstants.DOT + "justauth";
+
/**
* 加密配置
*/
diff --git a/continew-starter-dependencies/pom.xml b/continew-starter-dependencies/pom.xml
index 6f173371..5ff171a2 100644
--- a/continew-starter-dependencies/pom.xml
+++ b/continew-starter-dependencies/pom.xml
@@ -144,17 +144,6 @@