Authentication with passport.js

Mokhles El Heni
GoMyCode
Published in
5 min readMar 3, 2018

--

Authentication is the process of verifying who you are. When you log on to an application with a user name (or any unique identifier) and password you are authenticating.

(Other method to login are possible for example google drive long URL.)

Passport.js

Passport is authentication middleware for Node.js. Extremely flexible and modular, Passport can be unobtrusively dropped in to any Express-based web application.

Passport has many login Strategies:

  • passport-facebook
  • passport-http-bearer (Bearer tokens are typically used protect API endpoints, and are often issued using OAuth 2.0)
  • passport-google-oauth
  • passport-twitter

Passport: Making our own authentication system with local strategy:

Change your package.json and add this dependencies then run npm install

...
"dependencies" : {
"bcryptjs": "*",
"body-parser": "~1.15.2",
"cancan": "^3.1.0",
"cookie-parser": "~1.4.3",
"express": "~4.14.0",
"express-session": "~1.14.1",
"mongoose": "~4.13.1",
"passport": "~0.3.2",
"passport-facebook": "~2.1.1",
"passport-google-oauth"…

--

--