【发布时间】:2014-06-11 07:38:04
【问题描述】:
我正在使用 passport-twitter 在我的网站上设置 twitter 连接。用户可以通过单击“登录”或“添加新项目”进行连接。两者之间的唯一区别是,如果他们点击添加新项目,一旦他们登录,就会打开一个模式窗口。
要知道他们点击的按钮,我将网址存储在req.session.referrer:
// route for twitter authentication and login
app.get('/auth/twitter', function(req, res, next){
req.session.referrer = req.url;
console.log(req.session);
passport.authenticate('twitter')(req, res, next);
});
app.get('/auth/twitter/new', function(req, res, next){
req.session.referrer = req.url;
console.log(req.session);
passport.authenticate('twitter')(req, res, next);
});
// handle the callback after twitter has authenticated the user
app.get('/auth/twitter/callback', function(req, res, next){
var options = {
successRedirect : '/twitter-user/signin',
failureRedirect : '/'
};
console.log(req.session);
if (req.session.referrer && req.session.referrer.indexOf('new') > -1) options.successRedirect = '/twitter-user/new';
passport.authenticate('twitter', options)(req, res, next)
});
在我的开发环境中一切正常,但是一旦上线,我就会收到以下错误消息: 快递
500 Error: Failed to find request token in session
at Strategy.OAuthStrategy.authenticate (/app/node_modules/passport-twitter/node_modules/passport-oauth1/lib/strategy.js:142:54)
...
我的设置在 Twitter 中设置正确。这是我从日志中得到的: 对于请求:
{ cookie:
{ path: '/',
_expires: null,
originalMaxAge: null,
httpOnly: true },
passport: {},
referrer: '/auth/twitter' }
对于回调:
{ cookie:
{ path: '/',
_expires: null,
originalMaxAge: null,
httpOnly: true },
passport: {} }
也许这可能是由于子域问题(http://example.com 与 http://www.example.com),因为我在本地没有 pb。 我该如何解决这个问题?
非常感谢
编辑:我的 API 密钥是这样设置的(根据本教程:http://scotch.io/tutorials/javascript/easy-node-authentication-twitter):
passport.use(new TwitterStrategy({
consumerKey : configAuth.twitterAuth.consumerKey,
consumerSecret : configAuth.twitterAuth.consumerSecret,
callbackURL : configAuth.twitterAuth.callbackURL
},function(token, tokenSecret, profile, done) {
...
});
【问题讨论】:
-
你在哪里有 Tour twitter api 密钥设置?
-
我用信息编辑了我的问题。请看上面
标签: node.js twitter passport.js