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.
Thank you guys for the quick response. I don't have a clue what went wrong last time. But now it works. I was playing with different config including @krnbr 's. But my observations are below
When I use
DefaultReactiveOAuth2AuthorizedClientManager
, I get a different error likeIllegalArgumentException: serverWebExchange cannot be null
. Now I use @abhi2495 's code only which is withAuthorizedClientServiceReactiveOAuth2AuthorizedClientManager
.I dont need a
SecurityWebFilterChain
bean. Do you know what is the use of it? My app has nothing but a scheduled job in which a webclient talks to another app.My auth server is Keycloak. If the auth url uses
https
, spring throws SSLhandshakeException, though my httpclient (of webclient) uses an insecure trust factory. Do you know how to fix this?And most importantly, spring oauth2 client is not reusing the token. Everytime it requests for a new token. I configured the access token with 1 minute (minimum allowed) lifespan and client session expiry time. And I can see that Keycloak is retaining the sessions (the number of sessions just increases)
This is the sample app https://github.com/winster/oauth