passport
Simple, unobtrusive authentication middleware for Node.js with 480+ pluggable strategies.
Repository Health
Technical Analysis
Passport is Express-compatible authentication middleware for Node.js whose sole purpose is to authenticate requests. It does this through an extensible set of plugins known as strategies, ranging from verifying username and password credentials to delegated authentication via OAuth, OpenID, and SAML.
Passport does not mount routes or assume any particular database schema, which maximizes flexibility and lets application-level decisions stay with the developer. You provide Passport a request to authenticate, and it provides hooks for controlling what happens when authentication succeeds or fails.
What You Get
- A single
authenticate()route middleware that plugs into any Express or Connect app - Access to an ecosystem of 480+ community strategies covering local, OAuth, OpenID Connect, and SAML
- Persistent login sessions via configurable serialize/deserialize hooks
- A framework-agnostic core that imposes no routing or database schema on your app
Common Use Cases
- Adding username/password login to an Express application with passport-local
- Enabling social sign-in through Google, Facebook, or Twitter OAuth strategies
- Integrating enterprise SSO via SAML or OpenID Connect strategies
- Protecting API routes by requiring an authenticated session before access
Under The Hood
Architecture
Passport centers on the Authenticator class in lib/authenticator.js, exported as a default singleton from lib/index.js. On construction it adapts itself to Connect/Express via lib/framework/connect.js, registers a default SessionStrategy (lib/strategies/session.js), and wires up a SessionManager (lib/sessionmanager.js). Strategies are registered in a _strategies map through use(), and authenticate(name, options) in lib/middleware/authenticate.js returns Connect-style middleware that looks up the named strategy, instruments a per-request set of callbacks (success/fail/redirect/error), and drives the strategy’s authenticate() method. The initialize() middleware (lib/middleware/initialize.js) augments the request with helpers exposed via lib/http/request.js, and serialize/deserialize chains persist the authenticated user across the session.
Tech Stack
Pure JavaScript (99.8% of the codebase), targeting Node.js >= 0.4.0. Runtime dependencies are intentionally minimal: passport-strategy (the abstract Strategy base class shared by all strategies), pause (to buffer request events during async deserialization), and utils-merge. Tests run on Mocha with Chai and proxyquire. No build step or transpilation — the package’s main points directly at lib/.
Code Quality
The library ships a thorough Mocha test suite under test/ covering the authenticator, framework adapter, middleware, HTTP request extensions, and session strategy. Source files are small, single-responsibility modules with extensive JSDoc annotations on the public API. Error handling is explicit — use() throws when a strategy has no name, and a dedicated AuthenticationError class lives in lib/errors/. The codebase is stable and mature rather than actively evolving.
API Design
The public surface is deliberately tiny and ergonomic: passport.use() to register strategies, passport.serializeUser()/deserializeUser() for session persistence, and passport.authenticate() as drop-in route middleware. This small, consistent API is a large part of why Passport became the de-facto Node.js auth standard — getting started requires only a few lines, and every strategy follows the same registration and invocation contract.
Used by 31 apps in this directory
Teable
Databases · No Code Platforms
A no-code PostgreSQL database with spreadsheet UX, real-time collaboration, and native AI agents — built for teams that outgrow Airtable.
twenty
CRM
The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.
Wiki.js
Collaboration · Knowledge Management
A modern, self-hosted wiki platform built on Node.js with a rich plugin ecosystem for authentication, search, storage, and rendering that adapts to any team's infrastructure.
Worklenz
Collaboration · Product Management · Project Management
All-in-one open source project management for teams who want full control — plan projects, track tasks, manage resources, and monitor finances without the SaaS lock-in.