Class: AccountManager

AccountManager(client, optsopt)

Every person signed in through one GNAP client in this browser, with ONE active account per tab.

  • One cache, shared by every tab. Each account's grant (access token, management and continuation) is kept until the account is signed out or its grant ends, so any tab can make any signed-in account active with no trip to the AS.
  • One active account per tab. Only its token is reachable (getTokenSet()), and only its token is rotated in the background. The others are dormant. activate(key) rotates a dormant account's token if due and runs onActivate before it becomes active.
  • Rotations hold a lock shared by the tabs (Web Locks); sign-outs and ended grants are announced to the other tabs (BroadcastChannel).

Signing in: signIn() / addAccount() start a grant the AS decides on (its account picker when several people are signed in there). reauthenticate(key) names the person in the request's user and refuses a grant approved by anybody else. signOut(key) revokes that account's grant at the AS.

Events: "added" (account), "updated" (account), "activated" (account|undefined, previous|undefined), "rotated" (account) for the active account, "signed-out" (account), "ended" (account, reason), "forgotten" (account), "activation_error" (account, error), and "change" after any of them, including changes made in another tab.

Constructor

new AccountManager(client, optsopt)

Parameters:
Name Type Attributes Description
client *

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

opts AccountManagerOptions <optional>
Source:

Classes

AccountManager

Members

active

Source:

Methods

accountsForSubject(subId) → {Array.<Account>}

The accounts a security event's subject (sub_id) is about. A subject naming a session (iya-sts: gnap-grant:<id> or gnap-token:<jti>) matches only the account holding that grant or token.

Parameters:
Name Type Description
subId object
Source:
Returns:
Type
Array.<Account>

(async) activate(key) → {Promise.<(Account|undefined)>}

Makes a listed account this tab's active account; the previous one becomes dormant. Nothing is sent to the AS unless the account's token is due for rotation. When the rotation or onActivate fails, the previously active account is reactivated and the error thrown.

Parameters:
Name Type Description
key string
Source:
Returns:
Type
Promise.<(Account|undefined)>

addAccount(optsopt)

Starts a grant for another person, added as a further account.

Parameters:
Name Type Attributes Description
opts * <optional>

(TypeScript: Parameters<import('./gnap-client.js').GNAPClient['createGrantRequest']>[0])

Source:

close()

Cancels rotation timers and stops listening to other tabs (call on shutdown).

Source:

(async) end(key, reasonopt) → {Promise.<(Account|undefined)>}

Ends an account's session in this browser because the AS or a security event says its grant has ended: onLeave runs, its grant is removed from the cache (not revoked: the AS already knows), and it stays listed as ended with the reason. Does nothing for an account that is not signed in.

Parameters:
Name Type Attributes Description
key string
reason string <optional>
Source:
Returns:
Type
Promise.<(Account|undefined)>

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

Removes an account that is not signed in from the list.

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

get(key)

Parameters:
Name Type Description
key string

@returns {Account|undefined}

Source:

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

The active account's grant, its token rotated first when (nearly) expired.

Parameters:
Name Type Attributes Description
opts Object <optional>

(TypeScript: { forceRefresh?: boolean })

Source:
Returns:
Type
Promise.<GrantSet>

(async) handleCallback(response) → {Promise.<{account: Account, grantSet: GrantSet, intent: string, added: boolean}>}

Completes a grant from the finish redirect. The person it is about is added to the cache (or, when already listed, signed in again) and becomes this tab's active account.

An error is thrown with err.context ({ intent, key? }) and, for reauth, err.account.

Parameters:
Name Type Description
response URLSearchParams | Record.<string, string> | string
Source:
Returns:
Type
Promise.<{account: Account, grantSet: GrantSet, intent: string, added: boolean}>

identity(key) → {Object}

The identity subjectMatches() compares a security event's subject with: iss, sub, the grant's session ids as sid, and a verified email or phone number.

Parameters:
Name Type Description
key string
Source:
Returns:

(TypeScript: { iss: string, sub: string, sid?: string[], email?: string, email_verified?: boolean, phone_number?: string, phone_number_verified?: boolean }|undefined)

Type
Object

(async) init()

Loads the shared account list and reactivates the account this tab had active. A failed reactivation leaves the tab with no active account and is emitted as "activation_error".

Source:

list() → {Array.<Account>}

Source:
Returns:

Every account in this browser, in the order added.

Type
Array.<Account>

reauthenticate(key, optsopt)

Starts a grant for this account's person again: the request names them in user (RFC 9635 section 2.4), and a grant approved by anybody else is refused at the callback (account_mismatch).

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

(TypeScript: Parameters<import('./gnap-client.js').GNAPClient['createGrantRequest']>[0])

Source:

rotate() → {Promise.<GrantSet>}

Rotates the active account's access token now.

Source:
Returns:
Type
Promise.<GrantSet>

signIn(optsopt)

Starts a grant the AS decides on. Resolves { url } to send the browser to; or, when the AS issued the grant with nobody asked, the signed-in account ({ account, grantSet, intent, added }).

Parameters:
Name Type Attributes Description
opts * <optional>

(TypeScript: Parameters<import('./gnap-client.js').GNAPClient['createGrantRequest']>[0])

Source:

(async) signOut(keyopt, optsopt) → {Promise.<(Account|undefined)>}

Signs one account out of this browser: onLeave runs, its grant is revoked at the AS (with revoke, the default) and removed from the cache, and it stays listed as signed-out. GNAP has no front-channel logout: revoking the grant is what ends it, and iya-sts then sends CAEP session-revoked for it.

Parameters:
Name Type Attributes Description
key string <optional>

Default: the active account.

opts Object <optional>

(TypeScript: { revoke?: boolean })

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

(async) signOutAll(optsopt)

Signs every account out of this browser, revoking each grant.

Parameters:
Name Type Attributes Description
opts Object <optional>

(TypeScript: { revoke?: boolean })

Source: