Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Salesforce Refresh Token OAuth

Tags:

salesforce

I am trying to refresh the access token using the refresh token:

curl https://login.salesforce.com/services/oauth2/token -d "grant_type=refresh_token&client_id=3MVG9pHRjzOBdkd.WU9DLyfznP.sjOJRXXX_00nLDYSpM_0K7zAOsLrRKf6IWmCv6MxeTorXL7Zzaaea8IXXX&client_secret=3231123171523457&refresh_token=5Aep861VUUSqKxtr91VaZ7Zh54RmFqHE6zD4htOq6vY9edPgkgm9ZeFPwHIzQQvR__XypcEvWnXXX==&format=json"

But I keep getting the error "error_description":"expired access/refresh token"

Anyone have any idea?

like image 635
john smith Avatar asked May 04 '12 19:05

john smith


People also ask

Does OAuth use refresh token?

It is designed to allow an application to access resources hosted by other servers on behalf of a user. OAuth 2.0 uses Access Tokens and Refresh Tokens.

What is refresh token Salesforce?

After a client—via a connected app—receives an access token, it can use a refresh token to get a new session when its current session expires. The connected app's session timeout value determines when an access token is no longer valid and when to apply for a new one using a refresh token.

Do refresh tokens expire OAuth?

By default, access tokens are valid for 60 days and programmatic refresh tokens are valid for a year. The member must reauthorize your application when refresh tokens expire.


2 Answers

I know this is old, but for people that may stumble on this. I believe this issue is that you can only have 5 access grants per applications. After this it starts revoking refresh tokens from the oldest one. More info here:

  • Manage OAuth Access for Your Connected Apps
  • invalid_grant —expired access/refresh token | Issue #80
like image 79
rjbez Avatar answered Oct 05 '22 23:10

rjbez


You have the correct syntax for using a refresh token. Make sure all of your parameters are URL encoded, since in your example your refresh token has = instead of %3D.

You can also delete the user's refresh token by going to that user's User Detail page inside of setup and revoking the "Remote Access" near the bottom. Then obtain a new refresh token by going through the oauth flow again and try it in the curl command.

like image 30
willywu Avatar answered Oct 05 '22 23:10

willywu