Skip to content

Instantly share code, notes, and snippets.

@nelreina
Created June 9, 2016 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nelreina/afb9959e4d92a0a945abf1101bd52609 to your computer and use it in GitHub Desktop.
Save nelreina/afb9959e4d92a0a945abf1101bd52609 to your computer and use it in GitHub Desktop.
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 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment