本文介绍了Omniauth Facebook 错误 - Faraday::Error::ConnectionFailed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

当我使用 Omniauth 登录 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

这是什么意思?

这是我的代码

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

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

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

如何解决法拉第误差?

推荐答案

您收到此错误是因为 Ruby 找不到可信任的根证书.

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

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

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

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

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

这是根据上述站点的 Apple/Linux 修复:

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

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

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

and tell your https object to use it:

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

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

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.

最后,这将适用于 Mac OS X 和 Ubuntu:

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

这篇关于Omniauth Facebook 错误 - Faraday::Error::ConnectionFailed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:12