OAuth2AuthorizedClientManager manages authorized clients and obtains access tokens by executing configured OAuth 2 grant flows. A backend service can use it when calling another application requires an access token. section 16.2 section 16.3
Configure the manager around three cooperating pieces:
- Register client credentials, authentication method, grant type, token URI, and scopes in a ClientRegistrationRepository. section 16.2
- Build an OAuth2AuthorizedClientProvider with the supported grant flow, such as client credentials. section 16.2
- Create DefaultOAuth2AuthorizedClientManager, attach the provider, and expose it as a bean. section 16.2
- Submit an OAuth2AuthorizeRequest with a registration ID and principal, then read the returned access token. section 16.2
Token endpoint
A controller injects the manager, authorizes registration "1" for principal "client", and returns client.getAccessToken().getTokenValue() from a /token endpoint. A production design would normally place this responsibility in a proxy layer rather than directly in the controller. section 16.2
Figure 16.10 The controller uses a client manager to get the access token from an authorization server. The client manager is the Spring Security component responsible for connecting to the authorization server and properly using the grant type to get the access token.
Shows the manager connecting to the authorization server and applying the configured grant type to obtain an access token. section 16.2
