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 30 apps in this directory
Amplication
Developer Tools · AI Code Assistants · Automation
Create production-ready backend services with your organization's standards baked in — generating NestJS, Prisma, and GraphQL code that you own and control.
Automatisch
Automation · No Code Platforms
Self-hosted, no-code workflow automation that keeps your data on your own servers—a privacy-first alternative to Zapier with 90+ integrations.
Bigcapital
Invoicing Finance
Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.
Blinko
Knowledge Management · Note Taking
A self-hosted, AI-powered card note-taking tool that lets you capture fleeting thoughts instantly and retrieve them with natural language search.
Cal.diy
Scheduling
The 100% MIT-licensed, community-driven scheduling platform — self-host your own booking infrastructure with no enterprise strings attached.
Flowise
Developer Tools · Automation · No Code Platforms
Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.
Ghostfolio
Invoicing Finance
Track your stocks, ETFs, and crypto with a privacy-first, self-hostable wealth management platform built for data-driven investors.
Hexabot
AI Development · Automation
Build and run agentic workflows across channels with YAML, tools, and RAG
Hoppscotch
Developer Tools
A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.