护照认证中的独特模式

Unique Pattern in Passport Authentication

这是我第一次实现身份验证。我在一些 meanjs 示例项目中遇到过这个:

app.get('/auth/facebook', function(req, res, next) {
      passport.authenticate('facebook', {
        scope: ['email']
      })(req, res, next);
    });

我的主要困惑来源是 (req, res, next) 调用 - 我以前从未见过这样的调用。那里到底发生了什么?

1.函数app.get需要两个输入:路径和回调函数。
2.回调函数有三个输入:req、res、next。
3. 回调函数,在其体内调用一个函数生成器(passport.authenticate),即returns一个函数。
4. 这个函数生成器或函数工厂本身有两个输入:'facebook' 和范围为 属性 的对象。
5. 最后,使用原始 req、res 和 next 参数调用从 authenticate 返回的函数本身。