When integrating with some API behind OAuth authorization using old Spring's RestTemplate I was doing some kind of:
ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();resourceDetails.setClientId(oauthClientId);
resourceDetails.setClientSecret(oauthClientSecret);
resourceDetails.setAccessTokenUri(accessTokenUri);
// and we got the restTemplate:
OAuth2RestTemplate client = new OAuth2RestTemplate(resourceDetails);
and then GET goes like:
client.getForEntity(restApiUri, MyEntity.class);
But it is blocking :(
As a workaround I wrapped old RestTempate using Mono.fromCallable(...). I tried also do some custom client using WebClient that takes token and authorize user and then do second call to RestApi. But it is not convinient as token can expire and I would have to implement renewal process. There can also be more pitfalls in OAuth that I'm not aware of.
How I can do it using Spring web-flux and WebClient with Mono/Flux reactive objects?
Maybe this will help you. Medium article about configuring the webclient to use it the way you mentioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With