Does everyauth or passport works in expressJs 4+

747 views Asked by At

I've been looking for authentication in nodeJs. I've looked at PassportJs and Everyauth. Both of them had old documentation and old version of express used. Things that depreciated in express 4+.

app.use(express.cookieParser());
app.use(express.bodyParser());

I had a look at this question, which had nice answers. But had no success implementing them on PassportJs or Everyauth. So does anyone know an method to implement this ? or can anyone give me an authentication tutorial for express 4+ nodeJs authentication ?

2

There are 2 answers

0
vesse On BEST ANSWER

Should work like this:

var bodyParser   = require('body-parser'),
    cookieParser = require('cookie-parser'),
    express      = require('express'),
    session      = require('express-session'),
    passport     = require('passport');

var app = express();

app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(session({
  secret: 'secrit cat',
  resave: true,
  saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
0
sebilasse On

Scotch.io has updated its tutorial series "Easy node authentication" :

These are the changes regarding passport :

Easy node authentication with ExpressJS 4.0