2012-03-18 92 views
0

我正在嘗試爲AuthLogic與Facebook一起實施OmniAuth。目前,我發現了以下錯誤:rails 3 omniauth SSL錯誤

所以SSL_connect返回= 1個錯誤號= 0狀態= SSLv3的讀取服務器證書B:證書驗證失敗

我已經試過這裏顯示的解決方案:SSL Error OmniAuth in Ruby on Rails,但沒有成功。嘗試啓動我的服務器時,出現錯誤(未定義的局部變量或方法`config')。我在一臺Windows機器上下載了cacert.pem文件並將其放在/ config /文件夾中。

下面是我在我的/initialzers/omniauth.rb文件中的代碼:

Rails.application.config.middleware.use OmniAuth::Builder do 

require "omniauth-facebook" 

if RbConfig::CONFIG["host_os"] =~ /mingw|mswin/ 
ca_file = File.expand_path Rails.root.join("config", "cacert.pem") 

ssl_options = {} 
ssl_options[:ca_path] = '/etc/ssl/certs' if Rails.env.staging? 
ssl_options[:ca_file] = ca_file 

config.omniauth :facebook, "MYAPPID", "MYAPPSECRET", # "APP_ID", "APP_SECRET" your got from facebook app registration 
    :client_options => {:ssl => ssl_options} 
else 
config.omniauth :facebook, "MYAPPID", "MYAPPSECRET" 
end 

end 

我也看到了帖子引用CA-certificate.crt代替cacert.pem,其中哪些是找對於?我有點迷失在接下來的嘗試,所以任何幫助非常感謝!

回答

2

你得到的(未定義的局部變量或方法'config')錯誤是因爲在你的文件中沒有定義'config'變量。你從中提取的帖子是配置設計,其中有 Devise.setup do |config| ... end 塊,所以變量配置可以在那裏使用。

擺脫配置變量,因此它會是這樣的,

Rails.application.config.middleware.use OmniAuth::Builder do 


if RbConfig::CONFIG["host_os"] =~ /mingw|mswin/ 
    ca_file = File.expand_path Rails.root.join("config", "cacert.pem") 

    ssl_options = {} 
    ssl_options[:ca_path] = '/etc/ssl/certs' if Rails.env.staging? 
    ssl_options[:ca_file] = ca_file 

    provider :facebook, "MYAPPID", "MYAPPSECRET", # "APP_ID", "APP_SECRET" your got from facebook app registration 
    :client_options => {:ssl => ssl_options} 
else 
    provider :facebook, "MYAPPID", "MYAPPSECRET" 
end 

end 
0

Rails.application.config.middleware.use OmniAuth ::生成器做 提供商:臉譜,FACEBOOK_KEY,FACEBOOK_SECRET,{: client_options => {:SSL => {:ca_path => 「的/ etc/SSL /證書」}}} 結束

這不是標準的方式,但它可以通過禁用SSL驗證幫助你開發設置。

如果Rails.env.development? OpenSSL :: SSL :: VERIFY_PEER = OpenSSL :: SSL :: VERIFY_NONE end