JavaScript OAuth clients libraries

Updated Nov 2026

JavaScript OAuth libraries run the OAuth and OpenID Connect flows that let an app act for a user at another service. A client sends the user to the provider's authorization page and exchanges the returned code for tokens. These libraries let apps offer sign-in with an identity provider and let agents call APIs with a user's delegated permission.

Popularity

oauth4webapi has the most monthly downloads in this comparison, at 94.0M.

LibraryMonthly downloadsStarsLast releaseLicense
oauth4webapi
97.0M
806Sep 2026MIT
openid-client
91.2M
2.5KNov 2026MIT
oauth
32.6M
2.4KMar 2025MIT
oidc-client-ts
12.0M
2.0KMar 2026Apache-2.0
passport-oauth2
11.8M
617Feb 2024MIT
arctic
5.9M
1.7KMay 2025MIT
react-oidc-context
4.2M
1.0KMar 2026MIT
simple-oauth2
3.3M
1.6KJun 2024Apache-2.0
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Provides low-level OAuth and OpenID Connect request and response routines.

Downloads / mo
97.0M
Stars
806
Last release
3.8.8
License
MIT

Strengths

  • Exposes individual protocol steps. Build custom clients from separate request and response routines.
  • Includes token inspection and revocation. Inspect token status or request revocation through native protocol routines.

Limitations

  • Responses need explicit processing. Pass the grant response to processAuthorizationCodeResponse before consuming its result.
  • Uses ES modules. CommonJS loading depends on runtime support for requiring ES modules.

Quickstart

From client_credentials.ts
$ npm install oauth4webapi@3.8.8
import * as oauth from "oauth4webapi";
const issuer = new URL(process.env.OAUTH_ISSUER);
const response = await oauth.discoveryRequest(issuer);
const metadata = await oauth.processDiscoveryResponse(issuer, response);
console.log(metadata.authorization_endpoint);

oauth4webapi examples

From open-source projects on GitHub

Provides OAuth and OpenID Connect client flows across JavaScript runtimes.

Downloads / mo
91.2M
Stars
2.5K
Last release
6.9.0
License
MIT

Strengths

  • Discovers authorization server settings. Use discovery to load server metadata and configure the client.
  • Includes device authorization. Display the verification instructions, then poll for tokens after user approval.

Limitations

  • Redirect state needs session storage. Retain the verifier and state until the user returns.
  • Requires Web Crypto and Fetch. Choose a runtime that supplies both Web APIs.

Quickstart

From oauth.ts
$ npm install openid-client@6.9.0
import * as client from "openid-client";
const config = await client.discovery(new URL(process.env.OAUTH_ISSUER), process.env.OAUTH_CLIENT_ID);
console.log(config.serverMetadata().issuer);

openid-client examples

From open-source projects on GitHub

Interacts with OAuth 1.0, 1.0A, 2, and Echo providers.

Downloads / mo
32.6M
Stars
2.4K
Last release
0.10.2
License
MIT

Quickstart

From README.md
$ npm install oauth@0.10.2
const { OAuth2 } = require("oauth");
const client = new OAuth2(process.env.OAUTH_CLIENT_ID, null, process.env.OAUTH_BASE_URL, "/authorize", "/token");
const state = require("node:crypto").randomBytes(32).toString("hex");
console.log(client.getAuthorizeUrl({ redirect_uri: process.env.OAUTH_REDIRECT_URI, response_type: "code", state }));

oauth examples

From open-source projects on GitHub

oidc-client-ts

Provides an OpenID Connect and OAuth2 client library.

Downloads / mo
12.0M
Stars
2.0K
Last release
3.5.0
License
Apache-2.0

Quickstart

From README.md
$ npm install oidc-client-ts@3.5.0
import { UserManager } from "oidc-client-ts";
const manager = new UserManager({ authority: "https://issuer.example.com", client_id: "registered-client", redirect_uri: window.location.origin + "/callback", response_type: "code", scope: "openid profile" });
await manager.signinRedirect();

oidc-client-ts examples

From open-source projects on GitHub

passport-oauth2

Adds an OAuth 2.0 authentication strategy to Passport.

Downloads / mo
11.8M
Stars
617
Last release
1.8.0
License
MIT

Quickstart

