如何使用Github作为认证方配置Spring Boot 2 Security5集成的OAuth2登录到我们自己的工程项目------范例2

本篇范例在范例1的基础上持续集成扩展

我们需要登录https://github.com  点击settings 然后Register a new OAuth application 生成client-id和client-secret

我们只需要修改OAuth2LoginConfig.java和application.yml文件即可

/opt/coding/spring-boot2-oauth2-security5/src/main/java/com/contoso/config/OAuth2LoginConfig.java

package com.contoso.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
public class OAuth2LoginConfig {

	@EnableWebSecurity
	public static class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {

		@Override
		protected void configure(HttpSecurity http) throws Exception {
			http
				.authorizeRequests()
				.anyRequest().authenticated()
				.and()
				.oauth2Login();
		}
	}
	
}

/opt/coding/spring-boot2-oauth2-security5/src/main/resources/application.yml

server:
  port: 8080

logging:
  level:
    root: INFO
    org.springframework.web: INFO
    org.springframework.security: INFO
#    org.springframework.boot.autoconfigure: DEBUG

spring:
  thymeleaf:
    cache: false
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: 212269349981-v8oa5coeuali2tufmh0nm41q9k6geet7.apps.googleusercontent.com
            client-secret: CqLWmSzFg83Jj-MyAtRVkUH6
            client-name: Google Login
          github:
            client-id: 5b81d1b07a5ff382f23a
            client-secret: 575df7f247cbd319f3b83c3e8593f8cea9559d61
            client-name: Github Login

阅读更多
个人分类: OAuth2
上一篇如何使用Google作为认证方配置Spring Boot 2 Security5集成的OAuth2登录我们自己的工程项目------范例1
下一篇如何使用okta作为认证方配置Spring Boot 2 Security5集成的OAuth2登录到我们自己的工程项目------范例3
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