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
Owen MillardOwen Millard 

Just-issued refresh_token fails with "expired access/refresh token"

I'm trying to access the API of a sandbox instance using OAuth. 

1. I redirect the user to test.salesforce.com
2. The user confirms access and is redirected back to me
3. I exchange the code for a refreshToken
4. I immediately exchange the refresh_token for a new access_token using this command:

curl -X POST --data 'refresh_token=[refresh token form step 3]&client_id=[my client id]&client_secret=[my client secret]&grant_type=refresh_token' -H 'Accept: application/json' -H 'Sforce-Call-Options: client=fivetran' -H 'Content-Type: application/x-www-form-urlencoded' 'https://test.salesforce.com/services/oauth2/token'

Salesforce replies:

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

How can the token be expired? It was just issued. I have also used this exact same application logic to connect to production salesforce instances successfully (with a different application configuration, and using login.salesforce.com instead of test.salesforce.com).
Owen MillardOwen Millard
Just wanted to bump this - any help would be appreciated!
Vaughan Coder 6Vaughan Coder 6
Hey Owen, Are you sure your settings on you app is not set to automatically expire any refresh token? Manage Apps-> Connected Apps -> Your App then set  Refresh Token Policy:Refresh token is valid until revoked 
Shraey ChikkerShraey Chikker
Still facing the same issue. Can anyone help? 
Jayapriya VelumaniJayapriya Velumani
I get the below mention error  while trying to get access token using refresh token how to resolve this

{
   "error": "invalid_grant",
   "error_description": "expired access/refresh token"
Jayapriya VelumaniJayapriya Velumani
I got solutions for above queries,
POST /services/oauth2/token HTTP/1.1 Host: login.salesforce.com/ grant_type=refresh_token&client_id=3MVG9lKcPoNINVBIPJjdw1J9LLM82HnFVVX19KY1uA5mu0 QqEWhqKpoW3svG3XHrXDiCQjK1mdgAvhCscA9GE&client_secret=1955279925675241571 &refresh_token=your token here