passport (2024)

passport (1)

Passport is Express-compatible authenticationmiddleware for Node.js.

Passport's sole purpose is to authenticate requests, which it does through anextensible set of plugins known as strategies. Passport does not mountroutes or assume any particular database schema, which maximizes flexibility andallows application-level decisions to be made by the developer. The API issimple: you provide Passport a request to authenticate, and Passport provideshooks for controlling what occurs when authentication succeeds or fails.

Status:passport (5)passport (6)passport (7)

Install

$ npm install passport

Usage

Strategies

Passport uses the concept of strategies to authenticate requests. Strategiescan range from verifying username and password credentials, delegatedauthentication using OAuth (for example, via Facebookor Twitter), or federated authentication using OpenID.

Before authenticating requests, the strategy (or strategies) used by anapplication must be configured.

passport.use(new LocalStrategy( function(username, password, done) { User.findOne({ username: username }, function (err, user) { if (err) { return done(err); } if (!user) { return done(null, false); } if (!user.verifyPassword(password)) { return done(null, false); } return done(null, user); }); }));
See Also
Passport.js

There are 480+ strategies. Find the ones you want at: passportjs.org

Sessions

Passport will maintain persistent login sessions. In order for persistentsessions to work, the authenticated user must be serialized to the session, anddeserialized 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 necessaryserialization and deserialization logic. In a typical application, this will beas simple as serializing the user ID, and finding the user by ID whendeserializing.

passport.serializeUser(function(user, done) { done(null, user.id);});passport.deserializeUser(function(id, done) { User.findById(id, function (err, user) { done(err, user); });});

Middleware

To use Passport in an Express orConnect-based application, configure itwith the required passport.initialize() middleware. If your application usespersistent login sessions (recommended, but not required), passport.session()middleware must also be used.

var app = express();app.use(require('serve-static')(__dirname + '/../../public'));app.use(require('cookie-parser')());app.use(require('body-parser').urlencoded({ extended: true }));app.use(require('express-session')({ secret: 'keyboard cat', resave: true, saveUninitialized: true }));app.use(passport.initialize());app.use(passport.session());

Authenticate Requests

Passport provides an authenticate() function, which is used as routemiddleware to authenticate requests.

app.post('/login', passport.authenticate('local', { failureRedirect: '/login' }), function(req, res) { res.redirect('/'); });

Strategies

Passport has a comprehensive set of over 480 authentication strategiescovering 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:

StrategyProtocolDeveloper
LocalHTML formJared Hanson
OpenIDOpenIDJared Hanson
BrowserIDBrowserIDJared Hanson
FacebookOAuth 2.0Jared Hanson
GoogleOpenIDJared Hanson
GoogleOAuth / OAuth 2.0Jared Hanson
TwitterOAuthJared Hanson
Azure Active DirectoryOAuth 2.0 / OpenID / SAMLAzure

Examples

Related Modules

The modules page on thewiki lists other useful modulesthat build upon or integrate with Passport.

License

The MIT License

Copyright (c) 2011-2021 Jared Hanson <https://www.jaredhanson.me/>

passport (2024)
Top Articles
A Guide to Selling Canadian Coins & Paper Money
How to Fix Crypto.com App Not Working? (2023)
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Aron Pacocha

Last Updated:

Views: 5868

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Aron Pacocha

Birthday: 1999-08-12

Address: 3808 Moen Corner, Gorczanyport, FL 67364-2074

Phone: +393457723392

Job: Retail Consultant

Hobby: Jewelry making, Cooking, Gaming, Reading, Juggling, Cabaret, Origami

Introduction: My name is Aron Pacocha, I am a happy, tasty, innocent, proud, talented, courageous, magnificent person who loves writing and wants to share my knowledge and understanding with you.