Package org.springframework.security.config.annotation.web.configurers.oauth2.client

# Class OAuth2ClientConfigurer<B extends HttpSecurityBuilder<B>>

java.lang.Object
org.springframework.security.config.annotation.SecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,B>
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer<OAuth2ClientConfigurer<B>,B>
org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2ClientConfigurer<B>

All Implemented Interfaces:
  `SecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,B>`

public final class OAuth2ClientConfigurer<B extends HttpSecurityBuilder<B>> extends AbstractHttpConfigurer<OAuth2ClientConfigurer<B>,B>
An `AbstractHttpConfigurer` for OAuth 2.0 Client support.

The following configuration options are available:

- `authorizationCodeGrant()` - support for the OAuth 2.0 Authorization Code Grant

Defaults are provided for all configuration options with the only required configuration being `clientRegistrationRepository(ClientRegistrationRepository)`. Alternatively, a `ClientRegistrationRepository` `@Bean` may be registered instead.

## Security Filters

The following `Filter`'s are populated for `authorizationCodeGrant()`:

- `OAuth2AuthorizationRequestRedirectFilter`
- `OAuth2AuthorizationCodeGrantFilter`

## Shared Objects Created

The following shared objects are populated:

- `ClientRegistrationRepository` (required)
- `OAuth2AuthorizedClientRepository` (optional)

## Shared Objects Used

The following shared objects are used:

- `ClientRegistrationRepository`
- `OAuth2AuthorizedClientRepository`

Since:
  5.1
See Also:
  - `OAuth2AuthorizationRequestRedirectFilter`
  - `OAuth2AuthorizationCodeGrantFilter`
  - `ClientRegistrationRepository`
  - `OAuth2AuthorizedClientRepository`
  - `AbstractHttpConfigurer`

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`final class`
`OAuth2ClientConfigurer.AuthorizationCodeGrantConfigurer`
Configuration options for the OAuth 2.0 Authorization Code Grant.

## Constructor Summary

Constructors
Constructor
Description
`OAuth2ClientConfigurer()`

## Method Summary

Modifier and Type
Method
Description
`OAuth2ClientConfigurer<B>.AuthorizationCodeGrantConfigurer`
`authorizationCodeGrant()`
Deprecated, for removal: This API element is subject to removal in a future version.
For removal in 7.0.
`OAuth2ClientConfigurer<B>`
`authorizationCodeGrant(Customizer<OAuth2ClientConfigurer<B>.AuthorizationCodeGrantConfigurer> authorizationCodeGrantCustomizer)`
Configures the OAuth 2.0 Authorization Code Grant.
`OAuth2ClientConfigurer<B>`
`authorizedClientRepository(org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository authorizedClientRepository)`
Sets the repository for authorized client(s).
`OAuth2ClientConfigurer<B>`
`authorizedClientService(org.springframework.security.oauth2.client.OAuth2AuthorizedClientService authorizedClientService)`
Sets the service for authorized client(s).
`OAuth2ClientConfigurer<B>`
`clientRegistrationRepository(org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRegistrationRepository)`
Sets the repository of client registrations.
`void`
`configure(B builder)`
Configure the `SecurityBuilder` by setting the necessary properties on the `SecurityBuilder`.
`void`
`init(B builder)`
Initialize the `SecurityBuilder`.

### Methods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer

`disable, getSecurityContextHolderStrategy, withObjectPostProcessor, withObjectPostProcessor`

### Methods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter

`addObjectPostProcessor, addObjectPostProcessor, and, getBuilder, postProcess, setBuilder`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### OAuth2ClientConfigurer

public OAuth2ClientConfigurer()

## Method Details

### clientRegistrationRepository

public OAuth2ClientConfigurer<B> clientRegistrationRepository(org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRegistrationRepository)
Sets the repository of client registrations.

Parameters:
  `clientRegistrationRepository` - the repository of client registrations
Returns:
  the `OAuth2ClientConfigurer` for further configuration

### authorizedClientRepository

public OAuth2ClientConfigurer<B> authorizedClientRepository(org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository authorizedClientRepository)
Sets the repository for authorized client(s).

Parameters:
  `authorizedClientRepository` - the authorized client repository
Returns:
  the `OAuth2ClientConfigurer` for further configuration

### authorizedClientService

public OAuth2ClientConfigurer<B> authorizedClientService(org.springframework.security.oauth2.client.OAuth2AuthorizedClientService authorizedClientService)
Sets the service for authorized client(s).

Parameters:
  `authorizedClientService` - the authorized client service
Returns:
  the `OAuth2ClientConfigurer` for further configuration

### authorizationCodeGrant

@Deprecated(since="6.1", forRemoval=true) public OAuth2ClientConfigurer<B>.AuthorizationCodeGrantConfigurer authorizationCodeGrant()
Deprecated, for removal: This API element is subject to removal in a future version.
For removal in 7.0. Use `authorizationCodeGrant(Customizer)` instead
Returns the `OAuth2ClientConfigurer<B extends HttpSecurityBuilder<B>>.AuthorizationCodeGrantConfigurer` for configuring the OAuth 2.0 Authorization Code Grant.

Returns:
  the `OAuth2ClientConfigurer<B extends HttpSecurityBuilder<B>>.AuthorizationCodeGrantConfigurer`

### authorizationCodeGrant

public OAuth2ClientConfigurer<B> authorizationCodeGrant(Customizer<OAuth2ClientConfigurer<B>.AuthorizationCodeGrantConfigurer> authorizationCodeGrantCustomizer)
Configures the OAuth 2.0 Authorization Code Grant.

Parameters:
  `authorizationCodeGrantCustomizer` - the `Customizer` to provide more options for the `OAuth2ClientConfigurer<B extends HttpSecurityBuilder<B>>.AuthorizationCodeGrantConfigurer`
Returns:
  the `OAuth2ClientConfigurer` for further customizations

### init

public void init(B builder)
Description copied from interface: `SecurityConfigurer`
Initialize the `SecurityBuilder`. Here only shared state should be created and modified, but not properties on the `SecurityBuilder` used for building the object. This ensures that the `SecurityConfigurer.configure(SecurityBuilder)` method uses the correct shared objects when building. Configurers should be applied here.

Specified by:
  `init` in interface `SecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,B extends HttpSecurityBuilder<B>>`
Overrides:
  `init` in class `SecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,B extends HttpSecurityBuilder<B>>`

### configure

public void configure(B builder)
Description copied from interface: `SecurityConfigurer`
Configure the `SecurityBuilder` by setting the necessary properties on the `SecurityBuilder`.

Specified by:
  `configure` in interface `SecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,B extends HttpSecurityBuilder<B>>`
Overrides:
  `configure` in class `SecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,B extends HttpSecurityBuilder<B>>`