cmd-johnson / deno-oauth2-client

Minimalistic OAuth 2.0 client for Deno.
MIT License
45 stars 9 forks source link

Token expires_in returned from auth server as string #40

Open flackenstein opened 11 months ago

flackenstein commented 11 months ago

Working with a NetDocuments OAuth server it returns the client credentials token with expires_in formatted as a string and not a number.

Would it be possible to modify grant_base.ts parseTokenResponse method to support expires_in as both number and string and convert to number if needed prior to assignment to tokens.expires_in?

Example Concept...

if (
  ! ['number', 'string'].includes(typeof body.expires_in)
) {
  throw new TokenResponseError(
    "expires_in is not a string or number",
    response,
  );
}

....

if (body.expires_in) {
  if (typeof body.expires_in == 'string') {
    body.expires_in = parseInt(body.expires_in);
  }
  tokens.expiresIn = body.expires_in;
}