【问题标题】:SailsJS v0.1 + PassportJSSailsJS v0.1 + PassportJS
【发布时间】:2014-11-10 01:34:53
【问题描述】:

我在 SailsJS v0.9.x 中使用过 PassportJS,它运行良好。现在更新到 v0.1 并且 passportJS 似乎不起作用。

我在 http.js 中做了什么:

passportInit: require('passport').initialize(),

并将 passportInit 添加到中间件列表中。

我已将我的 BasicStrategy 定义为:

passport.use(new BasicStrategy(
  function(email, password, next) {
     // does not get called nor does it throw an error
  }
));

我将此策略称为:

passport.authenticate('basic', {session: false}, function(err, user, info) {
  // ...
});

这不会返回错误。它确实返回一个 nil 用户。此外,当我删除这个新的 BasicStrategy 时,它确实会抛出一个错误,即策略 Basic 未定义。

有什么想法吗?

【问题讨论】:

  • 您能否展示如何将 Passport 添加到 config/http.js 中的中间件列表中?您是否将它同时添加到 middleware 键和 order 数组中? (请参阅文档here)。

标签: node.js sails.js passport.js


【解决方案1】:

我在使用带有 PassportJS 的 SailsJS 时遇到同样的问题。我通过这种方式解决了它:-

someCtrl: function(req, res, next) {   
 passport.authenticate('basic', {session: false}, function(err, user, info) {
  // ...
})(req, res, next);
}

【讨论】:

    猜你喜欢
    • 2017-01-03
    • 2016-10-28
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2013-05-05
    • 2017-03-27
    • 2019-07-18
    • 2012-09-07
    相关资源
    最近更新 更多