This gist describes the configuration required for Spring reactive WebClient to make a call to an OAuth2 protected resource through OAuth2.0 Client Credentials Grant Type Flow.
Assumption is that the Authorization Server supports OpenId Connect 1.0 specifications.
BTW: I realized that if you use spring boot you should not define the WebClient bean like this. Spring boot normally configures a
WebClient.Builder
instance that considers settings likespring.jackson.serialization.write-dates-as-timestamps=false
etc. and creates aWebClient
bean for you, using this builder. But if you create aWebClient
bean like this, the settings in spring boot’s builder are lost - and so are you! 😉Use either this:
or even better this:
And use this builder in your services to create a WebClient instance:
See also here: https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-webclient-customization