Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Automatically refresh token #256

Open
dobesv opened this issue Feb 11, 2020 · 0 comments
Open

Automatically refresh token #256

dobesv opened this issue Feb 11, 2020 · 0 comments

Comments

@dobesv
Copy link

dobesv commented Feb 11, 2020

It would be nice if the client would check the expiry time on the access token and refresh it if it will expire within the next minute.

Or at least offer a method we can call that checks the expiry time and refreshes if the expiration time is within a specified time limit.

Something like:

refreshAccessTokenIfExpiring(secs=60) {
    const expiresAt = this.accessTokenExpiresIn + this.accessTokenUpdatedAt - secs;
    if(Date.now()/1000 >= (this.accessTokenExpiresIn + this.accessTokenUpdatedAt - secs))
      return this.oauth.refreshAccessToken()    
  }
}
// ...
apiRequest(opts) {
    const params = prepareParams(opts, this)
    return this.checkApiLimit(params).then(() => this.refreshAccessTokenIfExpiring()).then(() => ...)
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant