I have an OAuth2 enabled WebClient configured using Spring's very convenient spring-boot-starter-oauth2-client library. It works perfectly in terms of getting and managing tokens when I make requests to my OAuth2 secured resource server API
I'd like to add global exception handling to the WebClient to handle exceptions arising from requests to my resource server. An ExchangeFilterFunction following something like the approach outlined in this article looks good.
I'm just wondering, as the WebClient already has a ServletOAuth2AuthorizedClientExchangeFilterFunction applied, would adding additional filters have any impact on the interactions with the OAuth2 authorization server?
Here is my current WebClient config:
@Bean
public WebClient edmsDataIntegrationServiceWebClient(OAuth2AuthorizedClientManager authorizedClientManager) {
ServletOAuth2AuthorizedClientExchangeFilterFunction oauth2Client =
new ServletOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager);
oauth2Client.setDefaultClientRegistrationId("my-auth-server");
return WebClient.builder()
.baseUrl(baeUrl)
.apply(oauth2Client.oauth2Configuration())
.build();
}
So the additional filter would be something like the approach outlined here, where handleResourceServerError() would return an ExchangeFilterFunction that handles exceptions caused by my resource server response:
return WebClient.builder()
.baseUrl(baeUrl)
.apply(oauth2Client.oauth2Configuration())
.filter(WebClientFilter.handleResourceServerError()) //handles exceptions caused by resource server response
.build();
Is the above approach ok without breaking any of the ServletOAuth2AuthorizedClientExchangeFilterFunction functionality?