使用 omniauth-facebook 的 facebook 登录执行过期错误

Execution expired error with facebook login, using omniauth-facebook

自 7 月 3 日起,用户将无法从 Facebook 登录。 我正在使用 omniauth-facebook。我从 localhost 成功测试了登录(指向另一个 FB 测试应用程序)。但在生产中,应用程序显示此错误:

Started GET "/auth/facebook" for 190.238.101.80 at 2019-07-10 17:53:51 -0500
I, [2019-07-10T17:53:51.594796 #4707]  INFO -- omniauth: (facebook) Request phase initiated.
Started GET "/auth/facebook/callback?code=AQAj5FOJuHu7UY656lbwZ4Sfcf_J_ZX9Z_t0wRT-LDfnPLU530zKj5CNGEK53yJ9maNj8O80fWgGmxCq4zWqBK7CPN-ovokGZVIvfY0KaqzNRXWOC20kH4KhkYOHjPyRh4tMYTIcHZ1a0BvHfbBLVolYECVtfD1OKJ2Xob07LCpS0SHNhYc6PA3rBAnb6GnkvOZI-8S7nwXIICdFoKu0BbHd-6L8_Dq-dPFTOpJDSWgmoJUBc65EyCnuw7NCI4IFP1UtxtOmB_QjuzRQV-voQs_SV6N97c2ICK_Qc-IqL_WBwqd54aEzdnW5UOsDV4Wo0jA&state=cee86047aecb4d282b80d33bbd0469815a17d25566167d95" for 190.238.101.80 at 2019-07-10 17:53:52 -0500
I, [2019-07-10T17:53:52.082829 #4707]  INFO -- omniauth: (facebook) Callback phase initiated.

Faraday::ConnectionFailed (execution expired):
  /usr/lib/ruby/2.5.0/net/http.rb:937:in `initialize'
  /usr/lib/ruby/2.5.0/net/http.rb:937:in `open'
  /usr/lib/ruby/2.5.0/net/http.rb:937:in `block in connect'
  /usr/lib/ruby/2.5.0/timeout.rb:103:in `timeout'
  /usr/lib/ruby/2.5.0/net/http.rb:935:in `connect'
  /usr/lib/ruby/2.5.0/net/http.rb:920:in `do_start'
  /usr/lib/ruby/2.5.0/net/http.rb:909:in `start'
  /usr/lib/ruby/2.5.0/net/http.rb:1458:in `request'
  faraday (0.15.4) lib/faraday/adapter/net_http.rb:87:in `perform_request'
  faraday (0.15.4) lib/faraday/adapter/net_http.rb:43:in `block in call'
  faraday (0.15.4) lib/faraday/adapter/net_http.rb:92:in `with_net_http_connection'
  faraday (0.15.4) lib/faraday/adapter/net_http.rb:38:in `call'
  faraday (0.15.4) lib/faraday/request/url_encoded.rb:15:in `call'
  faraday (0.15.4) lib/faraday/rack_builder.rb:143:in `build_response'
  faraday (0.15.4) lib/faraday/connection.rb:387:in `run_request'
  oauth2 (1.4.1) lib/oauth2/client.rb:99:in `request'
  oauth2 (1.4.1) lib/oauth2/client.rb:146:in `get_token'
  oauth2 (1.4.1) lib/oauth2/strategy/auth_code.rb:30:in `get_token'
  omniauth-oauth2 (1.6.0) lib/omniauth/strategies/oauth2.rb:89:in `build_access_token'
  omniauth-facebook (5.0.0) lib/omniauth/strategies/facebook.rb:110:in `build_access_token'
  omniauth-oauth2 (1.6.0) lib/omniauth/strategies/oauth2.rb:73:in `callback_phase'
  omniauth-facebook (5.0.0) lib/omniauth/strategies/facebook.rb:67:in `block in callback_phase'
  omniauth-facebook (5.0.0) lib/omniauth/strategies/facebook.rb:131:in `with_authorization_code!'
  omniauth-facebook (5.0.0) lib/omniauth/strategies/facebook.rb:66:in `callback_phase'
  omniauth (1.9.0) lib/omniauth/strategy.rb:238:in `callback_call'
  omniauth (1.9.0) lib/omniauth/strategy.rb:189:in `call!'
  omniauth (1.9.0) lib/omniauth/strategy.rb:169:in `call'
  omniauth (1.9.0) lib/omniauth/builder.rb:64:in `call'
  rack (1.6.11) lib/rack/etag.rb:24:in `call'
  rack (1.6.11) lib/rack/conditionalget.rb:25:in `call'
  rack (1.6.11) lib/rack/head.rb:13:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.11) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.11) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.8) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.8) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
  activesupport (4.2.8) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
  activesupport (4.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.8) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.8) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.8) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.8) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.8) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.11) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.11) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.8) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/static.rb:120:in `call'
  rack (1.6.11) lib/rack/sendfile.rb:113:in `call'
  actionpack (4.2.8) lib/action_dispatch/middleware/ssl.rb:24:in `call'
  railties (4.2.8) lib/rails/engine.rb:518:in `call'
  railties (4.2.8) lib/rails/application.rb:165:in `call'
  rack (1.6.11) lib/rack/content_length.rb:15:in `call'
  thin (1.7.2) lib/thin/connection.rb:86:in `block in pre_process'
  thin (1.7.2) lib/thin/connection.rb:84:in `catch'
  thin (1.7.2) lib/thin/connection.rb:84:in `pre_process'
  thin (1.7.2) lib/thin/connection.rb:53:in `process'
  thin (1.7.2) lib/thin/connection.rb:39:in `receive_data'
  eventmachine (1.2.7) lib/eventmachine.rb:195:in `run_machine'
  eventmachine (1.2.7) lib/eventmachine.rb:195:in `run'
  thin (1.7.2) lib/thin/backends/base.rb:73:in `start'
  thin (1.7.2) lib/thin/server.rb:162:in `start'
  rack (1.6.11) lib/rack/handler/thin.rb:19:in `run'
  rack (1.6.11) lib/rack/server.rb:287:in `start'
  railties (4.2.8) lib/rails/commands/server.rb:80:in `start'
  railties (4.2.8) lib/rails/commands/commands_tasks.rb:80:in `block in server'
  railties (4.2.8) lib/rails/commands/commands_tasks.rb:75:in `tap'
  railties (4.2.8) lib/rails/commands/commands_tasks.rb:75:in `server'
  railties (4.2.8) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  railties (4.2.8) lib/rails/commands.rb:17:in `<top (required)>'
  bin/rails:8:in `require'
  bin/rails:8:in `<main>'

