passport-jwt

A Passport.js strategy for authenticating requests using JSON Web Tokens

Library
npm
v4.0.1
1,981 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
43 /100 Fair
Development Activity 0
Maintenance 0
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
67 /100 Good
Architecture 65
Code Quality 68
Innovation 55
Learning Curve 78

passport-jwt is a strategy module for Passport, the widely-used Node.js authentication middleware, that lets applications authenticate HTTP requests using JSON Web Tokens instead of cookies or sessions. It parses a JWT out of an incoming request via a pluggable extractor function, verifies its signature and claims (issuer, audience, algorithms, expiration) using the jsonwebtoken library, and hands the decoded payload to a user-supplied verify callback that resolves the associated user record.

Because it plugs directly into Passport’s strategy interface, teams already using Passport for other authentication schemes (local, OAuth, etc.) can add stateless, token-based auth to specific routes with minimal additional code, making it a common choice for securing RESTful APIs consumed by single-page apps and mobile clients.

What You Get

  • A JwtStrategy class that plugs into any existing Passport.js authentication setup
  • A library of built-in token extractors (header, bearer auth header, body field, URL query parameter, or a custom composed extractor chain)
  • Signature and claim verification (issuer, audience, algorithms, expiration) delegated to the battle-tested jsonwebtoken library
  • Support for both static secrets/keys and dynamic secretOrKeyProvider callbacks for per-request key resolution
  • An option to pass the full request into the verify callback for request-aware user lookups

Common Use Cases

  • Securing RESTful API endpoints consumed by single-page applications or mobile clients without maintaining server-side sessions
  • Adding stateless bearer-token authentication alongside existing Passport strategies like passport-local or OAuth providers
  • Verifying tokens issued by a separate auth service or identity provider before allowing access to protected routes
  • Supporting key rotation scenarios via secretOrKeyProvider, where the verification key depends on the token or request

Under The Hood

Architecture: passport-jwt is a thin adapter layer over two dependencies: passport-strategy (for the Strategy base class and pass/fail/error request lifecycle) and jsonwebtoken (for actual signature/claims verification). lib/strategy.js defines JwtStrategy, whose authenticate() method pulls a raw token string from the request via a caller-supplied jwtFromRequest function, resolves a secret/key via secretOrKeyProvider (a normalized wrapper around the simpler secretOrKey option), and delegates cryptographic verification to JwtStrategy.JwtVerifier (lib/verify_jwt.js, itself a wrapper around jsonwebtoken.verify). On success the decoded payload is handed to the user’s verify callback, whose done(err, user, info) result drives Passport’s success/fail/error branching. Tech Stack: Plain CommonJS JavaScript with no build step; runtime dependencies are just jsonwebtoken and passport-strategy, and dev dependencies (mocha, chai, chai-passport-strategy, sinon, nyc) support a classic Mocha/Chai unit-test suite with coverage reporting. Code Quality: The test/ directory has one spec file per concern (initialization, request extraction, validation, verify-callback behavior) with mocked requests (mock_request.js) and fixture data (testdata.js), giving reasonably thorough coverage of the strategy’s branching logic; the production code itself is small (a few hundred lines across strategy.js, extract_jwt.js, auth_header.js, verify_jwt.js) and uses util.inherits-style prototypal inheritance rather than ES6 classes, reflecting its 2014-era origins. API Design: The public surface is deliberately minimal — a Strategy constructor plus an ExtractJwt namespace of extractor factories — and the extractor-function convention (any (req) => token|null function is valid) makes it trivial to compose custom token sources (e.g. cookies) without modifying the library, keeping the integration surface small for consumers already familiar with Passport’s strategy pattern.

Used by 19 apps in this directory

JavaScript
46%
MIT

Kutt

Analytics · Marketing

11,166

Self-hosted URL shortener with custom domains, per-link analytics, and zero build step required.

View details
68
Repo Health
62
Technical
71
Dependency
Built with
JavaScript 46%
Handlebars 24%
HTML 16%
Updated 1 weeks ago
TypeScript
94%
AGPL 3.0

Laudspeaker

Automation · Marketing

2,629

Open-source customer engagement platform for building visual, event-triggered messaging journeys across email, SMS, push, in-app, and webhooks.

View details
45
Repo Health
66
Technical
62
Dependency
Built with
TypeScript 94%
Updated 3 months ago
TypeScript
85%
MIT

LibreChat

AI Assistants · Developer Tools

46,236

Unite every major AI model in one self-hosted chat platform with agents, code execution, MCP tools, and enterprise authentication.

View details
93
Repo Health
81
Technical
62
Dependency
Built with
TypeScript 85%
JavaScript 14%
Updated 6 days ago
TypeScript
65%
Other

NocoDB

Databases · Low Code Platforms · No Code Platforms

65,340

Turn any SQL database into a collaborative no-code spreadsheet with automatic REST APIs and real-time views.

View details
91
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 65%
Vue 30%
Updated 6 days ago
TypeScript
98%
Other

Novu

Developer Tools

40,195

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 98%
Updated 6 days ago
TypeScript
97%
AGPL 3.0

Swetrix

Analytics

1,213

Privacy-first, cookieless web analytics with error tracking, session replays, and performance monitoring — self-host or use Cloud.

View details
87
Repo Health
71
Technical
66
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago
TypeScript
99%
Other

Teable

Databases · No Code Platforms

21,920

A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.

View details
78
Repo Health
76
Technical
62
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
HTML
68%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,123

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
HTML 68%
JavaScript 20%
Updated 6 days ago
TypeScript
84%
Other

twenty

CRM

59,615

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 84%
MDX 14%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers