Omniauth Facebook错误 – Faraday ::错误:: ConnectionFailed

(仅供参考:我正在使用来自railscast#241的Twitter Omniauth,我成功地使用了Twitter,现在进入Facebook)

只要我使用OmniauthloginFacebook,我得到这个错误:

Faraday::Error::ConnectionFailed SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed 

这是什么意思?

这是我的代码

 Rails.application.config.middleware.use OmniAuth::Builder do provider :facebook, '<key from fb>', '<another key from fb>' end 

在我的代码中实际上没有什么,我所拥有的是在sessionController中,我想使用to_yaml来查看request.env

 class SessionsController < ApplicationController def create raise request.env["omniauth.auth"].to_yaml end end 

我如何解决法拉第误差?

您正在收到此错误,因为Ruby无法find要信任的根证书。

修复Windows: https : //gist.github.com/867550

修正苹果/ Linux: http : //martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error/ < – 这个网站现在已经closures。

以下是根据上述网站的Apple / Linux修复程序:

解决scheme是安装curl-ca-bundle端口,其中包含Firefox使用的相同根证书:

 sudo port install curl-ca-bundle 

并告诉你的https对象使用它:

 https.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt' 

请注意,如果您希望代码在Ubuntu上运行,则需要使用默authentication书位置/ etc / ssl / certs来设置ca_path属性。

最后,在Mac OS X和Ubuntu上都可以使用这个function:

 require 'net/https' https = Net::HTTP.new('encrypted.google.com', 443) https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_PEER https.ca_path = '/etc/ssl/certs' if File.exists?('/etc/ssl/certs') # Ubuntu https.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt' if File.exists('/opt/local/share/curl/curl-ca-bundle.crt') # Mac OS X https.request_get('/') 

我已经用这个解决scheme在Mac OS X Lion 10.7.4上解决了这个问题:

 $ rvm remove 1.9.3 (or whatever version of ruby you are using) $ rvm pkg install openssl $ rvm install 1.9.3 --with-openssl-dir=$rvm_path/usr 

在此之后,您将需要下载缺less的cacert.pem文件:

 $ cd $rvm_path/usr/ssl $ sudo curl -O http://curl.haxx.se/ca/cacert.pem $ sudo mv cacert.pem cert.pem 

在Mac OSX 10.8.3上,Andrei的回答并不适用于我。 前段时间我重新安装了openssl来安装ruby 2.0,从那以后总是得到这个错误。 我解决了这个问题,感谢Andrei的回答和来自Rails项目的指示 。

我跑了:

 $ rvm -v $ rvm get head # Installation of latest version of rvm... $ rvm -v # rvm 1.19.5 (master) $ rvm osx-ssl-certs status all # Certificates for /usr/local/etc/openssl/cert.pem: Old. # Certificates for /Users/mpapis/.sm/pkg/versions/openssl/0.9.8x/ssl/cert.pem: Old. $ sudo rvm osx-ssl-certs update all # Updating certificates... 

然后我再次运行rvm osx-ssl-certs status all检查证书是否正确更新,但是/usr/local/etc/openssl/cert.pem仍然没有更新。 我不知道这是否有必要,但我做了以下几点:

 $ cd /usr/local/etc/openssl/ $ curl -O http://curl.haxx.se/ca/cacert.pem $ mv cacert.pem cert.pem 

之后问题解决了。 希望能够帮助遇到同样问题的其他人。

这为我工作(在Mac OS X上):

 $ brew install curl-ca-bundle $ export SSL_CERT_FILE=/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt 

替代scheme:

[我是Win7用户,手动安装Ruby和Ruby on Rails]

我有同样的问题,但不能通过这个问题给出的答案来解决。 顺便说一下,最后,我通过下面的url解决了问题

Facebook的redirectURL在轨道上的Ruby打开SSL错误 https://github.com/technoweenie/faraday/wiki/Setting-up-SSL-certificates

RVM网站build议运行rvm osx-ssl-certs update all

RVM网站:如何修复您的操作系统中损坏的证书。

对于Windows 7:Neil Hoff(Fix for Windows: https : //gist.github.com/867550 )的上述解决scheme链接对我不起作用。

这是什么工作:

使用cmd.exe:

 curl -oc:\cacert.pem http://curl.haxx.se/ca/cacert.pem set SSL_CERT_FILE=c:\cacert.pem 

使用msysgit bash:

 curl -o /c/cacert.pem http://curl.haxx.se/ca/cacert.pem export SSL_CERT_FILE=/c/cacert.pem 

如果你没有curl你的Windows 7命令行得到它在这里: http : //www.confusedbycode.com/curl/#downloads

原来的解决scheme是从这里 – 信贷: https : //github.com/chef/chef-dk/issues/106

邓恩。

Andrei的答案为我工作,但是当我试图重新安装Ruby 1.9.3时遇到了一个巨大的障碍。 因为自从安装1.9.3版本以来,我已经安装了新版本的Xcode,所以我无法重新安装,直到我打开Xcode首选项并从“下载”选项卡安装了命令行工具。

查看authentication的gem。 描述:

确保net / https使用OpenSSL :: SSL :: VERIFY_PEER来validationSSL证书,并在OpenSSL找不到的时候提供证书包

Interesting Posts