【发布时间】:2014-12-05 00:32:42
【问题描述】:
我想通过护照的 twitter 策略对用户进行身份验证,但不让用户登录。我要做的只是存储他们的凭据,以便以后可以通过推文发送到他们的帐户,但我不知道这是怎么回事是可能的。
看起来您必须调用 done 回调,然后将用户 ID 存储在会话中。我的用户已经通过我的应用程序进行了身份验证,但想要附加一个或多个 Twitter 帐户,他们可以选择在以后发送推文。
这是我的 Twitter 策略
passport.use(new TwitterStrategy({
consumerKey: '...',
consumerSecret: '...',
callbackURL: '/add/twitter/callback',
passReqToCallback: true
},
function(req, token, tokenSecret, profile, done) {
process.nextTick(function() {
//save the users twitter credentials for use later on and call
//my custom callback here ...
});
});
}));
我也在使用 express.js,所以这是我的路线
router
.get('/auth/twitter', passport.authenticate('twitter'))
.get('/auth/twitter/callback',
passport.authenticate('twitter'), function(req, res) {
console.log('made it here');
// Successful authentication
res.render('manager/add-twitter', {});
});
是否有可能有一个无论如何都会被触发的自定义回调?
【问题讨论】:
-
缺乏答案并没有给我希望:/
标签: node.js express mongoose passport.js