passport

Simple, unobtrusive authentication middleware for Node.js with 480+ pluggable strategies.

Library
npm
v0.7.0
23,520 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 →
84 /100 Excellent
Architecture 85
Code Quality 82
Innovation 88
Learning Curve 80

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.

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