Skip to content

Instantly share code, notes, and snippets.

@parshap
Last active October 22, 2015 22:54
Show Gist options
  • Save parshap/4587e3379530d39799ee to your computer and use it in GitHub Desktop.
Save parshap/4587e3379530d39799ee to your computer and use it in GitHub Desktop.
Simple Passport-like interface compatible with passport strategies
"use strict";
var SimplePassport = {
authenticate: function(req, res, strategy, options, callback) {
strategy = Object.create(strategy);
Object.assign(strategy, {
success: callback.bind(null, null), // callback(null, user)
error: callback.bind(null), // callback(err)
fail: callback.bind(null, null, false), // callback(null, false)
pass: callback.bind(null, null, null), // callback(null, null)
redirect: function(url, status) {
res.statusCode = status || 302;
res.setHeader('Location', url);
res.setHeader('Content-Length', '0');
res.end();
},
});
strategy.authenticate(req, options);
},
};
module.exports = SimplePassport;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment