1

When I first authenticate to Salesforce, I get an access token and a refresh token. But if the access token has expired I make a call using the refresh token to get a new access token, but in the response there is no new refresh token.

Is that correct? Does the refresh token never expire for Salesforce?

Here is the call I am making to get a new access token using the refresh call.

var client = new RestClient("https://myOrg.salesforce.com/services/oauth2/token");
var request = new RestRequest("", Method.POST);
request.AddParameter("refresh_token", {currentRefreshToken}, ParameterType.GetOrPost);
request.AddParameter("grant_type", "refresh_token", ParameterType.GetOrPost);
request.AddParameter("client_id", {clientId}, ParameterType.GetOrPost);
request.AddParameter("client_secret", {clientsecret}, ParameterType.GetOrPost);
var response = client.Execute(request);

I would have expected a new Refresh token in the response.

7
  • Can you please add a snapshot of error/results you got when you tried to make a call, it should be "Session expired or invalid" and also you can check in Setup | Session settings for session timout whether it is set to some random value or never expire(not sure). Also check if you have set the right url/org instance. Commented Mar 22, 2022 at 4:56
  • the above does return a json result , except in the result there is no refresh_token. Does the refersh token get refreshed in this stage . So when a user request a new access token using the refresh token , do they get a refreshed refresh token , thats what im asking ? Or do they only get a refresh token when they call the grant_type = authorization_code" ?
    – Kelly
    Commented Mar 22, 2022 at 5:03
  • Refresh token is used to get the access token. Refer the this article help.salesforce.com/s/… Commented Mar 22, 2022 at 5:16
  • yes grant_type = authorization_code along with consumer_key and client_secret Commented Mar 22, 2022 at 5:16
  • ok let me rephrase it. Does the refresh token ever expire ?
    – Kelly
    Commented Mar 22, 2022 at 5:17

1 Answer 1

5

Access Tokens are governed through the global Session Settings or the Profile Session Settings, while Refresh Tokens are controlled via OAuth Access Policies. You simply reuse a Refresh Token as long as it is valid, which can be one of: "until revoked", "immediately", "inactive for x time", or "until x time has passed". If you lose the Refresh Token, it is expired, or revoked, the user will need to log in again. At this point, you would receive a new Refresh Token as part of the login flow. Note that Refresh Tokens will survive password resets, Security Token resets, and changing the username entirely. This makes them very durable for the purposes of maintaining a session in an app.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .