简体   繁体   English

rails 3 omniauth SSL错误

[英]rails 3 omniauth SSL error

I'm trying to implement OmniAuth for Facebook in tandem with AuthLogic. 我正在尝试与AuthLogic一起实现OmniAuth for Facebook。 I'm currently getting the following error: 我目前收到以下错误:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:证书验证失败

I've tried the solution shown here: SSL Error OmniAuth in Ruby on Rails with no success. 我试过这里显示的解决方案: Ruby on Rails中的SSL错误OmniAuth没有成功。 I'm getting the error (undefined local variable or method `config') when trying to start my server. 我在尝试启动服务器时收到错误(未定义的局部变量或方法`config')。 I'm on a windows machine and have downloaded the cacert.pem file and placed it in the /config/ folder. 我在Windows机器上并下载了cacert.pem文件并将其放在/ config /文件夹中。

Here's the code I have in my /initialzers/omniauth.rb file: 这是我在/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

I've also seen posts referencing ca-certificate.crt instead of cacert.pem, which of these is it looking for? 我也看过引用ca-certificate.crt而不是cacert.pem的帖子,其中有哪些是它在寻找? I'm a little lost on what to try next so any help is greatly appreciated! 我有点迷失在接下来的尝试,所以任何帮助都非常感谢!

The (undefined local variable or method 'config') error you are getting here is because there is no 'config' variable defined in your file. 您在此处获得的(未定义的局部变量或方法'config')错误是因为您的文件中没有定义'config'变量。 The post you extracted it from was configuring devise which has Devise.setup do |config| ... end 你从中提取的帖子是配置Devise.setup do |config| ... end Devise.setup do |config| ... end block so the variable config can be used there. Devise.setup do |config| ... end块所以可以在那里使用变量配置。

Get rid of the config variable so it would be something like this, 摆脱配置变量,所以它会是这样的,

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

Rails.application.config.middleware.use OmniAuth::Builder do provider :facebook, FACEBOOK_KEY, FACEBOOK_SECRET, {:client_options => {:ssl => {:ca_path => "/etc/ssl/certs"}}} end Rails.application.config.middleware.use OmniAuth :: Builder做提供者:facebook,FACEBOOK_KEY,FACEBOOK_SECRET,{:client_options => {:ssl => {:ca_path =>“/ etc / ssl / certs”}}}结束

This is not the standard way but it may help you on development setup by disabling ssl verification. 这不是标准方法,但它可以通过禁用ssl验证来帮助您进行开发设置。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM