Skip to main content

Class: Token

Internal representation of a OAuth2/OIDC Token. Contains accessToken, conditionally contains idToken and refreshToken

Remarks

Most operations can be done by Credential methods. It's recommended to use those instead before reaching for a Token method

See

  • Okta Documentation: OIDC

Extends

  • TokenImpl

Implements

Constructors

new Token()

new Token(obj): Token

The constructor of Token

Parameters

obj: TokenJSON

Returns

Token

Inherited from

TokenImpl.constructor

Properties

id

readonly id: string

Inherited from

TokenImpl.id


issuedAt

readonly issuedAt: Date

Implementation of

Expires.issuedAt

Inherited from

TokenImpl.issuedAt


tokenType

readonly tokenType: TokenType

The audience of the token. ex Bearer or DPoP

Inherited from

TokenImpl.tokenType


expiresIn

readonly expiresIn: number

Seconds until token expires

Implementation of

Expires.expiresIn

Inherited from

TokenImpl.expiresIn


scope

readonly scope: undefined | string

OAuth2 / OIDC scopes associated with token

Inherited from

TokenImpl.scope


accessToken

readonly accessToken: string

String value of accessToken

Inherited from

TokenImpl.accessToken


idToken?

readonly optional idToken: JWT

If the OAuth2 configuration includes OIDC, an idToken will be available

Inherited from

TokenImpl.idToken


refreshToken?

readonly optional refreshToken: string

If the OAuth2 configuration includes the scope offline_access, a refreshToken will be available

Inherited from

TokenImpl.refreshToken


context

readonly context: Context

Defines the context this token was issued from

Inherited from

TokenImpl.context

Accessors

expiresAt

get expiresAt(): Date

When the Token will expire, represented as a Date

Returns

Date

Implementation of

Expires.expiresAt

Inherited from

TokenImpl.expiresAt


isExpired

get isExpired(): boolean

Compares this.expiresAt against TimeCoordinator to determine if Token is expired

Returns

boolean

Implementation of

Expires.isExpired

Inherited from

TokenImpl.isExpired


isValid

get isValid(): boolean

Returns true if the Token is not expired

See

Token.isExpired

Returns

boolean

Implementation of

Expires.isValid

Inherited from

TokenImpl.isValid


scopes

get scopes(): string[]

Returns the OAuth2 scope(s) used to issue the token

Returns

string[]

Inherited from

TokenImpl.scopes

Methods

serializer()

static serializer(t): string

Parameters

t: object

Returns

string

Inherited from

TokenImpl.serializer


isEqual()

static isEqual(lhs, rhs): boolean

Parameters

lhs: Token

rhs: Token

Returns

boolean

Inherited from

TokenImpl.isEqual


decode()

static decode<T>(encoded): T

Type Parameters

T

Parameters

encoded: string

Returns

T

Inherited from

TokenImpl.decode


merge()

merge(token): Token

Used to merge separate Token instances together. Useful when handling token refresh as not every value is returned in a refresh request compared to the initial token request

Parameters

token: Token

the "old" token instance to be merged into the "new" token

Returns

Token

new Token instance

Inherited from

TokenImpl.merge


serialize()

serialize(): string

Returns

string

Inherited from

TokenImpl.serialize


authorize()

authorize(input, init?): Promise<Request>

Signs a outgoing Request with an Authorization header. Accepts the same method signature as fetch

Parameters

input: string | URL | Request

init?: RequestInit

Returns

Promise<Request>

Request wrapped in a Promise

TODO: add dpop support (method is async for this purpose)

Inherited from

TokenImpl.authorize


toJSON()

toJSON()

toJSON(): Record<string, unknown>

Returns

Record<string, unknown>

Inherited from

TokenImpl.toJSON

toJSON()

toJSON(): TokenJSON

Converts a Token instance to an serializable object literal representation

Returns

TokenJSON

Inherited from

TokenImpl.toJSON


encode()

encode(): string

Returns

string

Implementation of

Codable.encode

Inherited from

TokenImpl.encode