Autodesk-Forge / forge-api-nodejs-client

Forge Node.js SDK: Provides Node.js SDK to help you easily integrate Forge REST APIs into the application
Apache License 2.0
124 stars 86 forks source link

autoRefresh example? #14

Closed leefsmp closed 7 years ago

leefsmp commented 7 years ago

Can you show a concrete example using autoRefresh = true? Do my client code needs to pass a callback or can I assume calling OAuth2TwoLegged.prototype.getCredentials will always return a valid token? By looking at the implementation it seems to me autoRefresh is not doing anything ...

cyrillef commented 7 years ago

The autoRefresh code is here. As you can see, the autoRefresh will run 300 seconds before the access_token expires and request a new token.

leefsmp commented 7 years ago

Can we change this line of code by the following, that would allow skipping the oauth2client and provide credentials refreshed by custom logic:

if (oauth2client && oauth2client.autoRefresh && new Date(credentials.expires_at - 300).getTime() <= Date.now()) {

Thanks

gregra81 commented 7 years ago

@leefsmp, @cyrillef - fixed