Browse Source

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

pull/1/head
Yangkai.Shen 5 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>
<groupId>me.zhyd.oauth</groupId>
<artifactId>JustAuth</artifactId>
<version>1.0.1</version>
<version>1.2.0</version>
</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 配置
*/
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.request.AuthGithubRequest;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.request.AuthWeChatRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -66,6 +67,8 @@ public class OauthController {
switch (authSource) {
case GITHUB:
return getGithubAuthRequest();
case WECHAT:
return getWechatAuthRequest();
default:
throw new RuntimeException("暂不支持的第三方登录");
}
@@ -75,6 +78,10 @@ public class OauthController {
return new AuthGithubRequest(buildAuthConfig(properties.getGithub()));
}

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

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


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

@@ -7,4 +7,8 @@ oauth:
github:
client-id: 2d25a70d12e3d5f01086
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