public final class ServerOAuth2AuthorizedClientExchangeFilterFunction
extends java.lang.Object
implements org.springframework.web.reactive.function.client.ExchangeFilterFunction
OAuth2AuthorizedClient
to make OAuth2 requests by including the
token as a Bearer Token.Constructor and Description |
---|
ServerOAuth2AuthorizedClientExchangeFilterFunction() |
ServerOAuth2AuthorizedClientExchangeFilterFunction(ReactiveOAuth2AuthorizedClientService authorizedClientService) |
Modifier and Type | Method and Description |
---|---|
reactor.core.publisher.Mono<org.springframework.web.reactive.function.client.ClientResponse> |
filter(org.springframework.web.reactive.function.client.ClientRequest request,
org.springframework.web.reactive.function.client.ExchangeFunction next) |
static java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> |
oauth2AuthorizedClient(OAuth2AuthorizedClient authorizedClient)
Modifies the
ClientRequest.attributes() to include the OAuth2AuthorizedClient to be used for
providing the Bearer Token. |
void |
setAccessTokenExpiresSkew(java.time.Duration accessTokenExpiresSkew)
An access token will be considered expired by comparing its expiration to now +
this skewed Duration.
|
public ServerOAuth2AuthorizedClientExchangeFilterFunction()
public ServerOAuth2AuthorizedClientExchangeFilterFunction(ReactiveOAuth2AuthorizedClientService authorizedClientService)
public static java.util.function.Consumer<java.util.Map<java.lang.String,java.lang.Object>> oauth2AuthorizedClient(OAuth2AuthorizedClient authorizedClient)
ClientRequest.attributes()
to include the OAuth2AuthorizedClient
to be used for
providing the Bearer Token. Example usage:
WebClient webClient = WebClient.builder() .filter(new OAuth2AuthorizedClientExchangeFilterFunction(authorizedClientService)) .build(); MonoAn attempt to automatically refresh the token will be made if all of the following are true:response = webClient .get() .uri(uri) .attributes(oauth2AuthorizedClient(authorizedClient)) // ... .retrieve() .bodyToMono(String.class);
ServerOAuth2AuthorizedClientExchangeFilterFunction
is not nullsetAccessTokenExpiresSkew(Duration)
ReactiveSecurityContextHolder
will be used to attempt to save
the token. If it is empty, then the principal name on the OAuth2AuthorizedClient
will be used to create an Authentication for saving.authorizedClient
- the OAuth2AuthorizedClient
to use.Consumer
to populate thepublic void setAccessTokenExpiresSkew(java.time.Duration accessTokenExpiresSkew)
accessTokenExpiresSkew
- the Duration to use.public reactor.core.publisher.Mono<org.springframework.web.reactive.function.client.ClientResponse> filter(org.springframework.web.reactive.function.client.ClientRequest request, org.springframework.web.reactive.function.client.ExchangeFunction next)
filter
in interface org.springframework.web.reactive.function.client.ExchangeFilterFunction