diff --git a/spring-boot-demo-social/README.md b/spring-boot-demo-social/README.md
index d91e578..31195bd 100644
--- a/spring-boot-demo-social/README.md
+++ b/spring-boot-demo-social/README.md
@@ -225,23 +225,283 @@ $ nginx -s reload
### 2.1. pom.xml
-
+```xml
+
+
+ * 第三方登录配置 + *
+ * + * @package: com.xkcoding.oauth.config.props + * @description: 第三方登录配置 + * @author: yangkai.shen + * @date: Created in 2019-05-17 15:33 + * @copyright: Copyright (c) 2019 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Data +@Component +@ConfigurationProperties(prefix = "oauth") +public class OAuthProperties { + /** + * QQ 配置 + */ + private AuthConfig qq; + + /** + * github 配置 + */ + private AuthConfig github; + + /** + * 微信 配置 + */ + private AuthConfig wechat; + + /** + * Google 配置 + */ + private AuthConfig google; + + /** + * Microsoft 配置 + */ + private AuthConfig microsoft; + + /** + * Mi 配置 + */ + private AuthConfig mi; +} +``` ### 2.4. OauthController.java +```java +/** + *+ * 第三方登录 Controller + *
+ * + * @package: com.xkcoding.oauth.controller + * @description: 第三方登录 Controller + * @author: yangkai.shen + * @date: Created in 2019-05-17 10:07 + * @copyright: Copyright (c) 2019 + * @version: V1.0 + * @modified: yangkai.shen + */ +@RestController +@RequestMapping("/oauth") +@RequiredArgsConstructor(onConstructor_ = @Autowired) +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") + .set("Microsoft 登录", "http://oauth.xkcoding.com/demo/oauth/login/microsoft") + .set("小米登录", "http://oauth.xkcoding.com/demo/oauth/login/mi"); + } + + /** + * 登录 + * + * @param oauthType 第三方登录类型 + * @param response response + * @throws IOException + */ + @RequestMapping("/login/{oauthType}") + public void renderAuth(@PathVariable String oauthType, HttpServletResponse response) throws IOException { + AuthRequest authRequest = getAuthRequest(oauthType); + response.sendRedirect(authRequest.authorize()); + } + + /** + * 登录成功后的回调 + * + * @param oauthType 第三方登录类型 + * @param code 携带的授权码 + * @return 登录成功后的信息 + */ + @RequestMapping("/{oauthType}/callback") + public AuthResponse login(@PathVariable String oauthType, String code) { + AuthRequest authRequest = getAuthRequest(oauthType); + return authRequest.login(code); + } + + 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(); + case MICROSOFT: + return getMicrosoftAuthRequest(); + case MI: + return getMiAuthRequest(); + default: + throw new RuntimeException("暂不支持的第三方登录"); + } + } + + private AuthRequest getQqAuthRequest() { + return new AuthQqRequest(properties.getQq()); + } + + private AuthRequest getGithubAuthRequest() { + return new AuthGithubRequest(properties.getGithub()); + } + + private AuthRequest getWechatAuthRequest() { + return new AuthWeChatRequest(properties.getWechat()); + } + + private AuthRequest getGoogleAuthRequest() { + return new AuthGoogleRequest(properties.getGoogle()); + } + private AuthRequest getMicrosoftAuthRequest() { + return new AuthMicrosoftRequest(properties.getMicrosoft()); + } + + private AuthRequest getMiAuthRequest() { + return new AuthMiRequest(properties.getMi()); + } +} +``` ## 3. 运行方式 +打开浏览器,输入 http://oauth.xkcoding.com/demo/oauth ,点击各个登录方式自行测试。 + +> `Google 登录,有可能因为祖国的强大导致测试失败,自行解决~` :kissing_smiling_eyes: +![image-20190617154343815](assets/image-20190617154343815.png) ## 参考 diff --git a/spring-boot-demo-social/assets/image-20190617154343815.png b/spring-boot-demo-social/assets/image-20190617154343815.png new file mode 100644 index 0000000..6c911fb Binary files /dev/null and b/spring-boot-demo-social/assets/image-20190617154343815.png differ