npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@axa-fr/oidc-client-service-worker

v7.30.5

Published

OpenID Connect & OAuth authentication service worker

Readme

@axa-fr/oidc-client-service-worker

The service worker used by @axa-fr/oidc-client and @axa-fr/react-oidc. It intercepts OIDC token responses, keeps access and refresh tokens in worker memory by default, and adds access tokens to requests that match your trusted-domain configuration.

Most applications should install one of the client packages rather than use this package directly. The clients handle worker registration and communication.

How it works

flowchart LR
    App["Browser application"] --> Client["OIDC client or React bindings"]
    Client <-->|"Messages and token placeholders"| Worker["OIDC service worker"]
    Worker <-->|"Token requests and responses"| Provider["OIDC provider"]
    App -->|"API request"| Worker
    Worker -->|"Access token on trusted requests"| API["Trusted API"]
    Config["OidcTrustedDomains.js"] --> Worker

The application can use token metadata without receiving the real access or refresh token. showAccessToken: true explicitly exposes the access token to application JavaScript while keeping the refresh token in the worker.

[!IMPORTANT] Token isolation does not prevent XSS or CSRF. Injected code can still make authenticated requests from the application. Use a restrictive Content Security Policy, prevent script injection, and enforce authorization on your APIs.

Getting started

  1. Install and configure the vanilla client or React bindings.

  2. Create your application's public-assets directory if it does not exist, then run the copy command for the client you installed:

    # Vanilla client
    node ./node_modules/@axa-fr/oidc-client/bin/copy-service-worker-files.mjs public
    
    # React — use this instead
    node ./node_modules/@axa-fr/react-oidc/bin/copy-service-worker-files.mjs public

    Replace public if your framework serves static files from another directory. The command overwrites OidcServiceWorker.js but preserves an existing OidcTrustedDomains.js.

  3. Replace the sample entries in public/OidcTrustedDomains.js with your provider and API URLs, as described below.

  4. Add these fields to your OIDC client configuration:

    const configuration = {
      ...oidcConfiguration,
      service_worker_relative_url: '/OidcServiceWorker.js',
      service_worker_only: true,
    };

    With service_worker_only: true, authentication requires worker support. Set it to false only if you accept fallback to JavaScript-accessible browser storage when the worker is unavailable.

  5. Add the appropriate copy command to your application's postinstall script. For example, for React:

    {
      "scripts": {
        "postinstall": "node ./node_modules/@axa-fr/react-oidc/bin/copy-service-worker-files.mjs public"
      }
    }

    Merge this with existing installation steps rather than replacing them. Deploy the copied worker with every client upgrade.

Resource-specific token isolation

Use the local OpenIddict demos to test two isolated audiences and DPoP nonce challenges end to end. Their local trust rules activate only for a localhost worker explicitly selected with provider=openiddict; the online trust rules do not gain localhost access. Generated DPoP targets exclude query strings and fragments.

The clients' RFC 8707 resource API uses nested resource entries in the existing named/tab session, not separate OIDC clients. Access tokens, authorization state, PKCE, grant references, and DPoP state remain associated with the selected resource. Default and sibling access tokens are not replaced by acquisition or renewal. Additional authorization requires a fresh ID token for the same authenticated subject and transaction nonce. A resource refresh may omit an ID token even after its earlier ID token expires.

Configure resources in the client and allow both API origins in the worker:

const trustedDomains = {
  default: {
    oidcDomains: [/^https:\/\/issuer\.example\.com(?:\/|$)/],
    accessTokenDomains: [
      /^https:\/\/orders\.example\.com(?:\/|$)/,
      /^https:\/\/inventory\.example\.com(?:\/|$)/,
    ],
  },
};

Use fetchForResource() or useOidcFetchForResource(), not automatic selection by URL. A selected placeholder must match its exact resource context and both the client URL mapping and worker trusted-domain rules. Managed API requests without resource selection do not receive an arbitrary/default worker token, including paths outside the permitted prefixes on registered API origins. The standard provider user-info flow retains its default token handling. Default renewal also retains its own token entry for single-resource grants. The client sends a worker-only routing hint for explicit resource refreshes; the worker verifies it against the OAuth resource and removes it before dispatch. Resource tokens are always masked, including with showAccessToken: true. Automatic API redirects are rejected.

Shared refresh rotation is retained centrally; independently authorized resources keep their own grants. Clearing a resource resets only its entry; clearing the base session removes all nested entries. Late responses cannot recreate cleared state. Logout can revoke resource tokens through the exact trusted revocation endpoint.

DPoP remains configured through this file's existing options. Resource API proofs use the selected real token and its bound key/nonce; the browser receives neither refresh tokens nor private keys from the resource API. API nonces are retained per resource separately from authorization-server nonces. API responses are not automatically retried.

Resource support requires the resourceTokenManagement capability returned by protocol 1.1 workers. Copy and deploy the matching OidcServiceWorker.js with each client upgrade. Older/unavailable workers cause explicit resource errors, not browser-token fallback. Worker token memory is not durable: after loss, restore or reauthenticate the original session before requesting resource tokens. Resource entries cannot be reconstructed from stale placeholders. See the core guide for provider/opaque-token limitations.

Trusted domains

Keep provider endpoints and API destinations separate:

const trustedDomains = {
  default: {
    oidcDomains: [/^https:\/\/identity\.example\.com(?:\/|$)/],
    accessTokenDomains: [/^https:\/\/api\.example\.com(?:\/|$)/],
  },
};

default is the default client configuration name. Add a matching entry for every named client or OidcProvider. These rules use regular-expression matching, including when rules are strings. Anchor patterns, escape hostname dots, and include a host or path boundary so that lookalike URLs do not match. Include the actual OIDC endpoint origins if your provider serves discovery, tokens, or user information from different hosts. Allow only the API destinations that should receive this configuration's access token; do not copy the demo allowlist into production.

Use oidcClient.fetchWithTokens(fetch) in vanilla applications or useOidcFetch() in React. In particular, allowMultiTabLogin: true requires the OIDC fetch wrapper: its placeholder identifies the tab whose token the worker must inject. A plain fetch cannot supply that information.

See the client's service-worker guide for additional options, including DPoP, access-token visibility, and request handling.

Deployment and troubleshooting

  • Serve both JavaScript files from your application's origin over HTTPS (localhost is supported for development).
  • The worker must control the pages that use it. Serving it at the origin root is the simplest setup; account for worker scope when hosting under a subpath.
  • Serve the files as JavaScript, not the HTML fallback used for SPA routes. Check the Network and Application panels in browser developer tools if registration fails.
  • Keep the worker version aligned with the client. Edit the trusted-domain file, not the generated OidcServiceWorker.js.
  • If API requests return 401, check the active configuration name, the matching accessTokenDomains entry, and whether you are using the OIDC fetch wrapper. The API must also accept the token's issuer, audience, and scopes.
  • After changing worker assets, check which worker version controls your page; an already-open tab may still be controlled by an older worker.

The FAQ covers broader security and integration questions.

Protocol reference

Most applications do not need to send worker messages directly. For custom integrations, PROTOCOL.md describes the versioned message envelope, payloads, token placeholders, storage keys, and compatibility guarantees.

Protocol constants and types are exported from @axa-fr/oidc-client-service-worker/protocol and re-exported by @axa-fr/oidc-client.

For source development, use the root contributor commands and the committed lockfile with the root-pinned pnpm version. Keep this package's Vitest and coverage versions aligned. Run pnpm audit --audit-level low at the root to include development dependencies.

Back to the project overview