gnap-caep-client
    Preparing search index...

    Class AccountManager

    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.

    Hierarchy (View Summary)

    Index
    • 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

      • subId: object

      Returns Account[]

    • 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

      • key: string

      Returns Promise<Account | undefined>

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

      Parameters

      • Optionalopts: {
            access?: (string | Record<string, any>)[];
            context?: any;
            expectedSub?: string;
            extra?: Record<string, any>;
            flags?: string[];
            label?: string;
            subject?: boolean;
            user?: Record<string, any>;
        } = {}

      Returns Promise<
          | { account: Account; added: boolean; grantSet: any; intent: any }
          | { url: string },
      >

    • 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

      • key: string
      • Optionalreason: string

      Returns Promise<Account | undefined>

    • 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

      • response: string | Record<string, string> | URLSearchParams

      Returns Promise<
          { account: Account; added: boolean; grantSet: GrantSet; intent: string },
      >

    • 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

      • key: string

      Returns
          | {
              email?: string;
              email_verified?: boolean;
              iss: string;
              phone_number?: string;
              phone_number_verified?: boolean;
              sid?: string[];
              sub: string;
          }
          | undefined

    • 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

      • key: string
      • Optionalopts: {
            access?: (string | Record<string, any>)[];
            context?: any;
            expectedSub?: string;
            extra?: Record<string, any>;
            flags?: string[];
            label?: string;
            subject?: boolean;
            user?: Record<string, any>;
        } = {}

      Returns Promise<
          | { account: Account; added: boolean; grantSet: any; intent: any }
          | { url: string },
      >

    • 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

      • Optionalopts: {
            access?: (string | Record<string, any>)[];
            context?: any;
            expectedSub?: string;
            extra?: Record<string, any>;
            flags?: string[];
            label?: string;
            subject?: boolean;
            user?: Record<string, any>;
        } = {}

      Returns Promise<
          | { account: Account; added: boolean; grantSet: any; intent: any }
          | { url: string },
      >

    • 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

      • Optionalkey: string = ...

        Default: the active account.

      • Optionalopts: { revoke?: boolean } = {}

      Returns Promise<Account | undefined>

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

      Parameters

      • Optionalopts: { revoke?: boolean } = {}

      Returns Promise<void>