728x90
OAuth 2.0 로그인 페이지 자동 생성

- 기본적으로 OAuth 2.0 로그인 페이지는 DefaultLoginPageGeneratingFilter 가 자동으로 생성해 준다
- 이 디폴트 로그인 페이지는 OAuth 2.0 클라이언트명을 보여준다
- 링크를 누르면 인가 요청을 (또는 OAuth 2.0 로그인을) 시작할 수 있다
-
요청 매핑 Url
-
RequestMatcher : /oauth2/authorization/{registrationId}*
-
디폴트 로그인 페이지를 재정의하려면 oauth2Login().loginPage() 를 사용하면 된다
-
TEST
DefaultLoginPage 이동
@EnableWebSecurity
public class OAuth2ClientConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(authRequest -> authRequest
.anyRequest().authenticated());
http.oauth2Login(Customizer.withDefaults());
return http.build();
}
}

- defaultLoginPage로 이동한다.
- 로그인하고자 하는 클라이언트 클릭 시 해당 클라이언트 로그인 화면으로 이동한다.
CustomLoginPage 이동
@EnableWebSecurity
public class OAuth2ClientConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(authRequest -> authRequest
.antMatchers("/loginPage").permitAll()
.anyRequest().authenticated());
http.oauth2Login(oauth2 -> oauth2.loginPage("/loginPage"));//여기서 Customizer한 설정을 할 수 있다.
return http.build();
}
}
loginController
@RestController
public class LoginController {
@GetMapping("/loginPage")
public String loginPage() {
return "loginPage";
}
}
- customLoginPage로 이동
728x90
'스프링 시큐리티 OAuth2 > OAuth2LoginConfigurer 초기화 이해' 카테고리의 다른 글
| OAuth2 로그인 구현 - UserInfo 엔드포인트 요청하기 (0) | 2023.01.22 |
|---|---|
| OAuth2 로그인 구현 - Oauth 2.0 User 모델 소개 (0) | 2023.01.17 |
| OAuth2 로그인 구현 - Access Token 교환하기 (0) | 2023.01.17 |
| OAuth2 로그인 구현 - Authorization Code 요청하기 (0) | 2023.01.17 |
| OAuth2LoginConfigurer 초기화 이해 (0) | 2023.01.16 |