Omniauth Facebook Error - Faraday::Error::Connecti

2020-01-25 13:12发布

(FYI: I'm following the Twitter Omniauth from railscast #241. I used Twitter successfully, now going onto Facebook)

As soon as I logged into Facebook using Omniauth, I get this error:

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

What does this mean?

This is my code

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

There's actually nothing much in my code, all I have is in the sessionController that I want to use to_yaml to see what's inside the request.env

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

How do I solve the Faraday error?

9条回答
趁早两清
2楼-- · 2020-01-25 13:39

Andrei's answer worked for me, however I ran into a huge roadblock when trying to reinstall Ruby 1.9.3. Because I had installed a new version of Xcode since installing 1.9.3 I was unable to reinstall until I opened the Xcode Preferences and installed the Command Line Tools from the Downloads tab.

查看更多
三岁会撩人
3楼-- · 2020-01-25 13:46

I've fixed this on Mac OS X Lion 10.7.4 with this solution:

$ 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

after this you will need to download the missing cacert.pem file:

$ cd $rvm_path/usr/ssl
$ sudo curl -O http://curl.haxx.se/ca/cacert.pem
$ sudo mv cacert.pem cert.pem
查看更多
放我归山
4楼-- · 2020-01-25 13:51

this worked for me (on Mac OS X):

$ brew install curl-ca-bundle
$ export SSL_CERT_FILE=/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt
查看更多
Evening l夕情丶
5楼-- · 2020-01-25 13:51

Check out certified gem. Description:

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

查看更多
啃猪蹄的小仙女
6楼-- · 2020-01-25 13:52

For Windows 7: the above solution link of Neil Hoff (Fix for Windows: https://gist.github.com/867550) did not work for me.

Here is what works:

Using cmd.exe:

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

using 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

Dunn.

查看更多
Luminary・发光体
7楼-- · 2020-01-25 13:54

You are getting this error because Ruby cannot find a root certificate to trust.

Fix for Windows: https://gist.github.com/867550

Fix for Apple/Linux: http://martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error/ <--This site is now down.

Here is the Apple/Linux fix according the site above:

The solution is to install the curl-ca-bundle port which contains the same root certificates used by Firefox:

sudo port install curl-ca-bundle

and tell your https object to use it:

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

Note that if you want your code to run on Ubuntu, you need to set the ca_path attribute instead, with the default certificates location /etc/ssl/certs.

In the end, that’s what will work on both Mac OS X and 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('/')
查看更多
登录 后发表回答