Low-Level OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
This software provides a collection of routines that can be used to build client modules for OAuth 2.1, OAuth 2.0 with the latest Security Best Current Practices (BCP), and FAPI 2.0, as well as OpenID Connect where applicable. The primary goal of this software is to promote secure and up-to-date best practices while using only the capabilities common to both browser and non-browser JavaScript runtimes.
The following features are currently in scope and implemented in this software:
- Authorization Server Metadata discovery
- Authorization Code Flow (profiled under OpenID Connect 1.0, OAuth 2.0, OAuth 2.1, and FAPI 2.0), with PKCE
- Refresh Token, Device Authorization, and Client Credentials Grants
- Demonstrating Proof-of-Possession at the Application Layer (DPoP)
- Token Introspection and Revocation
- Pushed Authorization Requests (PAR)
- UserInfo and Protected Resource Requests
- Authorization Server Issuer Identification
- JWT Secured Introspection, Response Mode (JARM), Authorization Request (JAR), and UserInfo
- Validating incoming JWT Access Tokens
If you want to quickly add authentication to JavaScript apps, feel free to check out Auth0's JavaScript SDK and free plan. Create an Auth0 account; it's free!
Filip Skokan has certified that this software conforms to the Basic, FAPI 1.0, and FAPI 2.0 Relying Party Conformance Profiles of the OpenID Connectβ’ protocol.
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by becoming a sponsor.
oauth4webapi
has no dependencies and it exports tree-shakeable ESM.
oauth4webapi
is distributed via npmjs.com, jsr.io, deno.land/x, cdnjs.com, jsdelivr.com, and github.com.
example
ESM import1
import * as oauth from 'oauth4webapi'
- Authorization Code Flow (OAuth 2.0) - source
- Authorization Code Flow (OpenID Connect) - source | diff
- Extensions
- Client Authentication
- Other Grants
- FAPI
The supported JavaScript runtimes include those that support the utilized Web API globals and standard built-in objects. These are (but are not limited to):
- Browsers
- Bun
- Cloudflare Workers
- Deno
- Electron
- Node.js
- Vercel's Edge Runtime
Version | Security Fixes π | Other Bug Fixes π | New Features β |
---|---|---|---|
v3.x | β | β | β |
Footnotes
-
CJS style
let oauth = require('oauth4webapi')
is possible in Node.js versions whereprocess.features.require_module
istrue
or with the--experimental-require-module
Node.js CLI flag. β©