-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
I want to send the Oauth Token request sent in case of Grant type Client Credentials as a JSON object
{
"grantType" : "client_credentials"
}
instead of Form data
grant_type=client_credentials
Currently in those discussions I found two approaches
#7781
#8612
One solution is create custom OAuth2ClientCredentialsGrantRequestEntityConverter and other is to use Filters along with BodyInserters, but in both solutions we are able to add/edit the form data object only and not replace it with a json body.
When I try this approach, I can edit the whole body to a String...but I need it to go as Json Object and not Json String enclosed within "" as this below code does
private ExchangeFilterFunction addCustomFilter() {
return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> {
// Create a new ClientRequest.Builder and set the updated headers
ClientRequest.Builder newRequestBuilder = ClientRequest.from(clientRequest);
newRequestBuilder.header("Content-Type", "application/json");
newRequestBuilder.body(BodyInserters.fromValue("{\"grant_type\": \"client_credentials\"}"));
return Mono.just(newRequestBuilder.build());
});
}
and for OAuth2ClientCredentialsGrantRequestEntityConverter had method createParameters which is supposed to return MultiValueMap<String, String> ....which is again map for constructing form data...so changing request body to Json here wont be possible