Spring Security——简单第三方OAuth2登录自动配置——GitHub登录DEMO

GitHub OAuth2 APP申请

https://github.com/settings/applications/new 

Maven

        <!--Spring Security-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <!--Spring Security OAuth2-->
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.4.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth.boot</groupId>
            <artifactId>spring-security-oauth2-autoconfigure</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>	

解决方案

 application.yml配置文件

security:
 oauth2:
  client:
   client-id:
   client-secret:
   accessTokenUri: https://github.com/login/oauth/access_token
   userAuthorizationUri: https://github.com/login/oauth/authorize
   clientAuthenticationScheme: form
   registered-redirect-uri: ${site.baseUrl}/github_login
   use-current-uri: false
  resource:
   userInfoUri: https://api.github.com/user
  sso:
   login-path: /github_login

 

参考文章

https://www.jb51.net/article/127137.htm

https://www.cnblogs.com/guos/p/11728229.html

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页