Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Should Token type have expires property? #157

Open
moltar opened this issue Aug 5, 2020 · 6 comments
Open

Should Token type have expires property? #157

moltar opened this issue Aug 5, 2020 · 6 comments

Comments

@moltar
Copy link

moltar commented Aug 5, 2020

From console.log it does appear that this property is available, but it is not exposed.

Is it a private property or can it be made public?

{
      // ... snip

      tokenType: 'bearer',
      accessToken: '...',
      refreshToken: '...',

      // THIS
      expires: 2020-08-05T10:54:20.704Z
}

https://github.com/mulesoft/js-client-oauth2/blob/a237644785b4910689dd72f1c5d6905fa3a88ae7/index.d.ts#L61-L72

@jasonterando
Copy link

Seconded. We need a mechanism to renew the token before it expires

@ErwinSteffens
Copy link

ErwinSteffens commented Jan 27, 2021

Bumping this one. Really needed!

Maybe add a timespan to the expired method like:

/**
 * Check whether the token has expired.
 *
 * @return {boolean}
 */
ClientOAuth2Token.prototype.expired = function (marginSeconds) {
  var expireTime = this.expires.getTime()
  if (marginSeconds) {
    expireTime -= marginSeconds;
  }
  return Date.now() > expireTime
}

@whatsrupp
Copy link

I'm just migrating our use of this library to typescript, we've been depending on the expires property to know when to call refresh on the token in a long running process.

So +1 for: "Is expires a private or public property?

If it's just a case of updating the types, then I'd happily open a PR

@edneypitta
Copy link

as a workaround I'm doing:

const expiresIn = parseInt(accessToken.data.expires_in) || 0;
accessToken.expiresIn(expiresIn - EXPIRATION_WINDOW_IN_SECONDS);

@saitho
Copy link

saitho commented Apr 25, 2021

+1 for saving an expiry date instead of a expires_in number.
I'm serializing the token data and load it when needed, so the expiry time gets reinitialized every time I load the data into the Oauth2 object. ^^

@mgara
Copy link

mgara commented Oct 27, 2021

@ErwinSteffens is it expireTime -= marginSeconds or expireTime += marginSeconds ??
I did a fork ... I'm about to create a PR with the second option but you mentioned the expireTime -= marginSeconds so I'm like a little bit confused ... :D

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

7 participants