Skip to content

Commit 200829f

Browse files
committed
Document AuthorizedClientServiceOAuth2AuthorizedClientManager
Fixes gh-8152
1 parent 2d8242c commit 200829f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,36 @@ private Function<OAuth2AuthorizeRequest, Map<String, Object>> contextAttributesM
396396
}
397397
----
398398

399+
The `DefaultOAuth2AuthorizedClientManager` is designed to be used *_within_* the context of a `HttpServletRequest`.
400+
When operating *_outside_* of a `HttpServletRequest` context, use `AuthorizedClientServiceOAuth2AuthorizedClientManager` instead.
401+
402+
A _service application_ is a common use case for when to use an `AuthorizedClientServiceOAuth2AuthorizedClientManager`.
403+
Service applications often run in the background, without any user interaction, and typically run under a system-level account instead of a user account.
404+
An OAuth 2.0 Client configured with the `client_credentials` grant type can be considered a type of service application.
405+
406+
The following code shows an example of how to configure an `AuthorizedClientServiceOAuth2AuthorizedClientManager` that provides support for the `client_credentials` grant type:
407+
408+
[source,java]
409+
----
410+
@Bean
411+
public OAuth2AuthorizedClientManager authorizedClientManager(
412+
ClientRegistrationRepository clientRegistrationRepository,
413+
OAuth2AuthorizedClientService authorizedClientService) {
414+
415+
OAuth2AuthorizedClientProvider authorizedClientProvider =
416+
OAuth2AuthorizedClientProviderBuilder.builder()
417+
.clientCredentials()
418+
.build();
419+
420+
AuthorizedClientServiceOAuth2AuthorizedClientManager authorizedClientManager =
421+
new AuthorizedClientServiceOAuth2AuthorizedClientManager(
422+
clientRegistrationRepository, authorizedClientService);
423+
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
424+
425+
return authorizedClientManager;
426+
}
427+
----
428+
399429

400430
[[oauth2Client-auth-grant-support]]
401431
=== Authorization Grant Support

0 commit comments

Comments
 (0)