function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ignacio Sales 1Ignacio Sales 1 

Error "unsupported_grant_type" when getting OAuth token for a connected app. Single Sign on and custom domain enabled.

We are getting the error "unsupported_grant_type" when getting an OAuth token for a connected app. The connected app is installed on a Org with Single Sign on and which uses a custom domain.

When starting the OAuth 2.0 Web Server Flow for Web App Integration, the user is directed to their custom domain login url, they log in successfully, and are presented with the approval page, where they confirm that they grant the required access.

Then, when we request the token, we receive the error:

Client error: `POST https://<customercustomdomain>.lightning.force.com//services/oauth2/token` resulted in a `400 Bad Request` response:
{"error":"unsupported_grant_type","error_description":"grant type not supported"}

This same OAuth flow is working with all our other customers, using the same grant type (which is authorization_code). 

We've seen quite a lot of posts which talk about this error, but they all seem to refer to missing or incorrect headers, in situations in which the OAuth flow does not work at all. But in our case, it works in all Orgs, except for this particular one. 

Any ideas / help would be much appreciated.
 
Best Answer chosen by Ignacio Sales 1
Ignacio Sales 1Ignacio Sales 1
We found the cause of the issue, which had nothing to do with the grant type.

Will write it up here in case it helps someone with a similar problem.

The problem was that we were getting a 302-Redirect response from the call to get the OAuth token. Our http client was following the redirect with GET, instead of with POST, which was the method used on the first request. Configuring the client to use "strict" mode changed this behaviour, so the redirect URL was requested with POST, and the token was obtained successfully.

All Answers

VinayVinay (Salesforce Developers) 
Hi,

Check Endpoint URL since issue is only with particular org.

Also check http Post payload format using POSTMAN and you should be able to fix it.

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar
Ignacio Sales 1Ignacio Sales 1
We found the cause of the issue, which had nothing to do with the grant type.

Will write it up here in case it helps someone with a similar problem.

The problem was that we were getting a 302-Redirect response from the call to get the OAuth token. Our http client was following the redirect with GET, instead of with POST, which was the method used on the first request. Configuring the client to use "strict" mode changed this behaviour, so the redirect URL was requested with POST, and the token was obtained successfully.
This was selected as the best answer