Passport's sole purpose is to authenticate requests, which it does through an extensible set of plugins known as strategies. Passport does not mount routes or assume any particular database schema, which maximizes flexibility and allows application-level decisions to be made by the developer. The API is simple: you provide Passport a request to authenticate, and Passport provides hooks for controlling what occurs when authentication succeeds or fails.
$ npm install passport
Passport uses the concept of strategies to authenticate requests. Strategies can range from verifying username and password credentials, delegated authentication using OAuth (for example, via Facebook or Twitter), or federated authentication using OpenID.
Before authenticating requests, the strategy (or strategies) used by an application must be configured.
There are 300+ strategies. Find the ones you want at: passportjs.org
Passport will maintain persistent login sessions. In order for persistent sessions to work, the authenticated user must be serialized to the session, and deserialized when subsequent requests are made.
Passport does not impose any restrictions on how your user records are stored. Instead, you provide functions to Passport which implements the necessary serialization and deserialization logic. In a typical application, this will be as simple as serializing the user ID, and finding the user by ID when deserializing.
To use Passport in an Express or
Connect-based application, configure it
with the required
passport.initialize() middleware. If your application uses
persistent login sessions (recommended, but not required),
middleware must also be used.
var app = ;app;app;app;app;app;app;
Passport provides an
authenticate() function, which is used as route
middleware to authenticate requests.
Passport has a comprehensive set of over 300 authentication strategies covering social networking, enterprise integration, API services, and more.
Search all strategies
There is a Strategy Search at passportjs.org
The following table lists commonly used strategies:
|Local||HTML form||Jared Hanson|
|OAuth 2.0||Jared Hanson|
|OAuth / OAuth 2.0||Jared Hanson|
|Azure Active Directory||OAuth 2.0 / OpenID / SAML||Azure|
- For a complete, working example, refer to the example that uses passport-local.
- Local Strategy: Refer to the following tutorials for setting up user authentication via LocalStrategy (
- Social Authentication: Refer to the following tutorials for setting up various social authentication strategies:
- Locomotive — Powerful MVC web framework
- OAuthorize — OAuth service provider toolkit
- OAuth2orize — OAuth 2.0 authorization server toolkit
- connect-ensure-login — middleware to ensure login sessions
$ npm install $ make test
This project is supported by Auth0
Copyright (c) 2011-2015 Jared Hanson <http://jaredhanson.net/>