【发布时间】:2016-09-28 22:48:59
【问题描述】:
试图理解 https://github.com/jaredhanson/passport/blob/master/lib/middleware/authenticate.js,第 57 行。
我不明白为什么护照验证方法有 4 个参数:
module.exports = function authenticate(passport, name, options, callback){/*code*/}
实际上是这样使用的:
passport.authenticate('local', { successRedirect: '/', failureRedirect: '/login' });
或
passport.authenticate('local', function(req, res));
那么为什么方法定义中的第一个参数“passport”没有干扰?由于策略名称作为第一个参数传递,因此它应该映射到护照而不是名称。
【问题讨论】:
-
如果这是 Python,我会告诉你第一个参数从表达式
passport.authenticate接收对象passport。 Javascript 通常不会以这种方式工作,但如果有人发现有人找到了一种方法来使它以这种方式工作,我不会感到惊讶。
标签: javascript node.js express passport.js