javascript Passport-twitter:在会话中找不到请求令牌
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11075629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passport-twitter: failed to find request token in session
提问by piggyback
just yesterday on Heroku I started to have this error on twitter login in express
就在昨天在 Heroku 上,我开始在 express 中登录 Twitter 时出现此错误
Error: failed to find request token in session
at Strategy.<anonymous> (/app/node_modules/passport-twitter/node_modules/passport-oauth/lib/passport-oauth/strategies/oauth.js:120:54)
at Strategy.authenticate (/app/node_modules/passport-twitter/lib/passport-twitter/strategy.js:82:40)
at Passport.authenticate (/app/node_modules/passport/lib/passport/middleware/authenticate.js:153:14)
at callbacks (/app/node_modules/express/lib/router/index.js:272:11)
at param (/app/node_modules/express/lib/router/index.js:246:11)
at pass (/app/node_modules/express/lib/router/index.js:253:5)
at Router._dispatch (/app/node_modules/express/lib/router/index.js:280:4)
at Object.handle (/app/node_modules/express/lib/router/index.js:45:10)
at Context.next (/app/node_modules/express/node_modules/connect/lib/http.js:204:15)
at Context.<anonymous> (/app/node_modules/passport/lib/passport/context/http/actions.js:64:8)
any suggestion?
有什么建议吗?
回答by piggyback
YUHU I solved. the problem was that some times my website had www and sometimes not, so there were problems with sessions, apparently.
雨虎我解决了。问题是有时我的网站有 www 有时没有,所以显然会话存在问题。
回答by Gabe Sumner
I also encountered this error using Node.js, Express & Passport, although my fix was different than those described above.
我在使用 Node.js、Express 和 Passport 时也遇到了这个错误,尽管我的修复与上面描述的不同。
I had copied and pasted the following code from the 'express-session' documentation...
我从“express-session”文档中复制并粘贴了以下代码...
app.use(session({ secret: 'keyboard cat', key: 'sid', cookie: { secure: true }}))
That secure: truebit instructs express-session to use 'https', which I don't have setup in my development environment. Once I removed it, the error went away.
那个安全:真位指示 express-session 使用“https”,我在我的开发环境中没有设置。一旦我删除它,错误就消失了。
回答by Akash
In Twitters app settings, ensure the following fields have these values:
在 Twitter 应用设置中,确保以下字段具有以下值:
Website : http://127.0.0.1:3000
网址:http: //127.0.0.1: 3000
Callback URL : http://127.0.0.1:3000/auth/twitter/callback
回调网址:http: //127.0.0.1: 3000/auth/twitter/callback
**I am working with port number 3000. You could change that to whatever port you are working with.
**我正在使用端口号 3000。您可以将其更改为您正在使用的任何端口。
Now, navigate to http://127.0.0.1:3000in your browser. This should solve your problem.
现在,在浏览器中导航到http://127.0.0.1:3000。这应该可以解决您的问题。
回答by Arnav Gupta
This is a very late answer, but I just figured another reason this can happen. When the guys who made express-sessionsaid that MemoryStore is not meant for production, they really meant it.
这是一个很晚的答案,但我只是想出了另一个可能发生这种情况的原因。当制作express-session 的人说 MemoryStore 不适用于生产时,他们是认真的。
If you're using clustering, (pm2 or forever or running on Heroku), then memory based cookie storages have their own set of problems. You'll often loose cookies or corrupt them (because there are two or more separate processes on server side, not sharing common memory).
如果您使用集群(pm2 或永远或在 Heroku 上运行),那么基于内存的 cookie 存储有其自身的一系列问题。您经常会丢失 cookie 或损坏它们(因为服务器端有两个或多个单独的进程,不共享公共内存)。
If you want to run your Node app with clusters, you need to use Redis or some DB-backed cookie storage
如果你想用集群运行你的 Node 应用程序,你需要使用 Redis 或一些数据库支持的 cookie 存储
回答by drhayes
This is totally random, and I'm a Node newb... so apply salt liberally.
这完全是随机的,而且我是一个 Node 新手......所以要大量使用盐。
I was seeing this error and a very similar stack trace tonight, actually. It turned out that I had just changed my auth callback route to look like this:
实际上,我今晚看到了这个错误和一个非常相似的堆栈跟踪。原来,我刚刚将我的 auth 回调路由更改为如下所示:
app.use('/auth/twitter/callback', twitterCallback);
app.use('/auth/twitter/callback', twitterCallback);
See how I used use
there instead of get
? Once I changed it back, I stopped getting this error.
看看我如何使用use
那里而不是get
?一旦我把它改回来,我就不再收到这个错误了。
My stack trace looked a bit different, though:
不过,我的堆栈跟踪看起来有点不同:
DEBUG: Error: failed to find request token in session
at Strategy.<anonymous> (/Users/drhayes/src/incursion/node_modules/passport-twitter/node_modules/passport-oauth/lib/passport-oauth/strategies/oauth.js:122:54)
at Strategy.authenticate (/Users/drhayes/src/incursion/node_modules/passport-twitter/lib/passport-twitter/strategy.js:82:40)
at Passport.authenticate (/Users/drhayes/src/incursion/node_modules/passport/lib/passport/middleware/authenticate.js:153:14)
at Object.handle (native)
at next (/Users/drhayes/src/incursion/node_modules/express/node_modules/connect/lib/http.js:204:15)
at /Users/drhayes/src/incursion/node_modules/passport/lib/passport/middleware/authenticate.js:99:9
at /Users/drhayes/src/incursion/node_modules/passport/lib/passport/http/request.js:46:7
at pass (/Users/drhayes/src/incursion/node_modules/passport/lib/passport/index.js:229:30)
at /Users/drhayes/src/incursion/node_modules/passport/lib/passport/index.js:237:36
at /Users/drhayes/src/incursion/routes/auth.coffee:42:14
Has your source changed recently? Is there a revision bump in your deployed slug?
你的来源最近有变化吗?您部署的 slug 中是否存在修订版本?
回答by Renato Vilasboas dos Santos
I have the same issue, the solution was, take the site using http://127.0.0.1:3000/instead http://localhost:3000, when the request happens everything works well.
我有同样的问题,解决方案是,使用http://127.0.0.1:3000/而不是http://localhost:3000获取站点,当请求发生时一切正常。
回答by Dercni
Twitter does not accept localhost so i was forced to use the following settings:
Twitter 不接受 localhost 所以我被迫使用以下设置:
In https://apps.twitter.com/app/....
在https://apps.twitter.com/app/....
website = http://127.0.0.1:3000
callback url: http://localhost:3000/login/twitter/callback
In passport:
在护照中:
'callbackURL' : 'http://localhost:3000/login/twitter/callback'
Note: The twitter callback url works using both 127.0.0.1 & localhost
注意:twitter 回调 url 使用 127.0.0.1 和 localhost
回答by user2729636
I used passport-flickr and fixed the same problem by changing 127.0.0.1to localhost
我使用了passport-flickr 并通过将127.0.0.1更改为localhost来解决相同的问题
passport.use(new FlickrStrategy({
...
callbackURL: "http://localhost:3000/auth/flickr/callback"
},
回答by Seungha Kim
In my case, it is due to reverse proxy and secure cookie. Setting app.set('trust proxy', 1)
resolves the issue.
就我而言,这是由于反向代理和安全 cookie。设置app.set('trust proxy', 1)
解决了问题。
https://github.com/expressjs/session/issues/281#issuecomment-191327863
https://github.com/expressjs/session/issues/281#issuecomment-191327863
回答by mcha
I had this once, I fixed it by changing the call back URL
我有过一次,我通过更改回调 URL 来修复它
from127.0.0.1
从127.0.0.1
tolocalhost
到本地主机