我正在编写一个基于passport.js身份验证的nodejs应用程序。它允许用户向其他用户发送消息,其中只允许通过身份验证的用户检索由他们发送或以他们作为接收者的消息。我计划实现多个身份提供者,如facebook、google,以及本地身份验证。
我使用猫鼬建立的用户模式看起来有点像这样:
var userSchema = new mongoose.Schema({
googleId: String,
facebookId: String,
email: { type: String, required: true },
}, {
strict: false
})
module.exports = mongoose.Model('User', userSchema)现在我想到的方法是:
现在,当他们试图接收消息时,我想再次对他们进行身份验证,以便授予获得消息的授权。只要它是我配置的任何策略,它们如何进行身份验证并不重要;然而,没有app.get('/messages', passport.authenticate('any'), done)这样的东西,那么我将如何处理呢?
发布于 2015-07-06 13:38:46
一种选择是将所需的策略作为数组传递到passport.authenticate([Strategies])中。下面的链接很好地显示了这一点。
passport.js with multiple authentication providers?
护照提交人的另一个例子是:
https://github.com/jaredhanson/passport-http/blob/master/examples/multi/app.js
https://stackoverflow.com/questions/31245995
复制相似问题