From strategy.js
$ npm install passport-oauth2@1.8.0
const { Strategy } = require("passport-oauth2");
const strategy = new Strategy({ authorizationURL: process.env.OAUTH_AUTHORIZATION_URL, tokenURL: process.env.OAUTH_TOKEN_URL, clientID: process.env.OAUTH_CLIENT_ID, clientSecret: process.env.OAUTH_CLIENT_SECRET, callbackURL: process.env.OAUTH_REDIRECT_URI, state: true }, (_accessToken, _refreshToken, _profile, done) => done(null, false));
console.log(strategy.name);

passport-oauth2 examples

From open-source projects on GitHub

Provides OAuth 2.0 clients for specific providers.

Downloads / mo
5.9M
Stars
1.7K
Last release
3.7.0
License
MIT

Quickstart

From README.md
$ npm install arctic@3.7.0
import { OAuth2Client, CodeChallengeMethod, generateCodeVerifier, generateState } from "arctic";
const client = new OAuth2Client(process.env.OAUTH_CLIENT_ID, null, process.env.OAUTH_REDIRECT_URI);
const verifier = generateCodeVerifier();
const state = generateState();
const url = client.createAuthorizationURLWithPKCE(process.env.OAUTH_AUTHORIZATION_URL, state, CodeChallengeMethod.S256, verifier, ["openid"]);
console.log(url.href);

arctic examples

From open-source projects on GitHub

react-oidc-context

Adds OpenID Connect and OAuth2 authentication to React through the context API.

Downloads / mo
4.2M
Stars
1.0K
Last release
3.3.1
License
MIT

Quickstart

From README.md
$ npm install react-oidc-context@3.3.1 react@18 react-dom@18 oidc-client-ts@3.5.0
import React from "react";
import { createRoot } from "react-dom/client";
import { AuthProvider, useAuth } from "react-oidc-context";
const host = document.createElement("div");
document.body.append(host);
function Login() { const auth = useAuth(); return <button onClick={() => void auth.signinRedirect()}>Sign in</button>; }
createRoot(host).render(<AuthProvider authority="https://issuer.example.com" client_id="registered-client" redirect_uri={window.location.origin + "/callback"} onSigninCallback={() => window.history.replaceState({}, document.title, window.location.pathname)}><Login /></AuthProvider>);

simple-oauth2

Provides Node.js OAuth clients for authorization-code and application token grants.

Downloads / mo
3.3M
Stars
1.6K
Last release
5.1.0
License
Apache-2.0

Strengths

  • Recreates persisted token objects. Use createToken to restore an AccessToken instance from stored token data.
  • Supports early token renewal. Pass an expiration window to expired before requesting a replacement.

Limitations

  • Application tokens need replacement. Fetch a new client-credentials token after expiry instead of using refresh.
  • Refresh decisions belong to callers. Check expired and call refresh when the token needs renewal.

Quickstart

From README.md
$ npm install simple-oauth2@5.1.0
const { ClientCredentials } = require("simple-oauth2");
const client = new ClientCredentials({ client: { id: process.env.OAUTH_CLIENT_ID, secret: process.env.OAUTH_CLIENT_SECRET }, auth: { tokenHost: process.env.OAUTH_TOKEN_HOST, tokenPath: process.env.OAUTH_TOKEN_PATH } });
client.getToken({}).then((token) => console.log(token.expired())).catch(console.error);

FAQ

openid-client suits server code that runs full OAuth and OpenID Connect flows. oidc-client-ts suits browser apps that manage sign-in and token renewal. passport-oauth2 suits Express apps that already authenticate through Passport.

PKCE, or Proof Key for Code Exchange, binds an authorization code to the client that requested it. The client sends a hashed secret with the authorization request and the original secret with the token request. openid-client and oauth4webapi generate PKCE values.

openid-client is an OAuth and OpenID Connect client for JavaScript runtimes. It handles issuer discovery, authorization URLs, several grant types, and PKCE.

react-oidc-context wraps oidc-client-ts in a React provider and hooks. It intercepts the sign-in callback and exposes the authentication state to components.

OAuth grants an app access to a user's resources at another service. OpenID Connect adds an identity layer on top of OAuth with an ID token that says who the user is.

For coding agents

Found your OAuth clients library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official