Skip to content

Commit 810e4cb

Browse files
committed
Document OAuth2AuthorizedClientManager/Provider
Fixes gh-7403
1 parent 7f1b8ee commit 810e4cb

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/manual/src/docs/asciidoc/_includes/servlet/preface/oauth2-client.adoc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The following sections go into more detail on each of the configuration options
4242
* <<oauth2Client-client-registration-repo>>
4343
* <<oauth2Client-authorized-client>>
4444
* <<oauth2Client-authorized-repo-service>>
45+
* <<oauth2Client-authorized-manager-provider>>
4546
* <<oauth2Client-registered-authorized-client>>
4647
* <<oauth2Client-authorization-request-repository>>
4748
* <<oauth2Client-authorization-request-resolver>>
@@ -200,6 +201,53 @@ public class OAuth2LoginController {
200201
----
201202

202203

204+
[[oauth2Client-authorized-manager-provider]]
205+
=== OAuth2AuthorizedClientManager / OAuth2AuthorizedClientProvider
206+
207+
The `OAuth2AuthorizedClientManager` is responsible for the overall management of `OAuth2AuthorizedClient`(s).
208+
209+
The primary responsibilities include:
210+
211+
* Authorizing (or re-authorizing) an OAuth 2.0 Client, using an `OAuth2AuthorizedClientProvider`.
212+
* Delegating the persistence of an `OAuth2AuthorizedClient`, typically using an `OAuth2AuthorizedClientService` or `OAuth2AuthorizedClientRepository`.
213+
214+
An `OAuth2AuthorizedClientProvider` implements a strategy for authorizing (or re-authorizing) an OAuth 2.0 Client.
215+
Implementations will typically implement an authorization grant type, eg. `authorization_code`, `client_credentials`, etc.
216+
217+
The default implementation of `OAuth2AuthorizedClientManager` is `DefaultOAuth2AuthorizedClientManager`, which is associated with an `OAuth2AuthorizedClientProvider` that may support multiple authorization grant types using a delegation-based composite.
218+
The `OAuth2AuthorizedClientProviderBuilder` may be used to configure and build the delegation-based composite.
219+
220+
The following code shows an example of how to configure and build an `OAuth2AuthorizedClientProvider` composite that provides support for the `authorization_code`, `refresh_token`, `client_credentials` and `password` authorization grant types:
221+
222+
[source,java]
223+
----
224+
@Bean
225+
public OAuth2AuthorizedClientManager authorizedClientManager(
226+
ClientRegistrationRepository clientRegistrationRepository,
227+
OAuth2AuthorizedClientRepository authorizedClientRepository) {
228+
229+
OAuth2AuthorizedClientProvider authorizedClientProvider =
230+
OAuth2AuthorizedClientProviderBuilder.builder()
231+
.authorizationCode()
232+
.refreshToken()
233+
.clientCredentials()
234+
.password()
235+
.build();
236+
237+
DefaultOAuth2AuthorizedClientManager authorizedClientManager =
238+
new DefaultOAuth2AuthorizedClientManager(
239+
clientRegistrationRepository, authorizedClientRepository);
240+
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
241+
242+
return authorizedClientManager;
243+
}
244+
----
245+
246+
[NOTE]
247+
Spring Boot 2.x auto-configuration registers an `OAuth2AuthorizedClientManager` `@Bean` in the `ApplicationContext`.
248+
However, the application may choose to override and register a custom `OAuth2AuthorizedClientManager` `@Bean`.
249+
250+
203251
[[oauth2Client-registered-authorized-client]]
204252
=== RegisteredOAuth2AuthorizedClient
205253

0 commit comments

Comments
 (0)