Class ServletOAuth2AuthorizedClientExchangeFilterFunction

java.lang.Object
org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction
All Implemented Interfaces:
org.springframework.web.reactive.function.client.ExchangeFilterFunction

public final class ServletOAuth2AuthorizedClientExchangeFilterFunction extends Object implements org.springframework.web.reactive.function.client.ExchangeFilterFunction
Provides an easy mechanism for using an OAuth2AuthorizedClient to make OAuth 2.0 requests by including the access token as a bearer token.

NOTE:This class is intended to be used in a Servlet environment.

Example usage:

 ServletOAuth2AuthorizedClientExchangeFilterFunction oauth2 = new ServletOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager);
 WebClient webClient = WebClient.builder()
    .apply(oauth2.oauth2Configuration())
    .build();
 Mono<String> response = webClient
    .get()
    .uri(uri)
    .attributes(oauth2AuthorizedClient(authorizedClient))
    // ...
    .retrieve()
    .bodyToMono(String.class);
 

Authentication and Authorization Failures

Since 5.3, this filter function has the ability to forward authentication (HTTP 401 Unauthorized) and authorization (HTTP 403 Forbidden) failures from an OAuth 2.0 Resource Server to a OAuth2AuthorizationFailureHandler. A RemoveAuthorizedClientOAuth2AuthorizationFailureHandler can be used to remove the cached OAuth2AuthorizedClient, so that future requests will result in a new token being retrieved from an Authorization Server, and sent to the Resource Server.

If the ServletOAuth2AuthorizedClientExchangeFilterFunction(ClientRegistrationRepository, OAuth2AuthorizedClientRepository) constructor is used, a RemoveAuthorizedClientOAuth2AuthorizationFailureHandler will be configured automatically.

If the ServletOAuth2AuthorizedClientExchangeFilterFunction(OAuth2AuthorizedClientManager) constructor is used, a RemoveAuthorizedClientOAuth2AuthorizationFailureHandler will NOT be configured automatically. It is recommended that you configure one via setAuthorizationFailureHandler(OAuth2AuthorizationFailureHandler).

Since:
5.1
See Also: