graphql-spring-webclient
graphql-spring-webclient copied to clipboard
Apply oauth2 client configuration to WebClients not created by this starter
Is your feature request related to a problem? Please describe.
The oauth2 properties are only applied to the WebClient
created by this starter. When you need to connect to two different GraphQL endpoints you need two different GraphQLWebClient
instances, both with their own WebClient
instances containing the correct url. That's possible to do now by simply not using the auto-configuration features of this starter but by creating those instances manually.
In my case those GraphQL endpoints are secured by the same Identity Provider and I just have to apply one oauth2 configuration to make it work with both instances. Currently I'd have to copy paste the following logic when creating those WebClient
instances:
if (clientRegistrations != null && clientRegistrations.findByRegistrationId("graphql").blockOptional().isPresent()) {
ServerOAuth2AuthorizedClientExchangeFilterFunction oauth =
new ServerOAuth2AuthorizedClientExchangeFilterFunction(
clientRegistrations,
new UnAuthenticatedServerOAuth2AuthorizedClientRepository());
oauth.setDefaultClientRegistrationId("graphql");
clientBuilder.filter(oauth);
}
Describe the solution you'd like
Extract applying the oauth2 client configuration from the method creating the WebClient
instance. It should get a hold of the WebClient.Builder
bean and apply this logic to it before the WebClient
beans are created (manually or by this starter). That means that the WebClient
bean construction that's outside of control of this library should happen after that "listener" too. Not sure yet how that dependency could be implemented correctly.
Describe alternatives you've considered Copy pasting the logic and applying it manually.
Additional context N/A