TokenEndpoint
Spring Authorization Server - 엔드포인트 프로토콜
OAuth 2.0 Token Endpoint
OAuth2TokenEndpointConfigurer
OAuth2 토큰 엔드포인트에 대한 사용자 정의 할 수 있는 기능을 제공한다.
OAuth2 토큰 요청에 대한 전처리, 기본 처리 및 후처리 로직을 커스텀하게 구현할 수 있도록 API를 지원한다.
OAuth2TokenEndpointFilter를 구성하고 이를 OAuth2 인증 서버SecurityFilterChain빈에 등록한다.지원되는 권한 부여 유형은
authorization_code,refresh_token,client_credentials,device_code이다.
OAuth2TokenEndpointFilter
클라이언트의 토큰 요청을 처리하는 필터이며 다음과 같은 기본값으로 구성된다.
DelegatingAuthenticationConverter - 각 특정 유형의
AuthenticationConverter를 호출해서 처리를 위임한다.OAuth2AuthorizationCodeAuthenticationConverterOAuth2RefreshTokenAuthenticationConverterOAuth2ClientCredentialsAuthenticationConverterOAuth2DeviceCodeAuthenticationConverter각 컨버터는
HttpServletRequest정보를~~AuthenticationToken으로 변환하여 반환한다.
AuthenticationProviders
OAuth2AuthorizationCodeAuthenticationProviderRefreshTokenAuthenticationProviderClientCredentialsAuthenticationProviderOAuth2DeviceCodeAuthenticationProvider권한 부여 유형에 따라 토큰을 발행하는
AuthenticationProvider구현체 들이다.
AuthenticationSuccessHandler
인증된
OAuth2AccessTokenAuthenticationToken을 처리하는 내부 구현체로 인증 토큰을 사용하여OAuth2AccessTokenResponse를 반환한다.
AuthenticationFailureHandler
OAuth2AuthenticationException과 관련된OAuth2Error응답을 반환한다.
RequestMatcher
토큰 요청 패턴
/oauth2/token, POST
사용자 정의 기능

AuthenticationConverter추가스프링 시큐리티가 관리하는
AuthenticationConverter들을 커스텀하게 변경 가능AuthenticationProvider추가스프링 시큐리티가 관리하는
AuthenticationProvider들을 커스텀하게 변경 가능OAuth2AccessTokenAuthenticationToken을 처리하고OAuth2AccessTokenResponse를 반환하는 데 사용되는 후처리기OAuth2AuthenticationException을 처리하고OAuth2Error응답을 반환하는 데 사용되는 후처리기
클라이언트 인증하기
OAuth2ClientAuthenticationConfigurer
OAuth2 클라이언트 인증을 위한 사용자 정의 기능을 제공한다.
클라이언트 인증 요청에 대한 전처리, 기본 처리 및 후처리 로직을 커스텀하게 구현할 수 있도록 API를 지원한다.
OAuth2ClientAuthenticationFilter를 구성하고 이를 OAuth2 인증 서버SecurityFilterChain빈에 등록한다.지원되는 클라이언트 인증 방법은
client_secret_basic,client_secret_post,private_key_jwt,client_secret_jwt,none(공개 클라이언트)이다.
OAuth2ClientAuthenticationFilter
클라이언트 인증 요청을 처리하는 필터로 다음과 같은 기본값으로 구성된다.
DelegatingAuthenticationConverter
JwtClientAssertionAuthenticationConverter: 클라이언트 요청 방식이 HTTP Basic일 경우 처리ClientSecretBasicAuthenticationConverter: 클라이언트 요청 방식이 POST일 경우 처리ClientSecretPostAuthenticationConverter: 클라이언트 요청 방식이 JWT일 경우 처리PublicClientAuthenticationConverter: 클라이언트 요청 방식이 PKCE일 경우 처리
AuthenticationProviders
JwtClientAssertionAuthenticationProviderClientSecretAuthenticationProviderPublicClientAuthenticationProvider권한 부여 유형에 따라 토큰을 발행하는
AuthenticationProvider구현체들
AuthenticationSuccessHandler
인증된
OAuth2ClientAuthenticationToken을SecurityContext에 저장하는 내부 구현체
AuthenticationFailureHandler
OAuth2AuthenticationException을 사용하여OAuth2Error를 반환하는 내부 구현체
RequestMatcher
토큰 요청 패턴
/oauth2/token POST/oauth2/introspect POST/oauth2/revoke POST/oauth2/device_authorization POST
사용자 정의 기능

AuthenticationConverter추가스프링 시큐리티가 관리하는
AuthenticationConverter들을 커스텀하게 변경 가능AuthenticationProvider추가스프링 시큐리티가 관리하는
AuthenticationProvider들을 커스텀하게 변경 가능OAuth2ClientAuthenticationToken을 처리하는 데 사용되는 후처리기OAuth2AuthenticationException을 처리하고OAuth2Error응답을 반환하는 데 사용되는 후처리기
클라이언트 인증 흐름


필터 체인에 등록된 필터들의 순서를 보면 토큰과 관련된 필터들은 모두
AuthorizationFilter뒤에 있는 것을 확인할 수 있다.즉 토큰을 요청하기 위해서는 클라이언트 인증이 우선적으로 이루어져야 하며, 클라이언트 인증은
OAuth2ClientAuthenticationFilter에서 이루어진다.
1. 임시 코드로 토큰 요청

client_secret_post클라이언트 인증 방식
2. OAuth2ClientAuthenticationFilter -> ClientSecretPostAuthenticationConverter

필요한 정보 추출 후
OAuth2ClientAuthenticationToken생성
3. ProviderManager -> ClientSecretAuthenticationProvider

ClientSecretAuthenticationProvider는client_secret_basic방식과client_secret_post방식을 처리한다.인가 서버에 등록된 클라이언트 정보와 일치하는지 여러가지 정보들을 확인한다.
이후 최종적으로 인증된
OAuth2ClientAuthenticationToken을 반환한다.
4. OAuth2ClientAuthenticationFilter -> onAuthenticationSuccess()

인증객체 저장
5. AuthorizationFilter -> OAuth2TokenEndpointFilter
클라이언트 인증을 마쳤으므로
OAuth2TokenEndpointFilter를 통해 최종OAuth2AccessTokenResponse반환

권한 부여 유형에 따른 코드 흐름
이전 ↩️ - Spring Authorization Server(엔드포인트 프로토콜) - AuthorizationServer Endpoint
다음 ↪️ - Spring Authorization Server(엔드포인트 프로토콜) - Token Introspection Endpoint
Last updated