我正在Canvas
使用Sinatra
.
在我自己的机器上本地运行时,我的应用程序运行良好;但是当我把它推到上面时,Heroku
我遇到了会话不匹配的问题,因此当页面重新加载发生时,/callback 放入会话中的数据不存在。
问题似乎是,在运行时Heroku
,它会插入一些花哨的负载平衡,因此页面重新加载和用户 ID 存储在会话中request.env['REMOTE_HOST']
的 Facebook 之间是不同的。callback
一些(编辑过的)日志清楚地表明了这一点。
在 Heroku 上(注意不同的远程主机和不同的会话 ID)
X9.1XX.XX1.XX - - [23/Aug/2012 03:27:42] "POST / HTTP/1.1" 200 1878 0.0235
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Handling request from host ip-10-92-97-233.ec2.internal
DEBUG -- : Session ID: 39960b607fd7c1150791d4d42d6633b3b2a5b18e79e742f67d8f677f139dbca8
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Set session['oauth'] : Koala::Facebook::OAuth
DEBUG -- : Session id: 39960b607fd7c1150791d4d42d6633b3b2a5b18e79e742f67d8f677f139dbca8
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Session ID: 39960b607fd7c1150791d4d42d6633b3b2a5b18e79e742f67d8f677f139dbca8
DEBUG -- : Completed request from host ip-10-92-97-233.ec2.internal
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
X9.1XX.XX1.XX - - [23/Aug/2012 03:27:46] "GET /login HTTP/1.1" 302 - 0.0178
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Handling request from host ip-10-94-82-253.ec2.internal
DEBUG -- : Session ID: 20200e42add5ec9bfe12b225502c7449dda6e8ab06dd3fbe204239db0e21de89
DEBUG -- : ---------------------------------------------------------
ERROR -- : Could not find oauth key in session 20200e42add5ec9bfe12b225502c7449dda6e8ab06dd3fbe204239db0e21de89
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Session ID: 20200e42add5ec9bfe12b225502c7449dda6e8ab06dd3fbe204239db0e21de89
DEBUG -- : Completed request from host ip-10-94-82-253.ec2.internal
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
X9.1XX.XX1.XX - - [23/Aug/2012 03:27:48] "GET /callback?code=AQCs… …vxkEI76cq32juk HTTP/1.1" 302 - 0.0014
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Handling request from host ip-10-125-37-231.ec2.internal
DEBUG -- : Session ID: a94f5f36b44e5891657982248d1304e265f9619bdcdc37b648879e5a12a0fe5b
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Session ID: a94f5f36b44e5891657982248d1304e265f9619bdcdc37b648879e5a12a0fe5b
DEBUG -- : Completed request from host ip-10-125-37-231.ec2.internal
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
本地(这有效,请注意相同的主机和匹配的会话 ID)
X9.1XX.XX1.XX - - [23/Aug/2012 13:56:22] "POST / HTTP/1.1" 200 1878 0.0279
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Handling request from host ppp12345.static.someprovider.net
DEBUG -- : Session ID: 892e6ec515afde6f463102f83d373523bba62b26180a2e5a34a4945c787eacfd
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Set session['oauth'] : Koala::Facebook::OAuth
DEBUG -- : Session id: 892e6ec515afde6f463102f83d373523bba62b26180a2e5a34a4945c787eacfd
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Session ID: 892e6ec515afde6f463102f83d373523bba62b26180a2e5a34a4945c787eacfd
DEBUG -- : Completed request from host ppp12345.static.someprovider.net
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
X9.1XX.XX1.XX - - [23/Aug/2012 13:56:31] "GET /login HTTP/1.1" 302 - 0.0079
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Handling request from host ppp12345.static.someprovider.net
DEBUG -- : Session ID: 892e6ec515afde6f463102f83d373523bba62b26180a2e5a34a4945c787eacfd
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Session ID: 892e6ec515afde6f463102f83d373523bba62b26180a2e5a34a4945c787eacfd
DEBUG -- : Completed request from host ppp12345.static.someprovider.net
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
X9.1XX.XX1.XX - - [23/Aug/2012 13:56:34] "GET /callback?code=AQCs… …vxkEshwXTPMC8lnaY9FU HTTP/1.1" 302 - 1.4674
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Handling request from host ppp12345.static.someprovider.net
DEBUG -- : Session ID: 892e6ec515afde6f463102f83d373523bba62b26180a2e5a34a4945c787eacfd
DEBUG -- : ---------------------------------------------------------
DEBUG -- : {"username"=>"davesag", "verified"=>true, "updated_time"=>"2012-08-20T23:41:41+0000"}
DEBUG -- : ---------------------------------------------------------
DEBUG -- : Session ID: 892e6ec515afde6f463102f83d373523bba62b26180a2e5a34a4945c787eacfd
DEBUG -- : Completed request from host ppp12345.static.someprovider.net
DEBUG -- : ---------------------------------------------------------
DEBUG -- : ---------------------------------------------------------
所以问题是,我如何告诉 Heroku 统一其会话,以便 cookie 正确传输并匹配?