Home Reference Source Test Repository
import AccessToken from '@npr/npr-one-sdk/model/access-token.js'
public class | source

AccessToken

A thin wrapper around the raw JSON returned from the authorization server to represent an access token

Test:

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public get

Returns the access token itself (40-character alphanumeric string)

public get

Returns the TTL (in milliseconds) until this access token expires.

Method Summary

Public Methods
public

Returns whether or not this access token has expired.

public

A convenience function to cast this object back to a string, generally only used by the Logger class.

public

Ensure that the given access token model is valid

Public Constructors

public constructor(json: Object) source

Params:

NameTypeAttributeDescription
json Object

The decoded JSON object that should be used as the basis for this model

Test:

Public Members

public get token: string source

Returns the access token itself (40-character alphanumeric string)

Test:

public get ttl: number source

Returns the TTL (in milliseconds) until this access token expires. If you are using an auth proxy and have correctly configured the refreshTokenUrl, this SDK will automatically refresh expired access tokens for you, so consumers typically do not need to worry about whether or not a token is expired or about to expire.

Test:

Public Methods

public isExpired(): boolean source

Returns whether or not this access token has expired. Note that due to network latency, etc., it's possible that the internally-stored expiry date could be about a second or so behind, and so this function is not guaranteed to be perfectly accurate.

Return:

boolean

Test:

public toString(): string source

A convenience function to cast this object back to a string, generally only used by the Logger class. In this case, we return only the access_token itself, since the rest of the object is typically not useful.

Return:

string

Test:

public validate() source

Ensure that the given access token model is valid

Throw:

TypeError

if access token model is invalid

Test: