Authentication middleware for Express.js that validates JWT Bearer access tokens issued by an OAuth 2.0 authorization server. Version 1.8.0 supports DPoP (Proof-of-Possession) authentication, multiple custom domains, clock tolerance for nbf claim, and Node.js versions 12 through 24. Maintained by Auth0 with 100% test coverage. Differentiates from other JWT middleware by being Auth0-optimized, supporting OAuth 2.0 token validation (not just JWT decoding), and providing built-in security headers guidance.
npm install express-oauth2-jwt-bearerVerified import paths — ran on the pinned version, not inferred.
Shows how to configure auth middleware, protect a route with scopes, and access the decoded token payload.
Update to v1.7.3 or later. If you relied on the previous 401 status, adjust your error handling logic.
In error handling middleware, use err.status (e.g., if (err.status === 403) {...}) instead of assuming 401.Use issuerBaseURL with a JWKS endpoint instead of secret. If you must use HS256, ensure secret is a strong symmetric key.
Specify tokenSigningAlg: 'HS256' when using symmetric secret. Example: auth({ issuer: '...', audience: '...', secret: '...', tokenSigningAlg: 'HS256' })Read EXAMPLES.md for full DPoP config options. Set dpop: { enforce: true } to require DPoP proof.Add issuerBaseURL to auth(): auth({ issuerBaseURL: 'https://your-tenant.auth0.com/', audience: '...' })Use named import: import { auth } from 'express-oauth2-jwt-bearer' (or const { auth } = require(...) for CJS)Set NODE_TLS_REJECT_UNAUTHORIZED=0 (only for development) or configure proper CA certificates.