Browse Source

spring-boot-demo-oauth 微信 登录完成

pull/1/head
Yangkai.Shen 6 years ago
parent
commit
e8e6af3a8f
4 changed files with 14 additions and 2 deletions
  1. +1
    -1
      spring-boot-demo-oauth/pom.xml
  2. +1
    -0
      spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/config/props/OAuthProperties.java
  3. +7
    -0
      spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/controller/OauthController.java
  4. +5
    -1
      spring-boot-demo-oauth/src/main/resources/application.yml

+ 1
- 1
spring-boot-demo-oauth/pom.xml View File

@@ -49,7 +49,7 @@
<dependency> <dependency>
<groupId>me.zhyd.oauth</groupId> <groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId> <artifactId>JustAuth</artifactId>
<version>1.0.1</version>
<version>1.2.0</version>
</dependency> </dependency>


<dependency> <dependency>


+ 1
- 0
spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/config/props/OAuthProperties.java View File

@@ -26,4 +26,5 @@ public class OAuthProperties {
* github 配置 * github 配置
*/ */
private CommonProperties github; private CommonProperties github;
private CommonProperties wechat;
} }

+ 7
- 0
spring-boot-demo-oauth/src/main/java/com/xkcoding/oauth/controller/OauthController.java View File

@@ -8,6 +8,7 @@ import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthSource; import me.zhyd.oauth.model.AuthSource;
import me.zhyd.oauth.request.AuthGithubRequest; import me.zhyd.oauth.request.AuthGithubRequest;
import me.zhyd.oauth.request.AuthRequest; import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.request.AuthWeChatRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@@ -66,6 +67,8 @@ public class OauthController {
switch (authSource) { switch (authSource) {
case GITHUB: case GITHUB:
return getGithubAuthRequest(); return getGithubAuthRequest();
case WECHAT:
return getWechatAuthRequest();
default: default:
throw new RuntimeException("暂不支持的第三方登录"); throw new RuntimeException("暂不支持的第三方登录");
} }
@@ -75,6 +78,10 @@ public class OauthController {
return new AuthGithubRequest(buildAuthConfig(properties.getGithub())); return new AuthGithubRequest(buildAuthConfig(properties.getGithub()));
} }


private AuthRequest getWechatAuthRequest() {
return new AuthWeChatRequest(buildAuthConfig(properties.getWechat()));
}

private AuthConfig buildAuthConfig(CommonProperties properties) { private AuthConfig buildAuthConfig(CommonProperties properties) {
return AuthConfig.builder() return AuthConfig.builder()
.clientId(properties.getClientId()) .clientId(properties.getClientId())


+ 5
- 1
spring-boot-demo-oauth/src/main/resources/application.yml View File

@@ -7,4 +7,8 @@ oauth:
github: github:
client-id: 2d25a70d12e3d5f01086 client-id: 2d25a70d12e3d5f01086
client-secret: 5a2919b5fe911567343aea2ccc7a5ad7871306d1 client-secret: 5a2919b5fe911567343aea2ccc7a5ad7871306d1
redirect-uri: http://oauth.xkcoding.com/demo/oauth/github/callback
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

Loading…
Cancel
Save