【问题标题】:Why is heroku timing out when I try to use Omniauth + Google Apps?为什么当我尝试使用 Omniauth + Google Apps 时 heroku 会超时?
【发布时间】:2011-07-22 22:30:26
【问题描述】:

我正在尝试使用 Omniauth 针对 Google Apps 提供简单的基本身份验证。在本地一切正常(即使在生产模式下),但在 Heroku 我得到以下信息:

app[web.1]: Started GET "/auth/admin" for 24.155.228.161 at Fri Jul 22 15:10:26 -0700 2011
heroku[router]: Error H12 (Request timeout) -> GET example.com/auth/admin dyno=web.1 queue= wait= service=30000ms status=503 bytes=
heroku[router]: Error H12 (Request timeout) -> GET example.com/ dyno=web.1 queue= wait= service=30000ms status=503 bytes=0
app[web.1]: Generated checkid_setup request to https://www.google.com/a/example.com/o8/ud?be=o8 with assocication AOQobUegRUNfEpz1JOO2bZe0zXrjkdIvdsjpVyCh3rtbL_s-GSfhQ_zY

我的设置如下;

# initializers/omniauth.rb
require "openid/fetchers"
OpenID.fetcher.ca_file = "#{Rails.root}/cacert.crt"

require 'openid/store/filesystem'

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_apps, OpenID::Store::Filesystem.new('./tmp')
  use OmniAuth::Strategies::GoogleApps, OpenID::Store::Filesystem.new('./tmp'), :name => 'admin', :domain => 'bcarc.com' #, :client_options => {:ssl => {:ca_file => './cacert.crt'}} 
end

我已经尝试切换到 memcached,但我无法让 memcached-northscaledalli 工作,而且无论如何我已经验证了随机数正确保存在 ./tmp 中,所以我没有'认为这不是问题。

我收到有关 CA 证书的错误,但将证书文件指定给 fetcher 解决了这个问题,但我仍然遇到超时。

有什么建议吗?

更新: 我已经将此追踪到 OmniAuth 的回调处理程序。请求被发送到 Google Apps,但在回调控制器有机会做任何事情之前回调超时。

【问题讨论】:

  • 您可能想尝试使用 2 个测功机。

标签: ruby-on-rails openid heroku google-docs omniauth


【解决方案1】:

好的,所以经过多次拉扯后,看起来这是 OmniAuth 处理 Google Apps URI 的问题。我最终使用了普通的谷歌 OpenID 端点,然后手动验证了我的控制器中的域。对于任何感兴趣的人,我的代码现在看起来像这样:

require "openid/fetchers"
OpenID.fetcher.ca_file = "#{Rails.root}/cacert.crt"

require 'openid/store/filesystem'

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :openid, OpenID::Store::Filesystem.new('./tmp')

  use OmniAuth::Strategies::OpenID, OpenID::Store::Filesystem.new('./tmp'), :name =>       'openid', :identifier => 'https://www.google.com/accounts/o8/id'
end

前两行消除了 Heroku 抛出的一些 SSL 警告。我正在使用./tmp 进行文件存储,而且效果很好。在我的控制器中,我有一个 if/then 子句,用于在经过身份验证的电子邮件中检查我的域并重定向到一个页面,告诉用户选择正确的帐户。

这不是一个理想的解决方案,但我无法使用任何一个应用程序特定的 OpenID 标识符来工作。

【讨论】:

  • 我必须遗憾地支持这个解决方案。 :) 同意它是次优的,但它也完全可以运行。谢谢@Kerinin!
【解决方案2】:

我有同样的问题,但只有当我尝试对与 heroku 应用程序响应的域相同的域进行身份验证时。针对谷歌应用程序上的其他域进行身份验证工作正常。

我认为这个问题是因为从 google 或 omniauth gem 到 domain/openid?=some_number 有某种阻塞 pingback。因为测功机正忙于为 /auth/google_apps 提供请求,所以它无法回答其他请求,因此超时。如果我想办法避免该阻塞请求,我会告诉你的。

【讨论】:

  • 我遇到了同样的问题。在 1 台测功机上运行,​​将其增加到 2 台。第一个请求失败,第二个请求通过,我得到了批准我的应用程序的屏幕。仍然在回调时,我遇到了另一个错误。刷新时,我已登录。我的网站似乎已被 Google 索引,因此这可能解释了超时,因为一直在消耗 dynos。
【解决方案3】:

我在开发中遇到了同样的问题。基于@Kerinin 的辛勤工作,这就是我最终得到的,并且到目前为止似乎正在工作......

Rails.application.config.middleware.use OmniAuth::Builder do
 use OmniAuth::Strategies::OpenID, name: 'openid', identifier: 'https://www.google.com/accounts/o8/id'
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多