Class: TokenManager

TokenManager(client, optsopt)

Caches GrantSets per key (typically one per signed-in person) and keeps their access tokens fresh by GNAP token rotation (RFC 9635 section 6.1).

  • getTokenSet(key) always returns a token valid for at least refreshSkewSec, rotating on demand.
  • With autoRefresh (default), a timer rotates each token refreshSkewSec before it expires.
  • Concurrent rotations for the same key are coalesced into one request; across tabs sharing a store, a rotation holds a Web Lock and reuses the token another tab has just obtained, so a management token is never presented twice.

Events: "rotated" (key, grantSet) — a new access token obtained by rotation "rotation_error" (key, error) — rotation failed (tokens are dropped when the grant is gone) "expired" (key) — tokens for key could not be renewed and were removed "removed" (key) — tokens deleted via delete()

Constructor

new TokenManager(client, optsopt)

Parameters:
Name Type Attributes Description
client *

(TypeScript: import('./gnap-client.js').GNAPClient)

opts Object <optional>

(TypeScript: { store?: import('./stores.js').TokenStore, refreshSkewSec?: number, autoRefresh?: boolean, minRefreshDelayMs?: number, retryDelayMs?: number })

Source:

Classes

TokenManager

Methods

close()

Cancels all rotation timers (call on shutdown).

Source:

(async) delete(key, optsopt) → {Promise.<(GrantSet|undefined)>}

Removes the grant for key, optionally revoking it at the AS: the whole grant (section 5.4), or with revoke: 'token' only its access token (section 6.2).

Parameters:
Name Type Attributes Description
key string
opts Object <optional>

(TypeScript: { revoke?: boolean|'grant'|'token' })

Source:
Returns:
Type
Promise.<(GrantSet|undefined)>

(async) get(key) → {Promise.<(GrantSet|undefined)>}

Parameters:
Name Type Description
key string
Source:
Returns:

The cached grant (possibly expired) for key.

Type
Promise.<(GrantSet|undefined)>

(async) getTokenSet(key, optsopt) → {Promise.<GrantSet>}

Returns the cached grant for key, rotating first if the access token is (nearly) expired.

Parameters:
Name Type Attributes Description
key string
opts Object <optional>

(TypeScript: { forceRefresh?: boolean })

Source:
Returns:
Type
Promise.<GrantSet>

rotate(key) → {Promise.<GrantSet>}

Rotates key's access token now. Concurrent calls share a single request.

Parameters:
Name Type Description
key string
Source:
Returns:
Type
Promise.<GrantSet>

(async) schedule(key) → {Promise.<void>}

Schedules the proactive rotation of the token already stored for key.

Parameters:
Name Type Description
key string
Source:
Returns:
Type
Promise.<void>

(async) set(key, grantSet, optsopt) → {Promise.<GrantSet>}

Stores a grant for a key and (unless schedule: false) schedules its proactive rotation.

Parameters:
Name Type Attributes Description
key string
grantSet GrantSet | object
opts Object <optional>

(TypeScript: { schedule?: boolean })

Source:
Returns:
Type
Promise.<GrantSet>

unschedule(key)

Stops rotating key's token in the background; it stays stored.

Parameters:
Name Type Description
key string
Source: