1

This question already has an answer here:

My company is using the OAuth "Refresh Token" flow, and can get an accessToken and refreshToken fine using this flow.

The problem I'm having is that the responses we receive from Salesforce don't have an exp field in them, so we don't know how long an accessToken lives for.

{  
   "id":"https://login.salesforce.com/id/00Dx0000000BV7z/005x00000012Q9P",
   "issued_at":"1278448384422",
   "instance_url":"https://yourInstance.salesforce.com/",
   "signature":"SSSbLO/gBhmmyNUvN18ODBDFYHzakxOMgqYtu+hDPsc=",
   "access_token":"someValue",
   "token_type":"Bearer",
   "scope":"id api refresh_token"
}

Is there a way to find out how long the accessToken lives for?

We can change our request of course to include different scopes if need be.

Note that I've noticed that there's a beta endpoint that lets you request this information, but it feels to me like something that should be returned with the accessToken and refreshToken.

marked as duplicate by gNerb, David Reed, glls, codeyinthecloud, battery.cord Dec 19 '18 at 21:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    I think this answer is still applicable: salesforce.stackexchange.com/questions/73512/… – David Cheng Dec 19 '18 at 15:59
  • One way could be to calculate using issued_at. A token will live for the duration specified in the session settings. So as long as you have the issued_at available and you know the session settings duration, you can calculate the token's lifespan. – Jayant Das Dec 19 '18 at 16:07
  • 2
    Access tokens automatically update their expiration if at least half the time has passed since issue and it is used in any API call. Also, a user or admin might terminate the session at any time. It is a lot more efficient to build a framework that expects any given call to potentially fail. – sfdcfox Dec 19 '18 at 16:18

Browse other questions tagged or ask your own question.