Rails omniauth-facebook未解决的问题

时间:2013-02-20 10:11:10

标签: ruby-on-rails facebook-javascript-sdk omniauth

目前的omniauth-facebook似乎有一些问题,我想知道是否有人对它们有答案。

第一个问题是无效凭据问题。由于此问题,我无法使用客户端授权登录我的应用程序。但是,这可以通过将facebook-omniauth降级到1.4.0版本来解决。 (reference

但是,现在我遇到第二个问题 NoAuthorizationCodeError ,错误消息:

OmniAuth Strategies Facebook NoAuthorizationCodeError 
(must pass either a `code` parameter or a signed request 
(via `signed_request` parameter):

这是在here中提出的,但是接受的答案建议再次实际升级到1.4.1版本,这会使先前的无效凭据问题再次发生。所以这对我来说不是一个选择。

当我尝试通过 Internet Explorer 登录Facebook iFrame(从应用程序中心搜索我的应用程序)中的应用程序时,NoAuthorizationCodeError发生了。在chrome或firefox上一切正常。还有github issue确切地指出了这个问题,但还没有人提出答案。我也尝试降级到omniauth-facebook 1.3.0版本,但它没有任何区别。我还尝试传递signed_request参数,如下所示:

window.location = '/auth/facebook/callback', 
{ signed_request: response.authResponse.signedRequest }

然而,它没有任何区别(在IE上,错误仍然存​​在),我不确定这是否是将代码作为参数传递的正确方法(我该如何检查?)< / p>

我认为我的设置没有问题。我非常感谢你对此事的任何帮助。

更新:

我升级到1.4.1版本没有无效的凭据问题,但是当我通过Internet Explorer访问Facebook内的应用程序时仍然会出现NoAuthorizationCodeError。检查我的Github issue

更新

我降级到1.4.0版本,并添加了signedRequest params。

<script>
function login() {
  FB.login(function(response) {
    if (response.authResponse) {
      window.location = '/auth/facebook/callback?' + $.param({ signed_request: response.authResponse.signedRequest })
    } 
  }, {scope: 'email,publish_stream,publish_actions'});
}
</script>

日志中没有错误或警报,一切都按预期工作。 但是,如果我通过Internet Explorer在Facebook iFrame中登录,即使在回调阶段启动后它也不会登录。我想原来的问题已经解决,但是当没有任何错误信息时,我无法弄清楚如何调试它。

问题:当我点击Facebook iFrame中的“使用Facebook登录”我的应用程序与Internet Explorer时,我没有在授权过程完成时登录。这个问题只发生在那个特定的环境中,我很难弄清楚原因。

2013-02-22T01:10:40+00:00 app[web.1]: Started GET "/auth/facebook/callback?signed_request=LONGSTRING" for 200.1.102.103 at 2013-02-22 01:10:40 +0000
2013-02-22T01:10:40+00:00 app[web.1]: (facebook) Callback phase initiated.
2013-02-22T01:10:40+00:00 app[web.1]: Processing by SessionsController#create_facebook as HTML
2013-02-22T01:10:40+00:00 app[web.1]:   Parameters: {"signed_request"=>"LONGSTRING", "provider"=>"facebook"}
2013-02-22T01:10:40+00:00 app[web.1]:   User Load (1.6ms)  SELECT "users".* FROM "users" WHERE "users"."provider" = 'facebook' AND "users"."uid" = 'MYUID' LIMIT 1
2013-02-22T01:10:40+00:00 app[web.1]:    (0.8ms)  BEGIN
2013-02-22T01:10:40+00:00 app[web.1]:   User Exists (1.0ms)  SELECT 1 AS one FROM "users" WHERE ("users"."name" = 'MYNAME' AND "users"."id" != 3) LIMIT 1
2013-02-22T01:10:40+00:00 app[web.1]:    (0.9ms)  COMMIT
2013-02-22T01:10:40+00:00 app[web.1]: Redirected to http://MYAPP.COM
2013-02-22T01:10:40+00:00 app[web.1]: Completed 302 Found in 10ms (ActiveRecord: 4.2ms)

同样,在任何其他环境中,授权在所有浏览器中都能完美运行。仅当我尝试通过Internet Explorer在Facebook中登录时才会出现此问题。

我的环境:omniauth-facebook 1.4.0,omniauth 1.1.1,oauth2 0.8.0,Rails 3.2.11

由于最新版本中的无效凭据错误,我故意将omniauth-facebook从1.4.1降级到1.4.0。

3 个答案:

答案 0 :(得分:1)

使用omniauth(1.1.3),oauth2(0.8.1)和omniauth-facebook(1.4.1)。

这些

不会出现任何错误

答案 1 :(得分:0)

thisgetting-more-information-from-omniauth-exceptions的帮助下{p} fastcatch中所述

... OmniAuth strategies [...], if they encounter a problem, call the method fail! and pass in a symbol describing the problem like :invalid_credentials and the exception they encountered. The fail! method ends up calling OmniAuth.config.on_failure and passing in the Rack environment (after doing a few other things like sticking the exception into the environment...

{{1}}

答案 2 :(得分:0)

由于您在使用iframe时只在Internet Explorer中看到此问题,因此可能是P3P问题。

参见http://www.slideshare.net/cmercier/things-i-learned-writing-a-facebook-canvas-appCookie blocked/not saved in IFRAME in Internet Explorer

Internet Explorer对IFRAME页面提供较低级别的信任(IE称为“第三方”内容)。如果IFRAME内的页面没有隐私政策,则其cookie将被阻止(状态栏中的眼睛图标表示,当您单击它时,它会显示被阻止的URL列表)。 ... 在这种情况下,当cookie被阻止时,不会发送会话标识符,并且目标脚本会抛出“找不到会话”错误。

尝试添加rack-p3p gem并查看它是否有帮助!