English 中文(简体)
Omniauth Facebook错误-Faraday::错误::连接失败
原标题:Omniauth Facebook Error - Faraday::Error::ConnectionFailed

(仅供参考:我正在关注来自railscast#241的推特Omniauth。我成功地使用了推特,现在去了脸书)

当我使用Omniauth登录Facebook时,我收到了以下错误:

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找不到可信任的根证书。

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

修复适用于Apple/Linux的问题:http://martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error/<--该网站现已关闭。

根据上面的网站,这是Apple/Linux修复程序:

解决方案是安装curl ca捆绑包端口,该端口包含与Firefox使用的根证书相同的根证书:

sudo port install curl-ca-bundle

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

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

请注意,如果你想让你的代码在Ubuntu上运行,你需要设置ca_path属性,使用默认的证书位置/etc/ssl/certs。

最后,这就是适用于Mac OS X和Ubuntu的方法:

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( / )
问题回答

我已经用这个解决方案在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

在此之后,您需要下载丢失的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上对我不起作用。不久前,我重新安装了openssl来安装ruby 2.0,从那以后总是遇到这个错误。多亏了安德烈的回答和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

替代解决方案:

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

我也有同样的问题,但无法通过这个问题的答案来解决。顺便说一句,最后,我通过以下网址解决了问题

Facebook Redirect url in ruby on rails open ssl error https://github.com/technoweenie/faraday/wiki/Setting-up-SSL-certificates

RVM网站建议运行RVM-osx-ssl证书更新所有

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

对于Windows 7:Neil Hoff的上述解决方案链接(针对Windows的修复:https://gist.github.com/867550)对我不起作用。

以下是有效的方法:

使用cmd.exe:

curl -o c: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

If you do not have curl on your windows 7 command line get it here: http://www.confusedbycode.com/curl/#downloads

original solution is from here - credit to: https://github.com/chef/chef-dk/issues/106

邓恩。

Andrei的答案对我很有效,但在尝试重新安装Ruby 1.9.3时遇到了巨大的障碍。因为我在安装1.9.3后安装了新版本的Xcode,所以在打开Xcode首选项并从下载选项卡安装命令行工具之前,我无法重新安装。

查看认证宝石。描述:

Ensure net/https uses OpenSSL::SSL::VERIFY_PEER to verify SSL certificates and provides certificate bundle in case OpenSSL cannot find one





相关问题
Facebook Connect login dialog not working

I am using Facebook Connect for iPhone and following the official instructions. I use the following code to display the login dialog: FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:...

Facebook App Profile Tab is Empty ... No Content Displayed?

I can view my application via the http://apps.facebook.com/myapplication/ link and the content shows up correctly. I also added the application as a tab to a facebook page. However, when viewing the ...

Facebook Platform error: "Object cannot be liked"

I m working on a Facebook Application that generates wall posts. In testing these posts, I ve discovered that the Facebook Platform action of "liking" a post is failing. The specific error message ...

how to call showPermissionsDialog() in php (facebook api)?

I was reading over the documentation yet I could not figure out how to call Facebook.showPermissionsDialog() in php include_once ./facebook-platform/php/facebook.php ; $facebook = new Facebook(my ...

Facebook connect

If I plug in the facebook connect into my website, How can I prevent double signups? Lets say I have a user that s already signed up to my site but he clicked the connect with facebook, is there a ...