protocol-endpoints.adoc 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. [[protocol-endpoints]]
  2. = Protocol Endpoints
  3. [[oauth2-authorization-endpoint]]
  4. == OAuth2 Authorization Endpoint
  5. `OAuth2AuthorizationEndpointConfigurer` provides the ability to customize the https://datatracker.ietf.org/doc/html/rfc6749#section-3.1[OAuth2 Authorization endpoint].
  6. It defines extension points that let you customize the pre-processing, main processing, and post-processing logic for https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1[OAuth2 authorization requests].
  7. `OAuth2AuthorizationEndpointConfigurer` provides the following configuration options:
  8. [source,java]
  9. ----
  10. @Bean
  11. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  12. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  13. new OAuth2AuthorizationServerConfigurer();
  14. http.apply(authorizationServerConfigurer);
  15. authorizationServerConfigurer
  16. .authorizationEndpoint(authorizationEndpoint ->
  17. authorizationEndpoint
  18. .authorizationRequestConverter(authorizationRequestConverter) <1>
  19. .authorizationRequestConverters(authorizationRequestConvertersConsumer) <2>
  20. .authenticationProvider(authenticationProvider) <3>
  21. .authenticationProviders(authenticationProvidersConsumer) <4>
  22. .authorizationResponseHandler(authorizationResponseHandler) <5>
  23. .errorResponseHandler(errorResponseHandler) <6>
  24. .consentPage("/oauth2/v1/authorize") <7>
  25. );
  26. return http.build();
  27. }
  28. ----
  29. <1> `authorizationRequestConverter()`: Adds an `AuthenticationConverter` (_pre-processor_) used when attempting to extract an https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1[OAuth2 authorization request] (or consent) from `HttpServletRequest` to an instance of `OAuth2AuthorizationCodeRequestAuthenticationToken` or `OAuth2AuthorizationConsentAuthenticationToken`.
  30. <2> `authorizationRequestConverters()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationConverter``'s allowing the ability to add, remove, or customize a specific `AuthenticationConverter`.
  31. <3> `authenticationProvider()`: Adds an `AuthenticationProvider` (_main processor_) used for authenticating the `OAuth2AuthorizationCodeRequestAuthenticationToken` or `OAuth2AuthorizationConsentAuthenticationToken`.
  32. <4> `authenticationProviders()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationProvider``'s allowing the ability to add, remove, or customize a specific `AuthenticationProvider`.
  33. <5> `authorizationResponseHandler()`: The `AuthenticationSuccessHandler` (_post-processor_) used for handling an "`authenticated`" `OAuth2AuthorizationCodeRequestAuthenticationToken` and returning the https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2[OAuth2AuthorizationResponse].
  34. <6> `errorResponseHandler()`: The `AuthenticationFailureHandler` (_post-processor_) used for handling an `OAuth2AuthorizationCodeRequestAuthenticationException` and returning the https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1[OAuth2Error response].
  35. <7> `consentPage()`: The `URI` of the custom consent page to redirect resource owners to if consent is required during the authorization request flow.
  36. `OAuth2AuthorizationEndpointConfigurer` configures the `OAuth2AuthorizationEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  37. `OAuth2AuthorizationEndpointFilter` is the `Filter` that processes OAuth2 authorization requests (and consents).
  38. `OAuth2AuthorizationEndpointFilter` is configured with the following defaults:
  39. * `*AuthenticationConverter*` -- A `DelegatingAuthenticationConverter` composed of `OAuth2AuthorizationCodeRequestAuthenticationConverter` and `OAuth2AuthorizationConsentAuthenticationConverter`.
  40. * `*AuthenticationManager*` -- An `AuthenticationManager` composed of `OAuth2AuthorizationCodeRequestAuthenticationProvider` and `OAuth2AuthorizationConsentAuthenticationProvider`.
  41. * `*AuthenticationSuccessHandler*` -- An internal implementation that handles an "`authenticated`" `OAuth2AuthorizationCodeRequestAuthenticationToken` and returns the `OAuth2AuthorizationResponse`.
  42. * `*AuthenticationFailureHandler*` -- An internal implementation that uses the `OAuth2Error` associated with the `OAuth2AuthorizationCodeRequestAuthenticationException` and returns the `OAuth2Error` response.
  43. [[oauth2-authorization-endpoint-customizing-authorization-request-validation]]
  44. === Customizing Authorization Request Validation
  45. `OAuth2AuthorizationCodeRequestAuthenticationValidator` is the default validator used for validating specific OAuth2 authorization request parameters used in the Authorization Code Grant.
  46. The default implementation validates the `redirect_uri` and `scope` parameters.
  47. If validation fails, an `OAuth2AuthorizationCodeRequestAuthenticationException` is thrown.
  48. `OAuth2AuthorizationCodeRequestAuthenticationProvider` provides the ability to override the default authorization request validation by supplying a custom authentication validator of type `Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext>` to `setAuthenticationValidator()`.
  49. [TIP]
  50. `OAuth2AuthorizationCodeRequestAuthenticationContext` holds the `OAuth2AuthorizationCodeRequestAuthenticationToken`, which contains the OAuth2 authorization request parameters.
  51. [IMPORTANT]
  52. If validation fails, the authentication validator *MUST* throw `OAuth2AuthorizationCodeRequestAuthenticationException`.
  53. A common use case during the development life cycle phase is to allow for `localhost` in the `redirect_uri` parameter.
  54. The following example shows how to configure `OAuth2AuthorizationCodeRequestAuthenticationProvider` with a custom authentication validator that allows for `localhost` in the `redirect_uri` parameter:
  55. [source,java]
  56. ----
  57. @Bean
  58. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  59. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  60. new OAuth2AuthorizationServerConfigurer();
  61. http.apply(authorizationServerConfigurer);
  62. authorizationServerConfigurer
  63. .authorizationEndpoint(authorizationEndpoint ->
  64. authorizationEndpoint
  65. .authenticationProviders(configureAuthenticationValidator())
  66. );
  67. return http.build();
  68. }
  69. private Consumer<List<AuthenticationProvider>> configureAuthenticationValidator() {
  70. return (authenticationProviders) ->
  71. authenticationProviders.forEach((authenticationProvider) -> {
  72. if (authenticationProvider instanceof OAuth2AuthorizationCodeRequestAuthenticationProvider) {
  73. Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> authenticationValidator =
  74. // Override default redirect_uri validator
  75. new CustomRedirectUriValidator()
  76. // Reuse default scope validator
  77. .andThen(OAuth2AuthorizationCodeRequestAuthenticationValidator.DEFAULT_SCOPE_VALIDATOR);
  78. ((OAuth2AuthorizationCodeRequestAuthenticationProvider) authenticationProvider)
  79. .setAuthenticationValidator(authenticationValidator);
  80. }
  81. });
  82. }
  83. static class CustomRedirectUriValidator implements Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> {
  84. @Override
  85. public void accept(OAuth2AuthorizationCodeRequestAuthenticationContext authenticationContext) {
  86. OAuth2AuthorizationCodeRequestAuthenticationToken authorizationCodeRequestAuthentication =
  87. authenticationContext.getAuthentication();
  88. RegisteredClient registeredClient = authenticationContext.getRegisteredClient();
  89. String requestedRedirectUri = authorizationCodeRequestAuthentication.getRedirectUri();
  90. // Use exact string matching when comparing client redirect URIs against pre-registered URIs
  91. if (!registeredClient.getRedirectUris().contains(requestedRedirectUri)) {
  92. OAuth2Error error = new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST);
  93. throw new OAuth2AuthorizationCodeRequestAuthenticationException(error, null);
  94. }
  95. }
  96. }
  97. ----
  98. [[oauth2-device-authorization-endpoint]]
  99. == OAuth2 Device Authorization Endpoint
  100. `OAuth2DeviceAuthorizationEndpointConfigurer` provides the ability to customize the https://datatracker.ietf.org/doc/html/rfc8628#section-3.1[OAuth2 Device Authorization endpoint].
  101. It defines extension points that let you customize the pre-processing, main processing, and post-processing logic for OAuth2 device authorization requests.
  102. `OAuth2DeviceAuthorizationEndpointConfigurer` provides the following configuration options:
  103. [source,java]
  104. ----
  105. @Bean
  106. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  107. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  108. new OAuth2AuthorizationServerConfigurer();
  109. http.apply(authorizationServerConfigurer);
  110. authorizationServerConfigurer
  111. .deviceAuthorizationEndpoint(deviceAuthorizationEndpoint ->
  112. deviceAuthorizationEndpoint
  113. .deviceAuthorizationRequestConverter(deviceAuthorizationRequestConverter) <1>
  114. .deviceAuthorizationRequestConverters(deviceAuthorizationRequestConvertersConsumer) <2>
  115. .authenticationProvider(authenticationProvider) <3>
  116. .authenticationProviders(authenticationProvidersConsumer) <4>
  117. .deviceAuthorizationResponseHandler(deviceAuthorizationResponseHandler) <5>
  118. .errorResponseHandler(errorResponseHandler) <6>
  119. .verificationUri("/oauth2/v1/device_verification") <7>
  120. );
  121. return http.build();
  122. }
  123. ----
  124. <1> `deviceAuthorizationRequestConverter()`: Adds an `AuthenticationConverter` (_pre-processor_) used when attempting to extract an https://datatracker.ietf.org/doc/html/rfc8628#section-3.1[OAuth2 device authorization request] from `HttpServletRequest` to an instance of `OAuth2DeviceAuthorizationRequestAuthenticationToken`.
  125. <2> `deviceAuthorizationRequestConverters()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationConverter``'s allowing the ability to add, remove, or customize a specific `AuthenticationConverter`.
  126. <3> `authenticationProvider()`: Adds an `AuthenticationProvider` (_main processor_) used for authenticating the `OAuth2DeviceAuthorizationRequestAuthenticationToken`.
  127. <4> `authenticationProviders()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationProvider``'s allowing the ability to add, remove, or customize a specific `AuthenticationProvider`.
  128. <5> `deviceAuthorizationResponseHandler()`: The `AuthenticationSuccessHandler` (_post-processor_) used for handling an "`authenticated`" `OAuth2DeviceAuthorizationRequestAuthenticationToken` and returning the https://datatracker.ietf.org/doc/html/rfc8628#section-3.2[OAuth2DeviceAuthorizationResponse].
  129. <6> `errorResponseHandler()`: The `AuthenticationFailureHandler` (_post-processor_) used for handling an `OAuth2AuthenticationException` and returning the https://datatracker.ietf.org/doc/html/rfc6749#section-5.2[OAuth2Error response].
  130. <7> `verificationUri()`: The `URI` of the custom end-user verification page to direct resource owners to on a secondary device.
  131. `OAuth2DeviceAuthorizationEndpointConfigurer` configures the `OAuth2DeviceAuthorizationEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  132. `OAuth2DeviceAuthorizationEndpointFilter` is the `Filter` that processes OAuth2 device authorization requests.
  133. `OAuth2DeviceAuthorizationEndpointFilter` is configured with the following defaults:
  134. * `*AuthenticationConverter*` -- An `OAuth2DeviceAuthorizationRequestAuthenticationConverter`.
  135. * `*AuthenticationManager*` -- An `AuthenticationManager` composed of `OAuth2DeviceAuthorizationRequestAuthenticationProvider`.
  136. * `*AuthenticationSuccessHandler*` -- An internal implementation that handles an "`authenticated`" `OAuth2DeviceAuthorizationRequestAuthenticationToken` and returns the `OAuth2DeviceAuthorizationResponse`.
  137. * `*AuthenticationFailureHandler*` -- An `OAuth2ErrorAuthenticationFailureHandler` instance that handles the `OAuth2Error` associated with the `OAuth2AuthenticationException` and returns the `OAuth2Error` response.
  138. [[oauth2-device-verification-endpoint]]
  139. == OAuth2 Device Verification Endpoint
  140. `OAuth2DeviceVerificationEndpointConfigurer` provides the ability to customize the https://datatracker.ietf.org/doc/html/rfc8628#section-3.3[OAuth2 Device Verification endpoint] (or "User Interaction").
  141. It defines extension points that let you customize the pre-processing, main processing, and post-processing logic for OAuth2 device verification requests.
  142. `OAuth2DeviceVerificationEndpointConfigurer` provides the following configuration options:
  143. [source,java]
  144. ----
  145. @Bean
  146. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  147. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  148. new OAuth2AuthorizationServerConfigurer();
  149. http.apply(authorizationServerConfigurer);
  150. authorizationServerConfigurer
  151. .deviceVerificationEndpoint(deviceVerificationEndpoint ->
  152. deviceVerificationEndpoint
  153. .deviceVerificationRequestConverter(deviceVerificationRequestConverter) <1>
  154. .deviceVerificationRequestConverters(deviceVerificationRequestConvertersConsumer) <2>
  155. .authenticationProvider(authenticationProvider) <3>
  156. .authenticationProviders(authenticationProvidersConsumer) <4>
  157. .deviceVerificationResponseHandler(deviceVerificationResponseHandler) <5>
  158. .errorResponseHandler(errorResponseHandler) <6>
  159. .consentPage("/oauth2/v1/consent") <7>
  160. );
  161. return http.build();
  162. }
  163. ----
  164. <1> `deviceVerificationRequestConverter()`: Adds an `AuthenticationConverter` (_pre-processor_) used when attempting to extract an https://datatracker.ietf.org/doc/html/rfc8628#section-3.3[OAuth2 device verification request] (or consent) from `HttpServletRequest` to an instance of `OAuth2DeviceVerificationAuthenticationToken` or `OAuth2DeviceAuthorizationConsentAuthenticationToken`.
  165. <2> `deviceVerificationRequestConverters()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationConverter``'s allowing the ability to add, remove, or customize a specific `AuthenticationConverter`.
  166. <3> `authenticationProvider()`: Adds an `AuthenticationProvider` (_main processor_) used for authenticating the `OAuth2DeviceVerificationAuthenticationToken` or `OAuth2DeviceAuthorizationConsentAuthenticationToken`.
  167. <4> `authenticationProviders()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationProvider``'s allowing the ability to add, remove, or customize a specific `AuthenticationProvider`.
  168. <5> `deviceVerificationResponseHandler()`: The `AuthenticationSuccessHandler` (_post-processor_) used for handling an "`authenticated`" `OAuth2DeviceVerificationAuthenticationToken` and directing the resource owner to return to their device.
  169. <6> `errorResponseHandler()`: The `AuthenticationFailureHandler` (_post-processor_) used for handling an `OAuth2AuthenticationException` and returning the error response.
  170. <7> `consentPage()`: The `URI` of the custom consent page to redirect resource owners to if consent is required during the device verification request flow.
  171. `OAuth2DeviceVerificationEndpointConfigurer` configures the `OAuth2DeviceVerificationEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  172. `OAuth2DeviceVerificationEndpointFilter` is the `Filter` that processes OAuth2 device verification requests (and consents).
  173. `OAuth2DeviceVerificationEndpointFilter` is configured with the following defaults:
  174. * `*AuthenticationConverter*` -- A `DelegatingAuthenticationConverter` composed of `OAuth2DeviceVerificationAuthenticationConverter` and `OAuth2DeviceAuthorizationConsentAuthenticationConverter`.
  175. * `*AuthenticationManager*` -- An `AuthenticationManager` composed of `OAuth2DeviceVerificationAuthenticationProvider` and `OAuth2DeviceAuthorizationConsentAuthenticationProvider`.
  176. * `*AuthenticationSuccessHandler*` -- A `SimpleUrlAuthenticationSuccessHandler` that handles an "`authenticated`" `OAuth2DeviceVerificationAuthenticationToken` and redirects the user to a success page (`/?success`).
  177. * `*AuthenticationFailureHandler*` -- An internal implementation that uses the `OAuth2Error` associated with the `OAuth2AuthenticationException` and returns the `OAuth2Error` response.
  178. [[oauth2-token-endpoint]]
  179. == OAuth2 Token Endpoint
  180. `OAuth2TokenEndpointConfigurer` provides the ability to customize the https://datatracker.ietf.org/doc/html/rfc6749#section-3.2[OAuth2 Token endpoint].
  181. It defines extension points that let you customize the pre-processing, main processing, and post-processing logic for https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3[OAuth2 access token requests].
  182. `OAuth2TokenEndpointConfigurer` provides the following configuration options:
  183. [source,java]
  184. ----
  185. @Bean
  186. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  187. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  188. new OAuth2AuthorizationServerConfigurer();
  189. http.apply(authorizationServerConfigurer);
  190. authorizationServerConfigurer
  191. .tokenEndpoint(tokenEndpoint ->
  192. tokenEndpoint
  193. .accessTokenRequestConverter(accessTokenRequestConverter) <1>
  194. .accessTokenRequestConverters(accessTokenRequestConvertersConsumer) <2>
  195. .authenticationProvider(authenticationProvider) <3>
  196. .authenticationProviders(authenticationProvidersConsumer) <4>
  197. .accessTokenResponseHandler(accessTokenResponseHandler) <5>
  198. .errorResponseHandler(errorResponseHandler) <6>
  199. );
  200. return http.build();
  201. }
  202. ----
  203. <1> `accessTokenRequestConverter()`: Adds an `AuthenticationConverter` (_pre-processor_) used when attempting to extract an https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3[OAuth2 access token request] from `HttpServletRequest` to an instance of `OAuth2AuthorizationGrantAuthenticationToken`.
  204. <2> `accessTokenRequestConverters()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationConverter``'s allowing the ability to add, remove, or customize a specific `AuthenticationConverter`.
  205. <3> `authenticationProvider()`: Adds an `AuthenticationProvider` (_main processor_) used for authenticating the `OAuth2AuthorizationGrantAuthenticationToken`.
  206. <4> `authenticationProviders()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationProvider``'s allowing the ability to add, remove, or customize a specific `AuthenticationProvider`.
  207. <5> `accessTokenResponseHandler()`: The `AuthenticationSuccessHandler` (_post-processor_) used for handling an `OAuth2AccessTokenAuthenticationToken` and returning the https://datatracker.ietf.org/doc/html/rfc6749#section-5.1[`OAuth2AccessTokenResponse`].
  208. <6> `errorResponseHandler()`: The `AuthenticationFailureHandler` (_post-processor_) used for handling an `OAuth2AuthenticationException` and returning the https://datatracker.ietf.org/doc/html/rfc6749#section-5.2[OAuth2Error response].
  209. `OAuth2TokenEndpointConfigurer` configures the `OAuth2TokenEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  210. `OAuth2TokenEndpointFilter` is the `Filter` that processes OAuth2 access token requests.
  211. The supported https://datatracker.ietf.org/doc/html/rfc6749#section-1.3[authorization grant types] are `authorization_code`, `refresh_token`, `client_credentials`, and `urn:ietf:params:oauth:grant-type:device_code`.
  212. `OAuth2TokenEndpointFilter` is configured with the following defaults:
  213. * `*AuthenticationConverter*` -- A `DelegatingAuthenticationConverter` composed of `OAuth2AuthorizationCodeAuthenticationConverter`, `OAuth2RefreshTokenAuthenticationConverter`, `OAuth2ClientCredentialsAuthenticationConverter`, and `OAuth2DeviceCodeAuthenticationConverter`.
  214. * `*AuthenticationManager*` -- An `AuthenticationManager` composed of `OAuth2AuthorizationCodeAuthenticationProvider`, `OAuth2RefreshTokenAuthenticationProvider`, `OAuth2ClientCredentialsAuthenticationProvider`, and `OAuth2DeviceCodeAuthenticationProvider`.
  215. * `*AuthenticationSuccessHandler*` -- An internal implementation that handles an `OAuth2AccessTokenAuthenticationToken` and returns the `OAuth2AccessTokenResponse`.
  216. * `*AuthenticationFailureHandler*` -- An `OAuth2ErrorAuthenticationFailureHandler` instance that handles the `OAuth2Error` associated with the `OAuth2AuthenticationException` and returns the `OAuth2Error` response.
  217. [[oauth2-token-introspection-endpoint]]
  218. == OAuth2 Token Introspection Endpoint
  219. `OAuth2TokenIntrospectionEndpointConfigurer` provides the ability to customize the https://datatracker.ietf.org/doc/html/rfc7662#section-2[OAuth2 Token Introspection endpoint].
  220. It defines extension points that let you customize the pre-processing, main processing, and post-processing logic for https://datatracker.ietf.org/doc/html/rfc7662#section-2.1[OAuth2 introspection requests].
  221. `OAuth2TokenIntrospectionEndpointConfigurer` provides the following configuration options:
  222. [source,java]
  223. ----
  224. @Bean
  225. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  226. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  227. new OAuth2AuthorizationServerConfigurer();
  228. http.apply(authorizationServerConfigurer);
  229. authorizationServerConfigurer
  230. .tokenIntrospectionEndpoint(tokenIntrospectionEndpoint ->
  231. tokenIntrospectionEndpoint
  232. .introspectionRequestConverter(introspectionRequestConverter) <1>
  233. .introspectionRequestConverters(introspectionRequestConvertersConsumer) <2>
  234. .authenticationProvider(authenticationProvider) <3>
  235. .authenticationProviders(authenticationProvidersConsumer) <4>
  236. .introspectionResponseHandler(introspectionResponseHandler) <5>
  237. .errorResponseHandler(errorResponseHandler) <6>
  238. );
  239. return http.build();
  240. }
  241. ----
  242. <1> `introspectionRequestConverter()`: Adds an `AuthenticationConverter` (_pre-processor_) used when attempting to extract an https://datatracker.ietf.org/doc/html/rfc7662#section-2.1[OAuth2 introspection request] from `HttpServletRequest` to an instance of `OAuth2TokenIntrospectionAuthenticationToken`.
  243. <2> `introspectionRequestConverters()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationConverter``'s allowing the ability to add, remove, or customize a specific `AuthenticationConverter`.
  244. <3> `authenticationProvider()`: Adds an `AuthenticationProvider` (_main processor_) used for authenticating the `OAuth2TokenIntrospectionAuthenticationToken`.
  245. <4> `authenticationProviders()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationProvider``'s allowing the ability to add, remove, or customize a specific `AuthenticationProvider`.
  246. <5> `introspectionResponseHandler()`: The `AuthenticationSuccessHandler` (_post-processor_) used for handling an "`authenticated`" `OAuth2TokenIntrospectionAuthenticationToken` and returning the https://datatracker.ietf.org/doc/html/rfc7662#section-2.2[OAuth2TokenIntrospection response].
  247. <6> `errorResponseHandler()`: The `AuthenticationFailureHandler` (_post-processor_) used for handling an `OAuth2AuthenticationException` and returning the https://datatracker.ietf.org/doc/html/rfc7662#section-2.3[OAuth2Error response].
  248. `OAuth2TokenIntrospectionEndpointConfigurer` configures the `OAuth2TokenIntrospectionEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  249. `OAuth2TokenIntrospectionEndpointFilter` is the `Filter` that processes OAuth2 introspection requests.
  250. `OAuth2TokenIntrospectionEndpointFilter` is configured with the following defaults:
  251. * `*AuthenticationConverter*` -- An `OAuth2TokenIntrospectionAuthenticationConverter`.
  252. * `*AuthenticationManager*` -- An `AuthenticationManager` composed of `OAuth2TokenIntrospectionAuthenticationProvider`.
  253. * `*AuthenticationSuccessHandler*` -- An internal implementation that handles an "`authenticated`" `OAuth2TokenIntrospectionAuthenticationToken` and returns the `OAuth2TokenIntrospection` response.
  254. * `*AuthenticationFailureHandler*` -- An `OAuth2ErrorAuthenticationFailureHandler` instance that handles the `OAuth2Error` associated with the `OAuth2AuthenticationException` and returns the `OAuth2Error` response.
  255. [[oauth2-token-revocation-endpoint]]
  256. == OAuth2 Token Revocation Endpoint
  257. `OAuth2TokenRevocationEndpointConfigurer` provides the ability to customize the https://datatracker.ietf.org/doc/html/rfc7009#section-2[OAuth2 Token Revocation endpoint].
  258. It defines extension points that let you customize the pre-processing, main processing, and post-processing logic for https://datatracker.ietf.org/doc/html/rfc7009#section-2.1[OAuth2 revocation requests].
  259. `OAuth2TokenRevocationEndpointConfigurer` provides the following configuration options:
  260. [source,java]
  261. ----
  262. @Bean
  263. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  264. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  265. new OAuth2AuthorizationServerConfigurer();
  266. http.apply(authorizationServerConfigurer);
  267. authorizationServerConfigurer
  268. .tokenRevocationEndpoint(tokenRevocationEndpoint ->
  269. tokenRevocationEndpoint
  270. .revocationRequestConverter(revocationRequestConverter) <1>
  271. .revocationRequestConverters(revocationRequestConvertersConsumer) <2>
  272. .authenticationProvider(authenticationProvider) <3>
  273. .authenticationProviders(authenticationProvidersConsumer) <4>
  274. .revocationResponseHandler(revocationResponseHandler) <5>
  275. .errorResponseHandler(errorResponseHandler) <6>
  276. );
  277. return http.build();
  278. }
  279. ----
  280. <1> `revocationRequestConverter()`: Adds an `AuthenticationConverter` (_pre-processor_) used when attempting to extract an https://datatracker.ietf.org/doc/html/rfc7009#section-2.1[OAuth2 revocation request] from `HttpServletRequest` to an instance of `OAuth2TokenRevocationAuthenticationToken`.
  281. <2> `revocationRequestConverters()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationConverter``'s allowing the ability to add, remove, or customize a specific `AuthenticationConverter`.
  282. <3> `authenticationProvider()`: Adds an `AuthenticationProvider` (_main processor_) used for authenticating the `OAuth2TokenRevocationAuthenticationToken`.
  283. <4> `authenticationProviders()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationProvider``'s allowing the ability to add, remove, or customize a specific `AuthenticationProvider`.
  284. <5> `revocationResponseHandler()`: The `AuthenticationSuccessHandler` (_post-processor_) used for handling an "`authenticated`" `OAuth2TokenRevocationAuthenticationToken` and returning the https://datatracker.ietf.org/doc/html/rfc7009#section-2.2[OAuth2 revocation response].
  285. <6> `errorResponseHandler()`: The `AuthenticationFailureHandler` (_post-processor_) used for handling an `OAuth2AuthenticationException` and returning the https://datatracker.ietf.org/doc/html/rfc7009#section-2.2.1[OAuth2Error response].
  286. `OAuth2TokenRevocationEndpointConfigurer` configures the `OAuth2TokenRevocationEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  287. `OAuth2TokenRevocationEndpointFilter` is the `Filter` that processes OAuth2 revocation requests.
  288. `OAuth2TokenRevocationEndpointFilter` is configured with the following defaults:
  289. * `*AuthenticationConverter*` -- An `OAuth2TokenRevocationAuthenticationConverter`.
  290. * `*AuthenticationManager*` -- An `AuthenticationManager` composed of `OAuth2TokenRevocationAuthenticationProvider`.
  291. * `*AuthenticationSuccessHandler*` -- An internal implementation that handles an "`authenticated`" `OAuth2TokenRevocationAuthenticationToken` and returns the OAuth2 revocation response.
  292. * `*AuthenticationFailureHandler*` -- An `OAuth2ErrorAuthenticationFailureHandler` instance that handles the `OAuth2Error` associated with the `OAuth2AuthenticationException` and returns the `OAuth2Error` response.
  293. [[oauth2-authorization-server-metadata-endpoint]]
  294. == OAuth2 Authorization Server Metadata Endpoint
  295. `OAuth2AuthorizationServerMetadataEndpointConfigurer` provides the ability to customize the https://datatracker.ietf.org/doc/html/rfc8414#section-3[OAuth2 Authorization Server Metadata endpoint].
  296. It defines an extension point that lets you customize the https://datatracker.ietf.org/doc/html/rfc8414#section-3.2[OAuth2 Authorization Server Metadata response].
  297. `OAuth2AuthorizationServerMetadataEndpointConfigurer` provides the following configuration option:
  298. [source,java]
  299. ----
  300. @Bean
  301. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  302. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  303. new OAuth2AuthorizationServerConfigurer();
  304. http.apply(authorizationServerConfigurer);
  305. authorizationServerConfigurer
  306. .authorizationServerMetadataEndpoint(authorizationServerMetadataEndpoint ->
  307. authorizationServerMetadataEndpoint
  308. .authorizationServerMetadataCustomizer(authorizationServerMetadataCustomizer)); <1>
  309. return http.build();
  310. }
  311. ----
  312. <1> `authorizationServerMetadataCustomizer()`: The `Consumer` providing access to the `OAuth2AuthorizationServerMetadata.Builder` allowing the ability to customize the claims of the Authorization Server's configuration.
  313. `OAuth2AuthorizationServerMetadataEndpointConfigurer` configures the `OAuth2AuthorizationServerMetadataEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  314. `OAuth2AuthorizationServerMetadataEndpointFilter` is the `Filter` that returns the https://datatracker.ietf.org/doc/html/rfc8414#section-3.2[OAuth2AuthorizationServerMetadata response].
  315. [[jwk-set-endpoint]]
  316. == JWK Set Endpoint
  317. `OAuth2AuthorizationServerConfigurer` provides support for the https://datatracker.ietf.org/doc/html/rfc7517[JWK Set endpoint].
  318. `OAuth2AuthorizationServerConfigurer` configures the `NimbusJwkSetEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  319. `NimbusJwkSetEndpointFilter` is the `Filter` that returns the https://datatracker.ietf.org/doc/html/rfc7517#section-5[JWK Set].
  320. [NOTE]
  321. The JWK Set endpoint is configured *only* if a `JWKSource<SecurityContext>` `@Bean` is registered.
  322. [[oidc-provider-configuration-endpoint]]
  323. == OpenID Connect 1.0 Provider Configuration Endpoint
  324. `OidcProviderConfigurationEndpointConfigurer` provides the ability to customize the https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig[OpenID Connect 1.0 Provider Configuration endpoint].
  325. It defines an extension point that lets you customize the https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationResponse[OpenID Provider Configuration response].
  326. `OidcProviderConfigurationEndpointConfigurer` provides the following configuration option:
  327. [source,java]
  328. ----
  329. @Bean
  330. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  331. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  332. new OAuth2AuthorizationServerConfigurer();
  333. http.apply(authorizationServerConfigurer);
  334. authorizationServerConfigurer
  335. .oidc(oidc ->
  336. oidc
  337. .providerConfigurationEndpoint(providerConfigurationEndpoint ->
  338. providerConfigurationEndpoint
  339. .providerConfigurationCustomizer(providerConfigurationCustomizer) <1>
  340. )
  341. );
  342. return http.build();
  343. }
  344. ----
  345. <1> `providerConfigurationCustomizer()`: The `Consumer` providing access to the `OidcProviderConfiguration.Builder` allowing the ability to customize the claims of the OpenID Provider's configuration.
  346. `OidcProviderConfigurationEndpointConfigurer` configures the `OidcProviderConfigurationEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  347. `OidcProviderConfigurationEndpointFilter` is the `Filter` that returns the https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationResponse[OidcProviderConfiguration response].
  348. [[oidc-logout-endpoint]]
  349. == OpenID Connect 1.0 Logout Endpoint
  350. `OidcLogoutEndpointConfigurer` provides the ability to customize the https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RPLogout[OpenID Connect 1.0 Logout endpoint].
  351. It defines extension points that let you customize the pre-processing, main processing, and post-processing logic for RP-Initiated Logout requests.
  352. `OidcLogoutEndpointConfigurer` provides the following configuration options:
  353. [source,java]
  354. ----
  355. @Bean
  356. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  357. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  358. new OAuth2AuthorizationServerConfigurer();
  359. http.apply(authorizationServerConfigurer);
  360. authorizationServerConfigurer
  361. .oidc(oidc ->
  362. oidc
  363. .logoutEndpoint(logoutEndpoint ->
  364. logoutEndpoint
  365. .logoutRequestConverter(logoutRequestConverter) <1>
  366. .logoutRequestConverters(logoutRequestConvertersConsumer) <2>
  367. .authenticationProvider(authenticationProvider) <3>
  368. .authenticationProviders(authenticationProvidersConsumer) <4>
  369. .logoutResponseHandler(logoutResponseHandler) <5>
  370. .errorResponseHandler(errorResponseHandler) <6>
  371. )
  372. );
  373. return http.build();
  374. }
  375. ----
  376. <1> `logoutRequestConverter()`: Adds an `AuthenticationConverter` (_pre-processor_) used when attempting to extract a https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RPLogout[Logout request] from `HttpServletRequest` to an instance of `OidcLogoutAuthenticationToken`.
  377. <2> `logoutRequestConverters()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationConverter``'s allowing the ability to add, remove, or customize a specific `AuthenticationConverter`.
  378. <3> `authenticationProvider()`: Adds an `AuthenticationProvider` (_main processor_) used for authenticating the `OidcLogoutAuthenticationToken`.
  379. <4> `authenticationProviders()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationProvider``'s allowing the ability to add, remove, or customize a specific `AuthenticationProvider`.
  380. <5> `logoutResponseHandler()`: The `AuthenticationSuccessHandler` (_post-processor_) used for handling an "`authenticated`" `OidcLogoutAuthenticationToken` and performing the logout.
  381. <6> `errorResponseHandler()`: The `AuthenticationFailureHandler` (_post-processor_) used for handling an `OAuth2AuthenticationException` and returning the error response.
  382. `OidcLogoutEndpointConfigurer` configures the `OidcLogoutEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  383. `OidcLogoutEndpointFilter` is the `Filter` that processes https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RPLogout[RP-Initiated Logout requests] and performs the logout of the End-User.
  384. `OidcLogoutEndpointFilter` is configured with the following defaults:
  385. * `*AuthenticationConverter*` -- An `OidcLogoutAuthenticationConverter`.
  386. * `*AuthenticationManager*` -- An `AuthenticationManager` composed of `OidcLogoutAuthenticationProvider`.
  387. * `*AuthenticationSuccessHandler*` -- An internal implementation that handles an "`authenticated`" `OidcLogoutAuthenticationToken` and performs the logout.
  388. * `*AuthenticationFailureHandler*` -- An internal implementation that uses the `OAuth2Error` associated with the `OAuth2AuthenticationException` and returns the `OAuth2Error` response.
  389. [NOTE]
  390. `OidcLogoutAuthenticationProvider` uses a xref:core-model-components.adoc#session-registry[`SessionRegistry`] to look up the `SessionInformation` instance associated to the End-User requesting to be logged out.
  391. [TIP]
  392. `OidcClientInitiatedLogoutSuccessHandler` is the corresponding configuration in Spring Security’s OAuth2 Client support for configuring {spring-security-reference-base-url}/servlet/oauth2/login/advanced.html#oauth2login-advanced-oidc-logout[OpenID Connect 1.0 RP-Initiated Logout].
  393. [[oidc-user-info-endpoint]]
  394. == OpenID Connect 1.0 UserInfo Endpoint
  395. `OidcUserInfoEndpointConfigurer` provides the ability to customize the https://openid.net/specs/openid-connect-core-1_0.html#UserInfo[OpenID Connect 1.0 UserInfo endpoint].
  396. It defines extension points that let you customize the pre-processing, main processing, and post-processing logic for https://openid.net/specs/openid-connect-core-1_0.html#UserInfoRequest[UserInfo requests].
  397. `OidcUserInfoEndpointConfigurer` provides the following configuration options:
  398. [source,java]
  399. ----
  400. @Bean
  401. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  402. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  403. new OAuth2AuthorizationServerConfigurer();
  404. http.apply(authorizationServerConfigurer);
  405. authorizationServerConfigurer
  406. .oidc(oidc ->
  407. oidc
  408. .userInfoEndpoint(userInfoEndpoint ->
  409. userInfoEndpoint
  410. .userInfoRequestConverter(userInfoRequestConverter) <1>
  411. .userInfoRequestConverters(userInfoRequestConvertersConsumer) <2>
  412. .authenticationProvider(authenticationProvider) <3>
  413. .authenticationProviders(authenticationProvidersConsumer) <4>
  414. .userInfoResponseHandler(userInfoResponseHandler) <5>
  415. .errorResponseHandler(errorResponseHandler) <6>
  416. .userInfoMapper(userInfoMapper) <7>
  417. )
  418. );
  419. return http.build();
  420. }
  421. ----
  422. <1> `userInfoRequestConverter()`: Adds an `AuthenticationConverter` (_pre-processor_) used when attempting to extract an https://openid.net/specs/openid-connect-core-1_0.html#UserInfoRequest[UserInfo request] from `HttpServletRequest` to an instance of `OidcUserInfoAuthenticationToken`.
  423. <2> `userInfoRequestConverters()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationConverter``'s allowing the ability to add, remove, or customize a specific `AuthenticationConverter`.
  424. <3> `authenticationProvider()`: Adds an `AuthenticationProvider` (_main processor_) used for authenticating the `OidcUserInfoAuthenticationToken`.
  425. <4> `authenticationProviders()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationProvider``'s allowing the ability to add, remove, or customize a specific `AuthenticationProvider`.
  426. <5> `userInfoResponseHandler()`: The `AuthenticationSuccessHandler` (_post-processor_) used for handling an "`authenticated`" `OidcUserInfoAuthenticationToken` and returning the https://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse[UserInfo response].
  427. <6> `errorResponseHandler()`: The `AuthenticationFailureHandler` (_post-processor_) used for handling an `OAuth2AuthenticationException` and returning the https://openid.net/specs/openid-connect-core-1_0.html#UserInfoError[UserInfo Error response].
  428. <7> `userInfoMapper()`: The `Function` used to extract claims from `OidcUserInfoAuthenticationContext` to an instance of `OidcUserInfo`.
  429. `OidcUserInfoEndpointConfigurer` configures the `OidcUserInfoEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  430. `OidcUserInfoEndpointFilter` is the `Filter` that processes https://openid.net/specs/openid-connect-core-1_0.html#UserInfoRequest[UserInfo requests] and returns the https://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse[OidcUserInfo response].
  431. `OidcUserInfoEndpointFilter` is configured with the following defaults:
  432. * `*AuthenticationConverter*` -- An internal implementation that obtains the `Authentication` from the `SecurityContext` and creates an `OidcUserInfoAuthenticationToken` with the principal.
  433. * `*AuthenticationManager*` -- An `AuthenticationManager` composed of `OidcUserInfoAuthenticationProvider`, which is associated with an internal implementation of `userInfoMapper` that extracts https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims[standard claims] from the https://openid.net/specs/openid-connect-core-1_0.html#IDToken[ID Token] based on the https://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims[scopes requested] during authorization.
  434. * `*AuthenticationSuccessHandler*` -- An internal implementation that handles an "`authenticated`" `OidcUserInfoAuthenticationToken` and returns the `OidcUserInfo` response.
  435. * `*AuthenticationFailureHandler*` -- An internal implementation that uses the `OAuth2Error` associated with the `OAuth2AuthenticationException` and returns the `OAuth2Error` response.
  436. [TIP]
  437. You can customize the ID Token by providing an xref:core-model-components.adoc#oauth2-token-customizer[`OAuth2TokenCustomizer<JwtEncodingContext>`] `@Bean`.
  438. The OpenID Connect 1.0 UserInfo endpoint is an OAuth2 protected resource, which *REQUIRES* an access token to be sent as a bearer token in the https://openid.net/specs/openid-connect-core-1_0.html#UserInfoRequest[UserInfo request].
  439. The following example shows how to enable the OAuth2 resource server configuration:
  440. [source,java]
  441. ----
  442. @Bean
  443. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  444. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  445. new OAuth2AuthorizationServerConfigurer();
  446. http.apply(authorizationServerConfigurer);
  447. ...
  448. http.oauth2ResourceServer(resourceServer -> resourceServer.jwt(Customizer.withDefaults()));
  449. return http.build();
  450. }
  451. @Bean
  452. public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
  453. return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
  454. }
  455. ----
  456. [NOTE]
  457. A `JwtDecoder` `@Bean` is *REQUIRED* for the OpenID Connect 1.0 UserInfo endpoint.
  458. [TIP]
  459. The guide xref:guides/how-to-userinfo.adoc[How-to: Customize the OpenID Connect 1.0 UserInfo response] contains examples of customizing the UserInfo endpoint.
  460. [[oidc-client-registration-endpoint]]
  461. == OpenID Connect 1.0 Client Registration Endpoint
  462. `OidcClientRegistrationEndpointConfigurer` provides the ability to customize the https://openid.net/specs/openid-connect-registration-1_0.html#ClientRegistration[OpenID Connect 1.0 Client Registration endpoint].
  463. It defines extension points that let you customize the pre-processing, main processing, and post-processing logic for https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationRequest[Client Registration requests] or https://openid.net/specs/openid-connect-registration-1_0.html#ReadRequest[Client Read requests].
  464. `OidcClientRegistrationEndpointConfigurer` provides the following configuration options:
  465. [source,java]
  466. ----
  467. @Bean
  468. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  469. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  470. new OAuth2AuthorizationServerConfigurer();
  471. http.apply(authorizationServerConfigurer);
  472. authorizationServerConfigurer
  473. .oidc(oidc ->
  474. oidc
  475. .clientRegistrationEndpoint(clientRegistrationEndpoint ->
  476. clientRegistrationEndpoint
  477. .clientRegistrationRequestConverter(clientRegistrationRequestConverter) <1>
  478. .clientRegistrationRequestConverters(clientRegistrationRequestConvertersConsumers) <2>
  479. .authenticationProvider(authenticationProvider) <3>
  480. .authenticationProviders(authenticationProvidersConsumer) <4>
  481. .clientRegistrationResponseHandler(clientRegistrationResponseHandler) <5>
  482. .errorResponseHandler(errorResponseHandler) <6>
  483. )
  484. );
  485. return http.build();
  486. }
  487. ----
  488. <1> `clientRegistrationRequestConverter()`: Adds an `AuthenticationConverter` (_pre-processor_) used when attempting to extract a https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationRequest[Client Registration request] or https://openid.net/specs/openid-connect-registration-1_0.html#ReadRequest[Client Read request] from `HttpServletRequest` to an instance of `OidcClientRegistrationAuthenticationToken`.
  489. <2> `clientRegistrationRequestConverters()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationConverter``'s allowing the ability to add, remove, or customize a specific `AuthenticationConverter`.
  490. <3> `authenticationProvider()`: Adds an `AuthenticationProvider` (_main processor_) used for authenticating the `OidcClientRegistrationAuthenticationToken`.
  491. <4> `authenticationProviders()`: Sets the `Consumer` providing access to the `List` of default and (optionally) added ``AuthenticationProvider``'s allowing the ability to add, remove, or customize a specific `AuthenticationProvider`.
  492. <5> `clientRegistrationResponseHandler()`: The `AuthenticationSuccessHandler` (_post-processor_) used for handling an "`authenticated`" `OidcClientRegistrationAuthenticationToken` and returning the https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationResponse[Client Registration response] or https://openid.net/specs/openid-connect-registration-1_0.html#ReadResponse[Client Read response].
  493. <6> `errorResponseHandler()`: The `AuthenticationFailureHandler` (_post-processor_) used for handling an `OAuth2AuthenticationException` and returning the https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationError[Client Registration Error response] or https://openid.net/specs/openid-connect-registration-1_0.html#ReadError[Client Read Error response].
  494. [NOTE]
  495. The OpenID Connect 1.0 Client Registration endpoint is disabled by default because many deployments do not require dynamic client registration.
  496. `OidcClientRegistrationEndpointConfigurer` configures the `OidcClientRegistrationEndpointFilter` and registers it with the OAuth2 authorization server `SecurityFilterChain` `@Bean`.
  497. `OidcClientRegistrationEndpointFilter` is the `Filter` that processes https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationRequest[Client Registration requests] and returns the https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationResponse[OidcClientRegistration response].
  498. [TIP]
  499. `OidcClientRegistrationEndpointFilter` also processes https://openid.net/specs/openid-connect-registration-1_0.html#ReadRequest[Client Read requests] and returns the https://openid.net/specs/openid-connect-registration-1_0.html#ReadResponse[OidcClientRegistration response].
  500. `OidcClientRegistrationEndpointFilter` is configured with the following defaults:
  501. * `*AuthenticationConverter*` -- An `OidcClientRegistrationAuthenticationConverter`.
  502. * `*AuthenticationManager*` -- An `AuthenticationManager` composed of `OidcClientRegistrationAuthenticationProvider` and `OidcClientConfigurationAuthenticationProvider`.
  503. * `*AuthenticationSuccessHandler*` -- An internal implementation that handles an "`authenticated`" `OidcClientRegistrationAuthenticationToken` and returns the `OidcClientRegistration` response.
  504. * `*AuthenticationFailureHandler*` -- An internal implementation that uses the `OAuth2Error` associated with the `OAuth2AuthenticationException` and returns the `OAuth2Error` response.
  505. The OpenID Connect 1.0 Client Registration endpoint is an https://openid.net/specs/openid-connect-registration-1_0.html#ClientRegistration[OAuth2 protected resource], which *REQUIRES* an access token to be sent as a bearer token in the Client Registration (or Client Read) request.
  506. [IMPORTANT]
  507. The access token in a Client Registration request *REQUIRES* the OAuth2 scope `client.create`.
  508. [IMPORTANT]
  509. The access token in a Client Read request *REQUIRES* the OAuth2 scope `client.read`.
  510. The following example shows how to enable the OAuth2 resource server configuration:
  511. [source,java]
  512. ----
  513. @Bean
  514. public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
  515. OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
  516. new OAuth2AuthorizationServerConfigurer();
  517. http.apply(authorizationServerConfigurer);
  518. ...
  519. http.oauth2ResourceServer(resourceServer -> resourceServer.jwt(Customizer.withDefaults()));
  520. return http.build();
  521. }
  522. @Bean
  523. public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
  524. return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
  525. }
  526. ----
  527. [NOTE]
  528. A `JwtDecoder` `@Bean` is *REQUIRED* for the OpenID Connect 1.0 Client Registration endpoint.