UNPKG

@hyperse/paypal-node-sdk

Version:

NodeJS SDK for PayPal Checkout APIs

39 lines (38 loc) 1.11 kB
/** * Documentation * * @see {@link https://github.com/paypal/Checkout-NodeJS-SDK/blob/develop/lib/core/access_token.js} */ /** * A small amount of time to loosen the token expiration algorithm */ const EXPIRATION_THRESHOLD = 500; /** * An OAuth2 access token * * Documentation * * @see {@link https://github.com/hyperse-io/paypal-node-sdk/tree/main/src/core/AccessToken.ts} */ export class AccessToken { constructor(options) { this._accessToken = options.access_token; this._tokenType = options.token_type; this._expiresIn = options.expires_in * 1000; this._dateCreated = Date.now(); } /** * Get the expiration status of the token * @return - True if the token is expired otherwise false */ isExpired() { return (Date.now() > this._dateCreated + this._expiresIn - EXPIRATION_THRESHOLD); } /** * Get the value of an Authorization header with the current access token * @return The Authorization header value */ authorizationString() { return `${this._tokenType} ${this._accessToken}`; } }