Last active
October 22, 2015 22:54
-
-
Save parshap/4587e3379530d39799ee to your computer and use it in GitHub Desktop.
Simple Passport-like interface compatible with passport strategies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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