【问题标题】:Error when I try to authenticate through Facebook with omniauth当我尝试使用 omniauth 通过 Facebook 进行身份验证时出错
【发布时间】:2011-11-13 13:23:19
【问题描述】:

我关注了 Ryan Bates Omniauth Part1 railscats http://railscasts.com/episodes/235-omniauth-part-1 。我将 twitter 和 Facebook 身份验证与他们的密码一起使用,当我尝试通过 Facebook (auth/facebook) 进行身份验证时,我收到此错误:

{
   "error": {
      "message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
      "type": "OAuthException"
   }
}

当我尝试通过 twitter (auth/twitter) 进行身份验证时,我收到了 401 Unauthorized 响应。不知道怎么改啊

感谢我更正了在 twitter URL 回调字段和 facebook 我的网站字段中输入 http://127.0.0.1:3000。但是现在当我尝试使用 facebook 进行身份验证时,我收到了这个错误:

OpenSSL::SSL::SSLError

SSL_connect 返回=1 errno=0 state=SSLv3 读取服务器证书B: 证书验证失败

我该如何解决?我解决了将 OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE 放入 development.rb

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 omniauth facebook-oauth


    【解决方案1】:

    当您的服务器在 http 协议上运行时会出现该错误。需要在your_project/script/rails APP_PATH之前添加这段代码

    require 'rubygems'
    require 'rails/commands/server'
    require 'rack'
    require 'webrick'
    require 'webrick/https'
    
    module Rails
        class Server < ::Rack::Server
            def default_options
                super.merge({
                    :Port => 3000,
                    :environment => (ENV['RAILS_ENV'] || "development").dup,
                    :daemonize => false,
                    :debugger => false,
                    :pid => File.expand_path("tmp/pids/server.pid"),
                    :config => File.expand_path("config.ru"),
                    :SSLEnable => true,
                    :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
                    :SSLPrivateKey => OpenSSL::PKey::RSA.new(
                           File.open("/path_to_your/privatekey.pem").read),
                    :SSLCertificate => OpenSSL::X509::Certificate.new(
                           File.open("/path_to_your/servercert.crt").read),
                    :SSLCertName => [["CN", WEBrick::Utils::getservername]]
                })
            end
        end
    end
    

    要生成自签名证书,请阅读本教程 http://www.akadia.com/services/ssh_test_certificate.html(步骤 1 到 4)或本 www.tc.umn.edu/~brams006/selfsign.html

    更新您的 rails 脚本后,将 url 从 http://127.0.0.1:3000 更改为 https://127.0.0.1:3000

    【讨论】:

    • 非常感谢!!我更正了它,将 OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE 放在 development.rb 中的 development.rb 中,但我认为创建 ssl 安全连接会更好。
    【解决方案2】:

    我在开发 Twitter 时经常遇到这个问题。

    问题可能是您应用设置中的回调网址。尝试将其设置为:

    http://127.0.0.1
    

    然后再试一次。如果 http://localhost:3000 不起作用,请从 http://127.0.0.1:3000 尝试

    Facebook 的问题也很可能是应用设置中的回调 URL。对于 Facebook,我的 site url 设置为:http://localhost:3000/

    【讨论】:

    • 感谢 twitter 我更正了它,但 facebook 没有。在 FAcebbok appa 选项中,我必须输入 localhost:3000 ??
    • 我过去在使用 Webbrick 时也遇到过问题。我不确定这是不是这里的答案,只是买家要小心。我在 Gemfile 中切换到瘦,gem 'thin',然后是 rails -s thin。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 2015-12-25
    • 2022-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-13
    相关资源
    最近更新 更多