Authenticating with Passport

Passport is an Express plug-in that provides middleware for a variety of third-party logins. Using passport you can unobtrusively add support for logging in with Twitter, Facebook, and other services.

We’re going to use passport to support authentication with Google credentials. Go get the passport and passport-google modules from npm if you don’t have them already (npm install --save passport passport-google).

To add passport, first add this to your const declarations at the top of your server.js file:

web-app/b4/server.js
​ 
passport = require(​'passport'​),
​ 
GoogleStrategy = require(​'passport-google'​).Strategy;

Then you need to initialize the passport middleware. Add this right after app.use(express.session...) ...

Get Node.js the Right Way now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.