Skip to content

Support Sending Json Body instead of Multipart Form Data during WebClientReactive ClientCredentials TokenRequest #14404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ashetty-boku opened this issue Jan 5, 2024 · 1 comment
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@ashetty-boku
Copy link

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

@ashetty-boku ashetty-boku added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Jan 5, 2024
@sjohnr
Copy link
Contributor

sjohnr commented Jan 5, 2024

@ashetty-boku thanks for reaching out!

Regarding WebClientReactiveClientCredentialsTokenResponseClient (which extends AbstractWebClientReactiveOAuth2AccessTokenResponseClient), the intent is to create a spec-compliant request, which uses multipart/form-data. These classes do not intend to support JSON request bodies, as this is not required by the spec. However, you are free to create your own ReactiveOAuth2AccessTokenResponseClient that does this and plug it into the framework (as in this example). Doing so would not be difficult and I believe it will solve the problem for you.

I'm going to close this issue, as I don't believe it is realistic or necessary to bend the existing WebClientReactiveClientCredentialsTokenResponseClient to solve this use case. Please let me know if I have missed anything in the context of your request and we can reopen if necessary.

@sjohnr sjohnr closed this as completed Jan 5, 2024
@sjohnr sjohnr self-assigned this Jan 5, 2024
@sjohnr sjohnr added status: declined A suggestion or change that we don't feel we should currently apply in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants