diff --git a/spring-boot-demo-oauth/pom.xml b/spring-boot-demo-oauth/pom.xml index 8448b0b..cdb3659 100644 --- a/spring-boot-demo-oauth/pom.xml +++ b/spring-boot-demo-oauth/pom.xml @@ -49,7 +49,7 @@ me.zhyd.oauth JustAuth - 1.2.0 + 1.3.2 diff --git a/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/SpringBootDemoOauthApplication.java b/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/SpringBootDemoOauthApplication.java index 9c8c88f..382a8b1 100644 --- a/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/SpringBootDemoOauthApplication.java +++ b/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/SpringBootDemoOauthApplication.java @@ -2,6 +2,7 @@ package com.xkcoding.oauth; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; /** *

diff --git a/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/config/props/CommonProperties.java b/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/config/props/CommonProperties.java deleted file mode 100644 index bfcc090..0000000 --- a/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/config/props/CommonProperties.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.xkcoding.oauth.config.props; - -import lombok.Data; - -/** - *

- * 通用配置 - *

- * - * @package: com.xkcoding.oauth.config.props - * @description: 通用配置 - * @author: yangkai.shen - * @date: Created in 2019-05-17 16:02 - * @copyright: Copyright (c) 2019 - * @version: V1.0 - * @modified: yangkai.shen - */ -@Data -public class CommonProperties { - /** - * clientId - */ - private String clientId; - /** - * clientSecret - */ - private String clientSecret; - /** - * 成功后的回调 - */ - private String redirectUri; -} diff --git a/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/config/props/OAuthProperties.java b/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/config/props/OAuthProperties.java index 181cf21..0c20571 100644 --- a/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/config/props/OAuthProperties.java +++ b/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/config/props/OAuthProperties.java @@ -22,9 +22,23 @@ import org.springframework.stereotype.Component; @Component @ConfigurationProperties(prefix = "oauth") public class OAuthProperties { + /** + * QQ 配置 + */ + private AuthConfig qq; + /** * github 配置 */ - private CommonProperties github; - private CommonProperties wechat; + private AuthConfig github; + + /** + * 微信 配置 + */ + private AuthConfig wechat; + + /** + * Google 配置 + */ + private AuthConfig google; } diff --git a/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/controller/OauthController.java b/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/controller/OauthController.java index cc1eb0f..3fb789b 100644 --- a/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/controller/OauthController.java +++ b/spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/controller/OauthController.java @@ -1,15 +1,13 @@ package com.xkcoding.oauth.controller; -import com.xkcoding.oauth.config.props.CommonProperties; +import cn.hutool.core.lang.Dict; import com.xkcoding.oauth.config.props.OAuthProperties; import lombok.RequiredArgsConstructor; -import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthSource; -import me.zhyd.oauth.request.AuthGithubRequest; -import me.zhyd.oauth.request.AuthRequest; -import me.zhyd.oauth.request.AuthWeChatRequest; +import me.zhyd.oauth.request.*; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -36,6 +34,18 @@ import java.io.IOException; public class OauthController { private final OAuthProperties properties; + /** + * 登录类型 + */ + @GetMapping + public Dict loginType() { + return Dict.create() + .set("QQ登录", "http://oauth.xkcoding.com/demo/oauth/login/qq") + .set("GitHub登录", "http://oauth.xkcoding.com/demo/oauth/login/github") + .set("微信登录", "http://oauth.xkcoding.com/demo/oauth/login/wechat") + .set("Google登录", "http://oauth.xkcoding.com/demo/oauth/login/google"); + } + /** * 登录 * @@ -65,28 +75,32 @@ public class OauthController { private AuthRequest getAuthRequest(String oauthType) { AuthSource authSource = AuthSource.valueOf(oauthType.toUpperCase()); switch (authSource) { + case QQ: + return getQqAuthRequest(); case GITHUB: return getGithubAuthRequest(); case WECHAT: return getWechatAuthRequest(); + case GOOGLE: + return getGoogleAuthRequest(); default: throw new RuntimeException("暂不支持的第三方登录"); } } + private AuthRequest getQqAuthRequest() { + return new AuthQqRequest(properties.getQq()); + } + private AuthRequest getGithubAuthRequest() { - return new AuthGithubRequest(buildAuthConfig(properties.getGithub())); + return new AuthGithubRequest(properties.getGithub()); } private AuthRequest getWechatAuthRequest() { - return new AuthWeChatRequest(buildAuthConfig(properties.getWechat())); + return new AuthWeChatRequest(properties.getWechat()); } - private AuthConfig buildAuthConfig(CommonProperties properties) { - return AuthConfig.builder() - .clientId(properties.getClientId()) - .clientSecret(properties.getClientSecret()) - .redirectUri(properties.getRedirectUri()) - .build(); + private AuthRequest getGoogleAuthRequest() { + return new AuthGoogleRequest(properties.getGoogle()); } } diff --git a/spring-boot-demo-oauth/src/main/resources/application.yml b/spring-boot-demo-oauth/src/main/resources/application.yml index 376262c..e54ac58 100644 --- a/spring-boot-demo-oauth/src/main/resources/application.yml +++ b/spring-boot-demo-oauth/src/main/resources/application.yml @@ -4,11 +4,19 @@ server: context-path: /demo oauth: + qq: + client-id: 101577785 + client-secret: 1f7d08df5576671a5b799e73cc2d629e + redirect-uri: http://oauth.xkcoding.com/demo/oauth/qq/callback github: client-id: 2d25a70d12e3d5f01086 client-secret: 5a2919b5fe911567343aea2ccc7a5ad7871306d1 redirect-uri: http://oauth.xkcoding.com/demo/oauth/github/callback wechat: - client-id: - client-secret: - redirect-uri: http://oauth.xkcoding.com/demo/oauth/wechat/callback \ No newline at end of file + client-id: wxdcb31cd7f1794ff4 + client-secret: b4e9dc6841ef7d2f520d449bca08ed6d + redirect-uri: http://oauth.xkcoding.com/demo/oauth/wechat/callback + google: + client-id: 716518501517-6dbdkapivhia806vqcjjh9nttj320ie3.apps.googleusercontent.com + client-secret: 9IBornd7w1ALXhxZiDwEf7-E + redirect-uri: http://oauth.xkcoding.com/demo/oauth/google/callback \ No newline at end of file