diff --git a/continew-starter-auth/continew-starter-auth-justauth/pom.xml b/continew-starter-auth/continew-starter-auth-justauth/pom.xml
new file mode 100644
index 00000000..6554e264
--- /dev/null
+++ b/continew-starter-auth/continew-starter-auth-justauth/pom.xml
@@ -0,0 +1,36 @@
+
+
+ * 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.charles7c.continew.starter.auth.justauth.autoconfigure; + +import jakarta.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; +import me.zhyd.oauth.cache.AuthStateCache; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import top.charles7c.continew.starter.auth.justauth.impl.JustAuthStateCacheRedisImpl; + +/** + * JustAuth 自动配置 + * + * @author Charles7c + * @since 1.0.0 + */ +@Slf4j +@AutoConfiguration(after = com.xkcoding.justauth.autoconfigure.JustAuthAutoConfiguration.class) +@ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true) +public class JustAuthAutoConfiguration { + + /** + * 自定义 State 缓存实现 + */ + @Bean + @ConditionalOnProperty(prefix = "justauth.cache", value = "type", havingValue = "custom") + public AuthStateCache authStateCache() { + return new JustAuthStateCacheRedisImpl(); + } + + @PostConstruct + public void postConstruct() { + log.info("[ContiNew Starter] - Auto Configuration 'JustAuth' completed initialization."); + } +} \ No newline at end of file diff --git a/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/charles7c/continew/starter/auth/justauth/impl/JustAuthStateCacheRedisImpl.java b/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/charles7c/continew/starter/auth/justauth/impl/JustAuthStateCacheRedisImpl.java new file mode 100644 index 00000000..f759d558 --- /dev/null +++ b/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/charles7c/continew/starter/auth/justauth/impl/JustAuthStateCacheRedisImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + *
+ * 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.charles7c.continew.starter.auth.justauth.impl;
+
+import me.zhyd.oauth.cache.AuthStateCache;
+import top.charles7c.continew.starter.cache.redisson.util.RedisUtils;
+
+import java.time.Duration;
+
+/**
+ * Just Auth 自定义 State 缓存实现(Redis)
+ *
+ * @author Charles7c
+ * @since 1.0.0
+ */
+public class JustAuthStateCacheRedisImpl implements AuthStateCache {
+
+ private static final String KEY_PREFIX = "SOCIAL_AUTH_STATE";
+
+ /**
+ * 存入缓存
+ *
+ * @param key
+ * key
+ * @param value
+ * 内容
+ */
+ @Override
+ public void cache(String key, String value) {
+ // 参考:在 JustAuth 中,内置了一个基于 map 的 state 缓存器,默认缓存有效期为 3 分钟
+ RedisUtils.set(RedisUtils.formatKey(KEY_PREFIX, key), value,
+ Duration.ofMinutes(3));
+ }
+
+ /**
+ * 存入缓存
+ *
+ * @param key
+ * key
+ * @param value
+ * 内容
+ * @param timeout
+ * 缓存过期时间(毫秒)
+ */
+ @Override
+ public void cache(String key, String value, long timeout) {
+ RedisUtils.set(RedisUtils.formatKey(KEY_PREFIX, key), value,
+ Duration.ofMillis(timeout));
+ }
+
+ /**
+ * 获取缓存内容
+ *
+ * @param key
+ * key
+ * @return 内容
+ */
+ @Override
+ public String get(String key) {
+ return RedisUtils.get(RedisUtils.formatKey(KEY_PREFIX, key));
+ }
+
+ /**
+ * 是否存在 key,如果对应 key 的 value 值已过期,也返回 false
+ *
+ * @param key
+ * key
+ * @return true:存在 key,并且 value 没过期;false:key 不存在或者已过期
+ */
+ @Override
+ public boolean containsKey(String key) {
+ return RedisUtils.hasKey(RedisUtils.formatKey(KEY_PREFIX, 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
new file mode 100644
index 00000000..bbd7cc4f
--- /dev/null
+++ b/continew-starter-auth/continew-starter-auth-justauth/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1,2 @@
+top.charles7c.continew.starter.auth.justauth.autoconfigure.JustAuthAutoConfiguration
+com.xkcoding.justauth.autoconfigure.JustAuthAutoConfiguration
\ No newline at end of file
diff --git a/continew-starter-auth/pom.xml b/continew-starter-auth/pom.xml
index 8e6bcab3..23de50c7 100644
--- a/continew-starter-auth/pom.xml
+++ b/continew-starter-auth/pom.xml
@@ -17,6 +17,7 @@