7
votes

We implemented OAuth 2.0 using Web Server Authentication Flow. It was working fine in October/November but all of a sudden it has stopped working. Whenever we try authorising another client the server return (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 any reason why OAuth would suddenly stop working?


This is how we have implemented OAuth:

First user is directed 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

User is prompted by Salesforce to login to their account.

Once user is authenticated Salesforce calls Callback.aspx, Callback.aspx requests refresh token on behalf of the client by making a POST request to: https://login.salesforce.com/services/oauth2/token with the 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 is definitely: application/x-www-form-urlencoded

1
See the detailed answer I provided on this question: stackoverflow.com/questions/12794302/…Calvin Froedge

1 Answers

5
votes

After lot of fiddling around with fiddler figured out there was a space before grant_type=authorization_code in HTTP POST payload that was causing the issue.

Interestingly that space has been there in code base since July and this issue was first noticed on 14th Jan. It is possible Salesforce fixed a bug or made an internal change to reject space before grant_type=authorization_code.