Search code examples
facebookomniauthfaraday-oauth

Omniauth Facebook Error - Faraday::Error::ConnectionFailed


(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?


Solution

  • 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('/')