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
jeffatflowdotnetjeffatflowdotnet 

"expired access/refresh token" during OAuth 2.0 Username-Password Flow

I signed up for force.com and created a remote application.

I can successfully complete the OAuth 2.0 username and password flow using my account credentials. And can subsequently fetch *my* data using the API.

However, when I use an account that is not the creator of the remote application, the response I receive is:

{"error":"invalid_grant","error_description":"expired access/refresh token"}

As far as I'm concerned, this is not even an error that I should be seeing, considering I am completing this flow to receieve an access token.

The URL that I am POSTing to is:

https://login.salesforce.com/services/oauth2/token?response_type=token&redirect_uri=REDIRECT_URI


and my POST body is:

grant_type=password&client_id=KEY&client_secret=SECRET&username=EMAIL&password=PASSWORDSECURITY_TOKEN


All variables are replaced with the proper values as outlined in the document http://na9.salesforce.com/help/doc/en/remoteaccess_oauth_username_password_flow.htm

Can anyone see the problem with this?

Best Answer chosen by Admin (Salesforce Developers) 
jeffatflowdotnetjeffatflowdotnet

The Content-type header needs to be set to "application/x-www-form-urlencoded".

Consider adding this to the documentation because the error message that results does not help solve this problem. If you don't want to add that to the documentation, consider adding an error message with relevant HTTP status code, along the lines of "missing content-type header".

All Answers

jeffatflowdotnetjeffatflowdotnet

The Content-type header needs to be set to "application/x-www-form-urlencoded".

Consider adding this to the documentation because the error message that results does not help solve this problem. If you don't want to add that to the documentation, consider adding an error message with relevant HTTP status code, along the lines of "missing content-type header".

This was selected as the best answer
Carling KirkCarling Kirk
I was having this issue and my headers were set correctly.  I turns out I had the url wrong, it needed to be https://test.salesforce.com/services/oauth2/token