【问题标题】:Omniauth Facebook Error - Faraday::Error::ConnectionFailedOmniauth Facebook 错误 - Faraday::Error::ConnectionFailed
【发布时间】:2023-03-28 09:25:02
【问题描述】:

(仅供参考:我正在关注来自 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

这是什么意思?

这是我的代码

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

如何解决法拉第错误?

【问题讨论】:

    标签: facebook omniauth faraday-oauth


    【解决方案1】:

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

    【讨论】:

    • 谢谢!我尝试了一堆解决方案,但这就是让它在本地为我工作所需要的。
    • 是的,这对我来说效果更好,因为我没有使用“端口” - 谢谢!
    • 非常有用。与 Rails、devise 和 google oauth 一起在 10.8.2 中运行良好
    • 重新安装 ruby​​ 直到编译步骤。然后我得到: 运行'make'时出错,请阅读/usr/local/rvm/log/ruby-1.9.3-p392/make.log 运行make时出错。停止安装。
    • 如以下答案所示,您应该参考 Rails 项目中的这篇文章:railsapps.github.io/openssl-certificate-verify-failed.html
    【解决方案2】:

    您收到此错误是因为 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
    

    并告诉你的 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('/')
    

    【讨论】:

    • 谢谢,您的回答来得正是时候,因为我正在休假 1 周。谢谢!
    • 那个网站一定是刚下线。我添加了谷歌缓存版本。
    • "告诉你的 https 对象使用它:"你能详细说明一下吗?我应该将给定的代码行放在我的 Rails 应用程序某处的 .rb 文件中吗?在哪里?
    • 非常感谢。这对我有很大帮助:)
    • @NeilHoff 你能详细说明 GeorgMillo 的问题吗?
    【解决方案3】:

    Andrei 的回答在 Mac OSX 10.8.3 上对我不起作用。前段时间我重新安装了openssl来安装ruby 2.0,从那以后总是出现这个错误。感谢 Andrei 的回答和instructions from the Rails project,我修复了它。

    我跑了:

    $ 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
    

    之后问题就解决了。希望对遇到同样问题的其他人有所帮助。

    【讨论】:

    • 我已将此答案发送给 5 个人,它总能解决问题!你这个男人!
    【解决方案4】:

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

    $ brew install curl-ca-bundle
    $ export SSL_CERT_FILE=/usr/local/opt/curl-ca-bundle/share/ca-bundle.crt
    

    【讨论】:

    • 这在 OSx 10.8.5 上也适用于我,这里没有其他解决方案有效,只有这个,谢谢!
    【解决方案5】:

    替代解决方案:

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

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

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

    【讨论】:

      【解决方案6】:

      RVM 网站建议运行 rvm osx-ssl-certs update all

      RVM Website: How to fix broken certificates in your operating system.

      【讨论】:

        【解决方案7】:

        对于 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
        

        如果您的 Windows 7 命令行上没有 curl,请在此处获取: http://www.confusedbycode.com/curl/#downloads

        原始解决方案来自这里 - 归功于: https://github.com/chef/chef-dk/issues/106

        邓恩。

        【讨论】:

          【解决方案8】:

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

          【讨论】:

            【解决方案9】:

            查看certified gem。说明:

            确保 net/https 使用 OpenSSL::SSL::VERIFY_PEER 来验证 SSL 证书并提供证书包以防 OpenSSL 不能 找一个

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2016-01-27
              • 2020-03-29
              • 2021-01-26
              • 1970-01-01
              • 2016-01-27
              • 2018-10-25
              相关资源
              最近更新 更多