Jsforce: How to refresh an expired accessToken ?

Created on 9 Jun 2016  Â·  6Comments  Â·  Source: jsforce/jsforce

Hi,

Currently when we are trying to refresh the expired access token we have to use the refresh token as grant type . There are situations when my refresh token has expired (guess this has something to with 5 connections to a connected app in salesforce) and in this scenario how would i get an access token back ?

should the user start from the beginning where he requests an auth code and establish a connection from there ?

Please let me know. Thanks in advance !
@stomita

question

Most helpful comment

what is the default lifetime of refresh tokens in Salesforce? Mine seems to be expiring after about 1 day (this seems short). Is it possible to increase this time?

All 6 comments

should the user start from the beginning where he requests an auth code and establish a connection from there ?

When you expire the "refresh token", they should do so.

Hi stomata ,
Thanks for the reply. But I don't expire the refresh token. Sales force
does it and when salesforce expires the refresh token even if I try
refreshing the token using grant type equal to refresh token does not work
as it has already expired.

Please find below the steps i tried :

1)create a connection object in my code :

  var conn = new jsforce.Connection({
      oauth2: oauth2,
      accessToken: accessToken,
      refreshToken: refreshToken,
      instanceUrl: instanceURL,
      id: id
  });

2) trying to search a lead/contact in sales force

conn.search(searchQuery,function(err, response) {
//some logic
}

3) Now i get an err in the callback saying "expired access/refresh token"

4) In my case the refresh token has expired.

In this scenario i have tried,

oauth2.refreshToken(refreshToken,function(err, ret) {
//i tired create a new connection
}

This did not work as it was not even returning anything.........

Then i tried

Conn.on(refresh) too and i too did not work. Please let me know your thoughts

@stomita

On Thursday, June 9, 2016, Shinichi Tomita [email protected] wrote:

should the user start from the beginning where he requests an auth code
and establish a connection from there ?

When you expire the "refresh token", they should do so.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/jsforce/jsforce/issues/488#issuecomment-225070925,
or mute the thread
https://github.com/notifications/unsubscribe/AHAlvrW6QYGk1LdsUSp2YXqO9aNZgGKcks5qKLr2gaJpZM4Ix_tL
.

@vivinRajagopalan It doesn't matter who expired the refresh token. The expired refresh token is not useful and you need to ask authorization again by oauth2 flow.

Thanks a lot @stomita

what is the default lifetime of refresh tokens in Salesforce? Mine seems to be expiring after about 1 day (this seems short). Is it possible to increase this time?

How to get a new refresh token

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jbonigomes picture jbonigomes  Â·  3Comments

sushicodeur picture sushicodeur  Â·  3Comments

jimrae picture jimrae  Â·  6Comments

JonDum picture JonDum  Â·  7Comments

stomita picture stomita  Â·  5Comments