【问题标题】:Rails omniauth-facebook unsolved issueRails omniauth-facebook 未解决的问题
【发布时间】:2013-02-20 10:11:10
【问题描述】:

目前的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 版本,这会使之前的无效凭据问题再次发生。所以这不是我的选择。

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

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

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

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

更新:

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

更新:

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

<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 中为我的 Internet Explorer 应用程序单击“使用 Facebook 登录”时,授权过程完成后我没有登录。这个问题只发生在那个特定的环境中,我很难找出原因。

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

由于最新版本中出现invalid credentials错误,我故意将omniauth-facebook 从1.4.1 降级到1.4.0。

【问题讨论】:

  • 我也面临同样的问题,在我将 omniauth-facebook gem 降级到 1.4.0 版本后问题解决了。

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


【解决方案1】:

利用omniauth (1.1.3)、oauth2 (0.8.1) 和omniauth-facebook (1.4.1)。

这些不会有任何错误

【讨论】:

    【解决方案2】:

    fastcatchthis SO 帖子中在getting-more-information-from-omniauth-exceptions 的帮助下说,

    ... 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...

    【讨论】:

    • 感谢@saurabh,但这并不能完全解决上述问题。我已经知道这些信息了。
    【解决方案3】:

    因为您在使用 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 看看是否有帮助!

    【讨论】:

      猜你喜欢
      • 2015-09-11
      • 2017-11-14
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      相关资源
      最近更新 更多