【问题标题】:passport local vs custom authntication护照本地与自定义身份验证
【发布时间】:2018-01-08 20:23:54
【问题描述】:

护照本地策略与自定义代码的对比

// passport involved code

app.post('/login',
  passport.authenticate('local'),
  function(req, res) {
    // If this function gets called, authentication was successful.
    // `req.user` contains the authenticated user.
    res.redirect('/users/' + req.user.username);
  });

我也可以调用我的本地函数,它可以检查护照本地策略检查的相同内容,因此为什么要创建本地策略

// custom checking function

app.post('/login',
  customfunctionhere,
  function(req, res) {
    // If this function gets called, authentication was successful.
    // `req.user` contains the authenticated user.
    res.redirect('/users/' + req.user.username);
  });

【问题讨论】:

    标签: node.js mongodb express passport.js


    【解决方案1】:

    是的,您可以编写自己的本地策略函数。但是,护照为您提供了额外的功能,例如持久登录(cookie)、轻松处理成功和失败等等。

    另外,如果您使用 OAuth 或 google/fb/twitter 单点登录等其他策略,那么使用护照进行所有身份验证是有意义的。

    注意:您不会将验证函数传递给passport.authenticate()。查看passport-local 文档了解更多信息:https://github.com/jaredhanson/passport-local

    【讨论】:

      猜你喜欢
      • 2016-02-29
      • 2014-03-17
      • 2016-10-19
      • 2016-10-29
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多