在不覆盖用户请求对象的情况下使用passport.js和多个策略

我正在使用passport.js本地策略进行身份validation。 我还需要用户使用Facebook,Twitter和G +进行身份validation,但不能作为身份validation的替代品,而是要使用户能够从这些服务中检索其内容。

如书面所述,每个authentication策略都将一个用户对象写入请求对象。 这具有注销我的root用户的效果。 有没有办法利用这些额外的authentication策略的护照,但不覆盖用户对象?

这是典型的例子:

var passport = require('passport') , TwitterStrategy = require('passport-twitter').Strategy; passport.use(new TwitterStrategy({ consumerKey: TWITTER_CONSUMER_KEY, consumerSecret: TWITTER_CONSUMER_SECRET, callbackURL: "http://www.example.com/auth/twitter/callback" }, function(token, tokenSecret, profile, done) { User.findOrCreate(..., function(err, user) { if (err) { return done(err); } done(null, user); //trashes my existing user object }); } )); 

一个方法是使用callback而不是redirect。 通常你会调用req.login()来设置请求对象。 你可以跳过这一步,做任何你想要的回应。

 app.get('/auth/twitter/callback', function (req, res, next) { passport.authenticate('twitter', function (err, user, info) { res.send({err: err, user: user, info: info}); //skip req.login() })(req, res, next) }); 

这在护照文件中列出。 http://passportjs.org/guide/authorize/