liveBook · Manning

OAuth2AuthorizedClientManager

As explained in Spring Security in Action, Second Edition

OAuth2AuthorizedClientManager is a Spring Security component that manages authorized clients and obtains access tokens by executing OAuth 2 grant flows.

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

How Spring Security in Action, Second Edition covers it

How deep it goes
Defines registration, provider, manager, and authorization-request steps, but defers broader proxy-layer design.
Examples
Demonstrates a /token controller endpoint that authorizes a client registration and returns the retrieved token.
What it assumes
Assumes basic Spring configuration and client-registration concepts while supplying the manager configuration and request sequence.
What you can do after
Build an OAuth 2 client that retrieves an access token through a configured grant flow.
How it connects
Connects OAuth 2 clients with client credentials, client registrations, authorization servers, access tokens, and proxy layers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.