为什么当我尝试使用Omniauth + Google Apps时,heroku超时了?



我试图使用Omniauth提供简单,基本的身份验证对谷歌应用程序。一切工作正常本地(即使在生产模式),但在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的工作,在任何情况下,我已经验证了nces被保存在./tmp正确,所以我不认为这是问题。

我得到一个关于CA证书的错误,但指定证书文件到获取器解决了这个问题,我仍然得到超时。

有什么建议吗?

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

好了,经过一番折腾,看起来这是OmniAuth handline Google Apps URI的问题。我最终使用了普通的google 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标识符。

我也有同样的问题,但只有当我尝试对与heroku应用程序响应的域相同的域进行身份验证时,才会出现这种情况。在谷歌应用程序上对其他域进行身份验证工作正常。

我相信这个问题是因为有某种阻塞pingback从谷歌或omniauth gem,到domain/openid?=some_number。因为dyno忙于处理/auth/google_apps的请求,所以它不能回答其他请求,因此会超时。如果我找到了避免阻塞请求的方法,我会告诉你的。

我在开发过程中也遇到了同样的问题。基于@Kerinin的努力工作,这是我最终得到的,似乎到目前为止还在工作…

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

最新更新