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๋ฐํ

๊ถํ ๋ถ์ฌ ์ ํ์ ๋ฐ๋ฅธ ์ฝ๋ ํ๋ฆ
Last updated