Members
(constant) ASYMMETRIC_JWS_ALGS
Asymmetric JWS algorithms this library can verify (via jose, in browsers and Node.js).
(constant) CAEP
OpenID CAEP 1.0 event types.
- Source:
(constant) DEFINITE_JOSE_ERRORS
jose errors that say the SET itself is bad. Anything else (fetching the JWKS, a key it doesn't hold yet) may pass.
- Source:
(constant) DELIVERY
SSF delivery methods.
- Source:
(constant) DPOP_ALGS
DPoP proof algorithms this library can create, in preference order.
(constant) ENDPOINTS
Endpoints whose URLs must use TLS.
- Source:
(constant) FRONT_CHANNEL_TOKENS
Parameters that must never arrive at a code-flow redirect URI (tokens in the front channel).
- Source:
(constant) INTERACTION_REQUIRED
Errors the OP answers a prompt=none request with when it would have to show the person a screen
(OpenID Connect Core §3.1.2.6). account_selection_required is what an OP holding several signed-in
accounts answers when nothing in the request says which one.
- Source:
(constant) MUST_MATCH
Client metadata values the server must honour exactly as requested; if it registers something else (OIDC Dynamic Client Registration 1.0 §3.2 allows substitution) the registration is rejected.
- Source:
(constant) NAMED_HANDLERS
Named handler slots. Each maps to one event type URI and gets a matching on<Name>(handler) method.
- Source:
(constant) PROFILE_CLAIMS
ID token claims an account record keeps, for display and for naming the account to the OP. No tokens.
- Source:
(constant) RESERVED_AUTHORIZATION_PARAMS
Authorization request parameters extraParams may not set: the client sets them, and the callback relies on them.
- Source:
(constant) RISC
OpenID RISC 1.0 event types (receivable through onEvent(RISC.X, handler)).
- Source:
(constant) SSF
OpenID Shared Signals Framework 1.0 stream-control event types.
- Source:
(constant) SSF_URL_MEMBERS
SSF transmitter metadata members that are URLs, all of which must use TLS.
- Source:
(constant) SUPPORTED_ID_TOKEN_ALGS
ID token algorithms this library can verify. A public client has no secret, so HS* (MACed with the client secret) is not among them.
(constant) Subject
Helpers for RFC 9493 Subject Identifiers, as carried in the SET sub_id claim.
- Source:
Methods
accountKey(iss, sub) → {Promise.<string>}
The account key for an iss and sub: stable, opaque, and safe in a storage key or a URL.
Parameters:
| Name | Type | Description |
|---|---|---|
iss |
string | |
sub |
string |
- Source:
Returns:
- Type
- Promise.<string>
base64url()
base64url without padding.
clearDiscoveryCache()
Clears the in-process metadata cache (mostly useful in tests).
- Source:
codeChallengeS256()
RFC 7636 §4.2 S256 transformation.
complex()
SSF complex subject, e.g. { user: Subject.issSub(...), session: Subject.opaque(sid) }
- Source:
deleteClientRegistration(registration, optsopt)
Deletes a registration (RFC 7592 §2.3).
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
registration |
ClientRegistration | ||
opts |
Object |
<optional> |
(TypeScript: |
- Source:
digest()
SHA-256/384/512 digest of a string.
discoverOpenIdProvider(issuer, optsopt)
Retrieves and validates OpenID Provider metadata from <issuer>/.well-known/openid-configuration.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
issuer |
string | ||
opts |
Object |
<optional> |
(TypeScript: |
- Source:
discoverSSFTransmitter(issuer, optsopt)
Retrieves SSF 1.0 transmitter metadata from /.well-known/ssf-configuration
(RFC 8414-style path insertion first, then the appended form).
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
issuer |
string | ||
opts |
Object |
<optional> |
(TypeScript: |
- Source:
eventName()
Short name ("session-revoked") for an event type URI.
- Source:
fetchMetadata(urls, expectedIssuer, optsopt)
Fetches metadata from the first URL that answers 2xx and checks that its issuer matches exactly.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
urls |
Array.<string> | ||
expectedIssuer |
string | ||
opts |
Object |
<optional> |
(TypeScript: |
- Source:
generateCodeVerifier()
RFC 7636 §4.1: 43–128 chars; 32 random bytes → 43 base64url chars.
httpRequest(url, optsopt)
Thin fetch wrapper with timeout and consistent error handling.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
url |
string | URL | ||
opts |
* |
<optional> |
(TypeScript: |
htuOf(url) → {string}
The htu of a request: its URL without query and fragment (RFC 9449 §4.2).
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string | URL |
Returns:
- Type
- string
isLoopback()
Loopback hosts, where plain http is acceptable (RFC 8252 §7.3, RFC 9700 §2.6).
isSecureUrl()
https, or plain http to a loopback host. Anything unparseable is not secure.
logEventReceived(event) → {void}
The default onEventReceived hook: prints one line per accepted event to the console, naming the
event and its jti only. The payload and subject can carry personal data (email, phone, session id,
IP address), and a console is read by extensions and error reporters, so they are left out.
Call it from your own hook to keep the line.
Parameters:
| Name | Type | Description |
|---|---|---|
event |
SecurityEvent |
- Source:
Returns:
- Type
- void
needsInteraction(err) → {boolean}
True when err is an OAuthError that a request showing the sign-in screen (no prompt=none) would get past.
Parameters:
| Name | Type | Description |
|---|---|---|
err |
unknown |
- Source:
Returns:
- Type
- boolean
oidcDiscoveryUrl(issuer)
Builds the OpenID Connect Discovery 1.0 §4 URL: the well-known suffix is appended to the issuer.
Parameters:
| Name | Type | Description |
|---|---|---|
issuer |
string |
- Source:
onceEvent()
Resolves when emitter next emits event, with the event's arguments.
opaqueIs()
An opaque identifier naming exactly id: both must be non-empty strings.
- Source:
randomToken()
A cryptographically random base64url string (default 256 bits).
readClientRegistration(registration, optsopt)
Reads the current registration (OIDC DCR §4 / RFC 7592 §2.1).
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
registration |
ClientRegistration | ||
opts |
Object |
<optional> |
(TypeScript: |
- Source:
readJson(res, ErrorClassopt)
Reads a JSON body; turns OAuth error bodies and non-2xx responses into errors.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
res |
Response | ||
ErrorClass |
* |
<optional> |
(TypeScript: |
refreshLock()
The lock one key's refreshes and deletes share, across this origin's tabs.
- Source:
registerClient(providerMetadata, clientMetadata, optsopt) → {Promise.<ClientRegistration>}
Registers a client with an OpenID Provider (OpenID Connect Dynamic Client Registration 1.0, RFC 7591).
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
providerMetadata |
Record.<string, any> | OP metadata; must advertise |
|
clientMetadata |
Record.<string, any> | e.g. { redirect_uris, id_token_signed_response_alg, grant_types, ... } |
|
opts |
Object |
<optional> |
(TypeScript: |
- Source:
Returns:
- Type
- Promise.<ClientRegistration>
subjectMatches(subId, identity) → {boolean}
Tests whether a subject identifier refers to a known identity.
identity fields: iss, sub, sid (session id), email and email_verified, phone_number and
phone_number_verified, plus any of device/application/tenant/org_unit/group as opaque ids.
- An email or phone number identifies somebody only when the OP said it was verified
(
email_verified/phone_number_verifiedtrue): OIDC Core §5.7 makes neither a stable or unique identifier, and an unverified one may be anybody's. - A top-level opaque id is compared with
sub. A session is named inside a complex subject. - In a complex subject every member must match, and the members this identity can't be checked
against count as a non-match: an event about one session matches only an identity holding that
sid.
Parameters:
| Name | Type | Description |
|---|---|---|
subId |
Record.<string, any> | An RFC 9493 subject identifier, e.g. a SET's |
identity |
Record.<string, any> |
- Source:
Returns:
- Type
- boolean
timingSafeEqual()
Compares two strings in time independent of where they differ, so a response's state or a logout
state cannot be guessed byte by byte from timing. Both sides are hashed first so their lengths match.
(async) tokenHash()
at_hash: left-most half of the hash of the ASCII value, base64url encoded (OIDC Core §3.1.3.6).
- Source:
validateOpenIdProviderMetadata(metadata, expectedIssueropt) → {Record.<string, any>}
Validates an OpenID Provider metadata document (OIDC Discovery 1.0 §3) for use by a code-flow RP.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
metadata |
Record.<string, any> | ||
expectedIssuer |
string |
<optional> |
When given, |
- Source:
Returns:
the same metadata
- Type
- Record.<string, any>
wantsDpopNonce(response) → {boolean}
Whether a resource server's 401 asks for a (new) DPoP nonce (RFC 9449 §9).
Parameters:
| Name | Type | Description |
|---|---|---|
response |
Response |
Returns:
- Type
- boolean
wellKnownUrls(issuer, suffix)
Builds RFC 8414 §3-style well-known URLs: the suffix is inserted between host and path. Some deployments instead append it (OIDC style), so both are returned in preference order.
Parameters:
| Name | Type | Description |
|---|---|---|
issuer |
string | |
suffix |
string | e.g. "ssf-configuration" |
- Source:
withLock(name, fn) → {Promise.<T>}
Runs fn holding the lock name: across every tab of this origin where the Web Locks API exists
(navigator.locks), otherwise within this JavaScript realm only.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | |
fn |
function | (TypeScript: |
Returns:
- Type
- Promise.<T>
Type Definitions
Account
One person signed in through this client in this browser. Holds no token.
Type:
- object
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
key |
string | Stable id derived from |
|
iss |
string | ||
sub |
string | ||
sid |
string |
<optional> |
The OP session (OpenID Connect Front-/Back-Channel Logout |
name |
string |
<optional> |
|
email |
string |
<optional> |
|
preferred_username |
string |
<optional> |
|
status |
'signed-in' | 'tokens-missing' | 'signed-out' | 'ended' |
|
|
endedReason |
string |
<optional> |
|
addedAt |
number | ||
lastUsedAt |
number | ||
changedAt |
number |
<optional> |
When the status last left |
- Source:
Account
(TypeScript: import('./accounts.js').Account)
Type:
- *
AccountHook(account, access) → {unknown}
Parameters:
| Name | Type | Description |
|---|---|---|
account |
Account | |
access |
function | (TypeScript: |
- Source:
Returns:
Anything; a promise is awaited.
- Type
- unknown
AccountHook
(TypeScript: import('./accounts.js').AccountHook)
Type:
- *
AccountManagerOptions
Type:
- object
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
store |
* |
<optional> |
(TypeScript: |
tabStore |
* |
<optional> |
(TypeScript: |
storeKey |
string |
<optional> |
Default "accounts". |
refreshSkewSec |
number |
<optional> |
Default 60. |
maxAccounts |
number |
<optional> |
Default 10. Past it the account signed out longest ago is forgotten; when every place is held by a signed-in account, a further sign-in is refused. |
rememberSignedOutDays |
number |
<optional> |
How long a signed-out account stays listed. Default 30. |
loginHint |
function |
<optional> |
(TypeScript: |
onActivate |
AccountHook |
<optional> |
Runs when an account is about to become this tab's active account, after its tokens are refreshed if due and before "activated" is emitted — e.g. to poll its CAEP stream and act on the signals queued while it was dormant. Throwing aborts the activation. |
onDeactivate |
function |
<optional> |
(TypeScript: |
onLeave |
AccountHook |
<optional> |
Runs before an account's tokens are deleted by |
broadcast |
boolean |
<optional> |
Tell this origin's other tabs about changes (BroadcastChannel). Default true. |
- Source:
AccountManagerOptions
(TypeScript: import('./accounts.js').AccountManagerOptions)
Type:
- *
ClientRegistration
(TypeScript: import('./registration.js').ClientRegistration)
Type:
- *
ClientRegistration
Client Information Response (RFC 7591 §3.2.1 / OIDC DCR §3.2)
Type:
- object
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
client_id |
string | ||
client_secret |
string |
<optional> |
|
client_secret_expires_at |
number |
<optional> |
|
registration_access_token |
string |
<optional> |
RFC 7592 / OIDC DCR §3.2 |
registration_client_uri |
string |
<optional> |
|
id_token_signed_response_alg |
string |
<optional> |
|
token_endpoint_auth_method |
string |
<optional> |
- Source:
KeyStore
Where a DPoP key pair is kept between page loads. extractable: true says the store can only hold an
extractable key (Web Storage holds strings), so DPoPKey.loadOrCreate generates one.
Type:
- object
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
get |
function | (TypeScript: |
|
set |
function | (TypeScript: |
|
delete |
function | (TypeScript: |
|
extractable |
boolean |
<optional> |
KeyStore
(TypeScript: import('./dpop.js').KeyStore)
Type:
- *
OIDCClientConfig
(TypeScript: import('./oidc-client.js').OIDCClientConfig)
Type:
- *
OIDCClientConfig
Type:
- object
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
issuer |
string |
<optional> |
Issuer; metadata is loaded from |
metadata |
Record.<string, any> |
<optional> |
A provider metadata document to use instead of discovery. |
clientId |
string | A PUBLIC client (token_endpoint_auth_method "none"). |
|
redirectUri |
string |
<optional> |
|
postLogoutRedirectUri |
string |
<optional> |
|
scope |
string |
<optional> |
Default "openid profile email offline_access" (offline_access only if supported). |
resource |
string | Array.<string> |
<optional> |
RFC 8707 resource indicator(s): audience-restricts the tokens. |
idTokenSignedResponseAlg |
string |
<optional> |
Expected ID token |
par |
'auto' | 'always' | 'never' |
<optional> |
Pushed Authorization Requests (RFC 9126). Default "auto": used when advertised. |
dpop |
* |
<optional> |
(TypeScript: |
userinfoSignedResponseAlg |
string |
<optional> |
The only |
requireDpop |
boolean |
<optional> |
With DPoP enabled, refuse a token response whose token_type is Bearer
(RFC 9449 §5: the AS may fall back, but this client asked for bound tokens). Default: true when
|
transactionStore |
TransactionStore |
<optional> |
Where state/nonce/PKCE verifier wait for the callback (default sessionStorage). |
transactionTtlSec |
number |
<optional> |
How long an authorization request stays redeemable (default 600). |
maxIdTokenAgeSec |
number |
<optional> |
Reject ID tokens whose |
enforceAcr |
boolean |
<optional> |
When acr_values were requested, require the ID token's |
requireAuthTime |
boolean |
<optional> |
Require |
allowInsecureRequests |
boolean |
<optional> |
Allow non-TLS endpoints and redirect URIs other than loopback (default false). |
clockToleranceSec |
number |
<optional> |
Allowed clock skew (default 30). |
httpTimeoutMs |
number |
<optional> |
Per-request timeout (default 10000). |
discoveryCacheTtlMs |
number |
<optional> |
How long discovered metadata is cached (default 1h). |
fetch |
* |
<optional> |
(TypeScript: |
- Source:
SSFErrorContext
Where an error came from.
Type:
- object
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
phase |
'poll' | 'handler' | 'hook' | 'stop' | 'error' |
|
|
jti |
string |
<optional> |
The SET concerned, when there is one. |
event |
SecurityEvent |
<optional> |
The event whose handler threw. |
willRetry |
boolean |
<optional> |
The SET was left for the transmitter to send again. |
- Source:
SSFErrorContext
(TypeScript: import('./caep/ssf-receiver.js').SSFErrorContext)
Type:
- *
SSFErrorHandler(error, context) → {void}
Parameters:
| Name | Type | Description |
|---|---|---|
error |
* | (TypeScript: |
context |
SSFErrorContext |
- Source:
Returns:
- Type
- void
SSFErrorHandler
(TypeScript: import('./caep/ssf-receiver.js').SSFErrorHandler)
Type:
- *
SSFReceiverConfig
Type:
- object
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
transmitterIssuer |
string | SSF transmitter issuer; metadata is loaded from its |
|
audience |
string | Array.<string> |
<optional> |
Expected SET |
eventsRequested |
Array.<string> |
<optional> |
Default: all CAEP event types. |
accessToken |
function |
<optional> |
(TypeScript: |
authorizationHeaders |
function |
<optional> |
(TypeScript: |
streamId |
string |
<optional> |
Use an existing stream instead of creating one. |
description |
string |
<optional> |
|
pollIntervalMs |
number |
<optional> |
Default 5000. |
maxEvents |
number |
<optional> |
Max SETs per poll. Default 25. |
clockToleranceSec |
number |
<optional> |
Default 60. |
maxSetAgeSec |
number |
<optional> |
Reject SETs whose |
maxDeliveryAttempts |
number |
<optional> |
How many times a SET whose handlers throw is left for the
transmitter to send again before it is acknowledged anyway ( |
allowInsecureRequests |
boolean |
<optional> |
Allow non-TLS SSF URLs other than loopback. Default false. |
deleteOnPageHide |
boolean |
<optional> |
Delete the stream, best effort, when the page is unloaded for good
( |
pageEvents |
Object |
<optional> |
Where |
trustedPollOrigins |
Array.<string> |
<optional> |
Origins besides the transmitter's issuer and configuration_endpoint that the stream's poll endpoint_url may be at. The poll request carries the person's access token, so it is refused anywhere else. |
requireTyp |
boolean |
<optional> |
Require the |
jtiCacheSize |
number |
<optional> |
Replay-protection window size. Default 10000. |
httpTimeoutMs |
number |
<optional> |
|
fetch |
* |
<optional> |
(TypeScript: |
handlers |
* |
<optional> |
(TypeScript: |
onEventReceived |
SecurityEventHandler | null |
<optional> |
Your logic for every accepted event: called
once per event, before the typed handlers, and awaited. Default |
- Source:
SSFReceiverConfig
(TypeScript: import('./caep/ssf-receiver.js').SSFReceiverConfig)
Type:
- *
SecurityEvent
What every handler receives.
Type:
- object
Properties:
| Name | Type | Description |
|---|---|---|
type |
string | Event type URI. |
name |
string | Short name, e.g. "session-revoked". |
payload |
Record.<string, any> | The event-specific object from the SET |
subject |
Record.<string, any> | undefined | RFC 9493 subject identifier ( |
eventTimestamp |
number | undefined | CAEP |
initiatingEntity |
string | undefined | "admin" | "user" | "policy" | "system" |
reasonAdmin |
Record.<string, string> | undefined | |
reasonUser |
Record.<string, string> | undefined | |
jti |
string | |
iss |
string | |
aud |
string | Array.<string> | |
iat |
number | |
txn |
string | undefined | |
set |
Record.<string, any> | All validated SET claims. |
raw |
string | The SET as received (compact JWS). |
- Source:
SecurityEvent
(TypeScript: import('./caep/ssf-receiver.js').SecurityEvent)
Type:
- *
SecurityEventHandler(event) → {unknown}
Parameters:
| Name | Type | Description |
|---|---|---|
event |
SecurityEvent |
- Source:
Returns:
Anything; a promise is awaited before the SET is acknowledged.
- Type
- unknown
SecurityEventHandler
(TypeScript: import('./caep/ssf-receiver.js').SecurityEventHandler)
Type:
- *
StoredKey
Type:
- object
Properties:
| Name | Type | Description |
|---|---|---|
alg |
string | |
keyPair |
CryptoKeyPair |
StoredKey
(TypeScript: import('./dpop.js').StoredKey)
Type:
- *
StoredTokens
(TypeScript: import('./stores.js').StoredTokens)
Type:
- *
StoredTokens
A token set as a store keeps it (TokenSet#toJSON()).
Type:
- Record.<string, any>
TokenStore
(TypeScript: import('./stores.js').TokenStore)
Type:
- *
TokenStore
Storage for tokens and for in-flight authorization transactions.
Token store interface (async or sync methods):
Type:
- object
Properties:
| Name | Type | Description |
|---|---|---|
get |
function | (TypeScript: |
set |
function | (TypeScript: |
delete |
function | (TypeScript: |