build.gradle
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
application-oauth.properties
# 사용자인증정보 > client ID/PW 추가
spring.security.oauth2.client.registration.google.client-id=발급ID
spring.security.oauth2.client.registration.google.client-secret=발급PW
spring.security.oauth2.client.registration.google.scope=email
application.properties
spring.profiles.include=oauth
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/sample/all").permitAll()
.antMatchers("/sample/ex*").permitAll()
.antMatchers("/sample/member").hasRole("USER");
http.formLogin(); // 인가 or 인증에 문제 시 로그인 화면 반환
http.csrf().disable(); // csrf 토큰 비활성화
http.oauth2Login(); // O Auth 로그인 추가
http.logout(); // invalidatedHttpSession() deleteCookies() 쿠키나 세션을 무효화 시키는 설정 추가 가능
return http.build();
}