我尝试使用 localhost 通过 Facebook 创建一个测试应用程序并且它有效。 我尝试在另一个域中使用另一个正在生产的应用程序,它可以工作。 它不适用于生产中的这个特定应用程序。我给 Facebook 支持发了消息,但他们没有回复,几天过去了。

我使用的是 RoR 4.2.8,Bundler 1.17.3 我尝试使用 ruby-2.5.1 和 ruby-2.3.3 以防万一(同样的错误)

我尝试使用另一个具有相同设置的 Facebook 应用程序,使用另一个具有 ruby-2.6 的 RoR v5 应用程序并且它有效,因此 FB 应用程序设置似乎没问题。

我创建了另一个 FB 应用程序,尝试使用失败的 RoR v4.2.8 应用程序,它失败并出现相同的 "Faraday::ConnectionFailed (execution expired):" 错误。

config/initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, 'APP-ID', 'SECRET',
    scope: 'email'
end

用户应该可以使用 Facebook 登录,但失败 "Faraday::ConnectionFailed (execution expired):"

从您的情况来看,您遇到了网络问题,Faraday 未设置为等待足够长的响应时间。从跟踪中我能真正看出的是,在通往 facebook 的路径上的某个地方,你遇到了网络问题。

我想检查几件事:

  • 如果您的站点 运行 通过 HTTPS,请确保您的证书工作正常。
    • 检查您的 gem 文件是否设置为需要与您的 Rails 版本和依赖项兼容的特定版本 omniauth-facebook
    • 延长法拉第的超时时间
    • 使用像 https://github.com/ooyala/retries 这样的重试 gem 来尝试给网络足够的时间在法拉第关闭连接之前做出响应。

其他一些人在 omniauth-facebook 的 github https://github.com/mkdynamic/omniauth-facebook/issues/283

中对此问题发表了评论