Omniauth Facebook错误 - 法拉第::错误:: ConnectionFailed

use*_*829 45 facebook omniauth faraday-oauth

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

当我使用Omniauth登录Facebook时,我收到此错误:

Faraday::Error::ConnectionFailed
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
Run Code Online (Sandbox Code Playgroud)

这是什么意思?

这是我的代码

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, '<key from fb>', '<another key from fb>'
end
Run Code Online (Sandbox Code Playgroud)

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

class SessionsController < ApplicationController
    def create
        raise request.env["omniauth.auth"].to_yaml
    end
end
Run Code Online (Sandbox Code Playgroud)

如何解决法拉第错误?

And*_*scu 63

我用这个解决方案在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
Run Code Online (Sandbox Code Playgroud)

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

$ cd $rvm_path/usr/ssl
$ sudo curl -O http://curl.haxx.se/ca/cacert.pem
$ sudo mv cacert.pem cert.pem
Run Code Online (Sandbox Code Playgroud)


Nei*_*off 29

您收到此错误是因为Ruby无法找到要信任的根证书.

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

修复Apple/Linux:http://martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error/ < - 此网站现已关闭.

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

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

sudo port install curl-ca-bundle
Run Code Online (Sandbox Code Playgroud)

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

https.ca_file = '/opt/local/share/curl/curl-ca-bundle.crt'
Run Code Online (Sandbox Code Playgroud)

请注意,如果您希望代码在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('/')
Run Code Online (Sandbox Code Playgroud)

  • "告诉你的https对象使用它:"你能详细说明吗?我应该将给定的代码行放在我的Rails应用程序中的某个.rb文件中吗?哪里? (7认同)

jtb*_*lin 21

在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...
Run Code Online (Sandbox Code Playgroud)

然后我检查证书是否通过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
Run Code Online (Sandbox Code Playgroud)

之后问题得到解决.希望能帮助遇到同样问题的其他人.


lev*_*lex 8

这对我有用(在Mac OS X上):

$ brew install curl-ca-bundle
$ export SSL_CERT_FILE=/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt
Run Code Online (Sandbox Code Playgroud)