Salesforce returns "unsupported_grant_type"

We implemented OAuth 2.0 using the web server authentication flow. It worked great in October / November, but suddenly it stopped working. Whenever we try to resolve another client, the server returns (400) "Bad request" with the body

{"error":"unsupported_grant_type","error_description":"grant type not supported"} 

grant_type is set as authorization_code, which is definitely valid.

Is there a reason OAuth suddenly stops working?


Here's how we implemented OAuth:

The first user is redirected to: https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=blah.id&redirect_uri=https://domain.com/Web/Salesforce/Callback.aspx&scope=api%20refresh_token

A user asks Salesforce to log in to their account.

As soon as the user authenticates, Salesforce calls Callback.aspx, Callback.aspx requests an update token on behalf of the client, making a POST request: https://login.salesforce.com/services/oauth2/token with a payload:

grant_type = authorization_code & code = blah.code & client_id = blah.Id & client_secret = 11111111 & redirect_uri = HTTPS://domain.com/Web/Salesforce/Callback.aspx

Content Type Definitely: application / x-www-form-urlencoded

+4
source share
2 answers

After a lot of associates with the help of a violinist found out, there was space before grant_type = authorization_code in the HTTP POST payload that caused the problem.

Interestingly, the space has been in the codebase since July, and this problem was first noticed on January 14th. Perhaps Salesforce corrected the error or made an internal change to reject the space before grant_type = authorization_code.

+2
source

I had it only yesterday. Put the title in, Code: code

This title is undocumented, but it exists in some examples somewhere.

0
source

All Articles