nelreina
6/9/2016 - 12:45 PM

passport-basic-es5.js

var passport = require('passport');
var basicStrategy = require('passport-http').BasicStrategy;

passport.use(new basicStrategy(basicAuth)); 

passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
   done(null, id);
});
function basicAuth(username, password, done) {
    
	if (username === 'foo' && password === 'bar'){
		return done(null, {profileName:'The Real Foo', id:1}); 
	} else {
		return done(null, false); 
	}

    return done(new Error("Error occured!"))
}


exports.authenticate = passport.authenticate('basic', { session: false });