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

oidc-js

v1.1.0

Published

Simple OIDC authentication for JavaScript. Drop-in client with login, logout, token refresh, and zero dependencies.

Readme

oidc-js

Simple OIDC authentication for JavaScript. Drop-in client with login, logout, token refresh, and zero dependencies.

Handles the full Authorization Code + PKCE flow: discovery, redirect-based login, callback handling, token refresh, userinfo fetching, and logout. Framework-agnostic -- use it directly or through one of the framework adapters.

Install

npm install oidc-js

Quick start

import { OidcClient } from "oidc-js";

const client = new OidcClient({
  issuer: "https://auth.example.com",
  clientId: "my-app",
  redirectUri: window.location.origin + "/callback",
  scopes: ["openid", "profile"],
});

// Subscribe to state changes
client.subscribe((state) => {
  console.log("authenticated:", state.isAuthenticated);
  console.log("user:", state.user);
});

// Initialize: fetches discovery and handles any callback in the URL
const { returnTo } = await client.init();

if (returnTo) {
  // Navigate to the path the user was on before login
  history.replaceState(null, "", returnTo);
}

// Trigger login when the user clicks a button
loginButton.addEventListener("click", () => client.login());

// Trigger logout
logoutButton.addEventListener("click", () => client.logout());

API

new OidcClient(config)

Creates a new client instance. Does not perform any IO until init() is called.

client.init(): Promise<{ returnTo?: string }>

Fetches the OIDC discovery document and checks the current URL for callback parameters. If an authorization code is present, it completes the token exchange, optionally fetches the userinfo profile, and returns the returnTo path that was saved before login. Call this once on app startup.

client.login(options?): Promise<void>

Starts the Authorization Code + PKCE flow by redirecting the browser to the authorization endpoint. Generates PKCE, state, and nonce values and persists them in sessionStorage before navigating away.

options accepts:

| Field | Type | Description | |-------|------|-------------| | returnTo | string | Path to return to after login. Defaults to the current location. | | extraParams | Record<string, string> | Additional query parameters for the authorization request. |

client.logout(): void

Clears local auth state and redirects the browser to the provider's end-session endpoint (if available).

client.refresh(): Promise<void>

Uses the stored refresh token to obtain a new set of tokens. Throws if no refresh token is available.

client.fetchProfile(): Promise<void>

Fetches the userinfo endpoint with the current access token and updates state.user.profile. Throws if no access token is available.

client.subscribe(fn): () => void

Registers a callback that fires whenever the auth state changes. Returns an unsubscribe function.

client.state: AuthState

The current authentication state (read-only).

client.destroy(): void

Aborts any in-flight requests and removes all subscribers.

State shape

interface AuthState {
  user: AuthUser | null;
  isAuthenticated: boolean;
  isLoading: boolean;
  error: Error | null;
  tokens: AuthTokens;
}

interface AuthUser {
  claims: IdTokenClaims;
  profile: OidcUser | null;  // null if fetchProfile is disabled
}

interface AuthTokens {
  access: string | null;
  id: string | null;
  refresh: string | null;
  expiresAt: number | null;  // milliseconds since epoch
}

Configuration

OidcClientConfig extends the core OidcConfig with one additional option:

| Option | Type | Default | Description | |--------|------|---------|-------------| | issuer | string | -- | OIDC provider URL (required). | | clientId | string | -- | OAuth 2.0 client identifier (required). | | redirectUri | string | -- | Redirect URI registered with the provider (required for login). | | scopes | string[] | ["openid"] | OAuth 2.0 scopes to request. | | postLogoutRedirectUri | string | -- | Where to send the user after logout. | | fetchProfile | boolean | true | Whether to fetch the userinfo endpoint after token exchange. |

Exported types

import type {
  OidcClientConfig,
  AuthState,
  AuthUser,
  AuthTokens,
  IdTokenClaims,
  LoginOptions,
} from "oidc-js";

Re-exported from oidc-js-core: OidcConfig, OidcUser, TokenSet.

License

MIT -- see LICENSE.

Links