badgateway / oauth2-client

OAuth2 client for Node and browsers
https://www.npmjs.com/package/@badgateway/oauth2-client
MIT License
269 stars 31 forks source link

Token expires_in response formatted as string #123

Closed flackenstein closed 11 months ago

flackenstein commented 11 months ago

If the authentication server client_credentials response has the expires_in formatted as a string grant_base.ts will throw an error.

Body Example: { access_token: "/DsAH2ykgeGGfbLY7GEhduWMCc9H0Gih1XVrUZQaeNJNJONEWJm0uuZpmrXSK5mzMXC5jEXSJVjYpF+Xy6FRdarw646T+4pPaJ5KMawlaVY=", expires_in: "2700", token_type: "Bearer", }

Code block at line 114 in grant_base.ts:

if ( body.expires_in !== undefined && typeof body.expires_in !== "number" ) { throw new TokenResponseError( "expires_in is not a number", response, ); }

Testing for both number and string would handle this situation and in the tokens.expiresIn assignment below convert type from string to number if needed.

evert commented 11 months ago

This sounds like a bug in your server. What server is this?

flackenstein commented 11 months ago

Net Documents API -- it's a legal documents platform. They have a few idiosyncrasies in how they implement OAuth which are easy to work around, but this was the only issue to cause a problem.

https://www.netdocuments.com

evert commented 11 months ago

Actually i think you might be confused. Neither that line nor that file exists in this project. I think this client would handle expires_in as a string (wrong as it may be lol)