commit 78d8dccad80635168fc61707d63f55bcdbde9fa1
Author: Yangkai.Shen <237497819@qq.com>
Date: Mon Jul 22 15:23:07 2019 +0800
:sparkles: justauth-spring-boot-starter 完成~
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..3d1c15e
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,19 @@
+# JustAuth 开发组IDE 编辑器标准
+root = true
+
+# 空格替代Tab缩进在各种编辑工具下效果一致
+[*]
+indent_style = space
+indent_size = 2
+charset = utf-8
+end_of_line = lf
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.java]
+indent_size = 4
+
+[*.md]
+insert_final_newline = false
+trim_trailing_whitespace = false
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ae3f179
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,30 @@
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rarp
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+# exclude idea files
+.idea
+*.iml
+*.sh
+
+target
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..95e60c0
--- /dev/null
+++ b/README.md
@@ -0,0 +1,120 @@
+# justauth-spring-boot-starter
+
+> Spring Boot 集成 JustAuth 的最佳实践~
+
+## 快速开始
+
+- 因为暂时没有发布至中央仓库,因此需要体验的童鞋暂时使用我的私服玩儿吧~ 在 `pom.xml` 中添加以下内容
+
+```xml
+
+ * 测试 Controller + *
+ * + * @author yangkai.shen + * @date Created in 2019-07-22 11:17 + */ +@RestController +@RequestMapping("/oauth") +@RequiredArgsConstructor(onConstructor_ = @Autowired) +public class TestController { + private final AuthRequestFactory factory; + + @GetMapping("/login/qq") + public void login(HttpServletResponse response) throws IOException { + AuthRequest authRequest = factory.get(AuthSource.QQ); + response.sendRedirect(authRequest.authorize()); + } + + @RequestMapping("/qq/callback") + public AuthResponse login(AuthCallback callback) { + AuthRequest authRequest = factory.get(AuthSource.QQ); + AuthResponse response = authRequest.login(callback); + // 移除校验通过的state + AuthState.delete(AuthSource.QQ); + return response; + } +} +``` + +## 附录 + +`justauth` 配置列表 + +| 属性名 | 类型 | 默认值 | 可选项 | 描述 | +| ------------------ | ------------------------------------------------------------ | ------ | ---------- | ----------------- | +| `justauth.enabled` | `boolean` | true | true/false | 是否启用 JustAuth | +| `justauth.type` | `java.util.Map+ * AuthRequest工厂类 + *
+ * + * @author yangkai.shen + * @date Created in 2019-07-22 14:21 + */ +@RequiredArgsConstructor +public class AuthRequestFactory { + private final JustAuthProperties properties; + + /** + * 返回AuthRequest对象 + * + * @param source {@link AuthSource} + * @return {@link AuthRequest} + */ + public AuthRequest get(AuthSource source) { + switch (source) { + case GITHUB: + return new AuthGithubRequest(properties.getType().get(source)); + case WEIBO: + return new AuthWeiboRequest(properties.getType().get(source)); + case GITEE: + return new AuthGiteeRequest(properties.getType().get(source)); + case DINGTALK: + return new AuthDingTalkRequest(properties.getType().get(source)); + case BAIDU: + return new AuthBaiduRequest(properties.getType().get(source)); + case CSDN: + return new AuthCsdnRequest(properties.getType().get(source)); + case CODING: + return new AuthCodingRequest(properties.getType().get(source)); + case TENCENT_CLOUD: + return new AuthTencentCloudRequest(properties.getType().get(source)); + case OSCHINA: + return new AuthOschinaRequest(properties.getType().get(source)); + case ALIPAY: + return new AuthAlipayRequest(properties.getType().get(source)); + case QQ: + return new AuthQqRequest(properties.getType().get(source)); + case WECHAT: + return new AuthWeChatRequest(properties.getType().get(source)); + case TAOBAO: + return new AuthTaobaoRequest(properties.getType().get(source)); + case GOOGLE: + return new AuthGoogleRequest(properties.getType().get(source)); + case FACEBOOK: + return new AuthFacebookRequest(properties.getType().get(source)); + case DOUYIN: + return new AuthDouyinRequest(properties.getType().get(source)); + case LINKEDIN: + return new AuthLinkedinRequest(properties.getType().get(source)); + case MICROSOFT: + return new AuthMicrosoftRequest(properties.getType().get(source)); + case MI: + return new AuthMiRequest(properties.getType().get(source)); + case TOUTIAO: + return new AuthToutiaoRequest(properties.getType().get(source)); + case TEAMBITION: + return new AuthTeambitionRequest(properties.getType().get(source)); + case RENREN: + return new AuthRenrenRequest(properties.getType().get(source)); + case PINTEREST: + return new AuthPinterestRequest(properties.getType().get(source)); + case STACK_OVERFLOW: + return new AuthStackOverflowRequest(properties.getType().get(source)); + default: + return null; + } + } +} diff --git a/src/main/java/com/xkcoding/justauth/JustAuthAutoConfiguration.java b/src/main/java/com/xkcoding/justauth/JustAuthAutoConfiguration.java new file mode 100644 index 0000000..3bc00df --- /dev/null +++ b/src/main/java/com/xkcoding/justauth/JustAuthAutoConfiguration.java @@ -0,0 +1,27 @@ +package com.xkcoding.justauth; + +import com.xkcoding.justauth.properties.JustAuthProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + *+ * JustAuth 自动装配类 + *
+ * + * @author yangkai.shen + * @date Created in 2019-07-22 10:52 + */ +@Configuration +@EnableConfigurationProperties(JustAuthProperties.class) +public class JustAuthAutoConfiguration { + + @Bean + @ConditionalOnProperty(prefix = "justauth", value = "enabled", havingValue = "true", matchIfMissing = true) + public AuthRequestFactory authRequestFactory(JustAuthProperties properties) { + return new AuthRequestFactory(properties); + } + +} diff --git a/src/main/java/com/xkcoding/justauth/properties/JustAuthProperties.java b/src/main/java/com/xkcoding/justauth/properties/JustAuthProperties.java new file mode 100644 index 0000000..bc64b35 --- /dev/null +++ b/src/main/java/com/xkcoding/justauth/properties/JustAuthProperties.java @@ -0,0 +1,34 @@ +package com.xkcoding.justauth.properties; + +import lombok.Getter; +import lombok.Setter; +import me.zhyd.oauth.config.AuthConfig; +import me.zhyd.oauth.config.AuthSource; +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.HashMap; +import java.util.Map; + +/** + *+ * JustAuth自动装配配置类 + *
+ * + * @author yangkai.shen + * @date Created in 2019-07-22 10:59 + */ +@Getter +@Setter +@ConfigurationProperties(prefix = "justauth") +public class JustAuthProperties { + /** + * 是否启用 JustAuth + */ + private boolean enabled; + + /** + * JustAuth 配置 + */ + private Map