스프링 시큐리티 OAuth2/OAuth2LoginConfigurer 초기화 이해

OAuth2LoginConfigurer 초기화 이해

webmaster 2023. 1. 16. 19:03
728x90

설정 클래스 생성

설정 클래스 생성(만들지 않으면 시큐리티가 생성)

  • API 설정
    • SecurityFilterChain 타입의 빈을 생성해서 보안 필터를 구성한다
    • HttpSecurity에 있는 oauth2Login()과 oauth2Client() API를 정의하고 빌드한다

OAuth2LoginCOnfigurer 초기화 및 설정

OAuth2LoginCOnfigurer 초기화 및 설정

    • OAuth2LoginAuthenticationFilter(/login/oauth2/code/*)
      • Access token 교환 및 사용자 정보 엔드 포인트 요청 필터
      • Authentication Code 방식을 2단계 방식에서 사용되는 필터(code 값을 통해 token을 얻을 때 사용)
      • clientRegistrationRepository: clientRegistration가 인가 서버의 엔드포인트 정보, URL을 가지고 있기 떄문에 이를 관리하는 repository이다.
      • authorizedClientRepository: client가 인가서버로 부터 권한을 받게 되면 이를 authorizedClient에 저장하고 이를 관리하는 repository이다.
      • authorizedClientRequestRepository : client가 인가서버한테 요청을 보내게 될 때, authorizedClientRequest에 해당 정보를 저장하고 이를 관리하는 repository이다.
    • OAuth2LoginAuthenticationFilter는 총 2가지의 사용자 정보를 가지고 오는 방식이 있다.
      • OAuth2LoginAuthenticationProvider
        • authenticationCodeAuthenticationProvider에서 실제 인가 서버의 통신을 담당한다.
      • OidcAuthorizationCodeAuthenticationProvider
        • openId 프로토콜을 통해 인증 정보를 가지고 온다.
      • 두 값을 비교해서 값이 같은지를 검증한다.
    • DefaultLoginPageGeneratingFilter 
      • 실제 인증을 할 때 필요한 로그인 페이지를 생성해 주는 필터

OAuth2LoginConfigurer

  • 가장 먼저 임시 코드 발급을 받기 위한 필터(Authentication Code 1단계 요청)

  • AuthorizationEndpointConfig = 코드 발급 요청을 할 때, 설정을 관리하는 config
  • RedirectionEndpointConfig = 인가서버에서 클라이언트에게 code를 발급하기 위해 redirect를 하는데 이 정보를 관리하는 config
  • TokenEndpointConfig = AccessToken을 요청할 때 인가서버로 다시 요청하는데 이 정보를 관리하는 config
  • UserInfoEndpointConfig = 토큰을 통해 user정보를 읽어 올때, 설정을 관리하는 config
728x90