当我尝试使用omniauth 通过 Facebook 进行身份验证时出错

发布于 2024-12-15 06:12:11 字数 871 浏览 8 评论 0原文

我关注了 Ryan Bates Omniauth Part1 Railscats http://railscasts.com/episodes/235-omniauth-第 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 未经授权的响应。我不知道如何更正它

谢谢我更正了在 Twitter URL 回调字段和 Facebook 我的网站字段中输入的 http://127.0.0.1:3000 。但现在当我尝试使用 Facebook 进行身份验证时,出现此错误:

OpenSSL::SSL::SSLError

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

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

I followed Ryan Bates Omniauth Part1 railscats http://railscasts.com/episodes/235-omniauth-part-1 . I put twitter and Facebook authentication with their secret numbers and when I try to authenticate through Facebook (auth/facebook) I get this error:

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

And when I try to authenticate through twitter (auth/twitter) I get this 401 Unauthorized response. I don't know how I can correct it

Thanks I corrected entering http://127.0.0.1:3000 in twitter URL callback field and in facebook my website field. But now when I try to authenticate with facebook I get this error:

OpenSSL::SSL::SSLError

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

How can I solve it? I solved putting OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE in development.rb

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兔小萌 2024-12-22 06:12:11

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

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

That error appears when your server runs on http protocol. You need to add this piece of code in your_project/script/rails before 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

To generate self-signed certificates read this tutorial http://www.akadia.com/services/ssh_test_certificate.html (steps 1 to 4) or this www.tc.umn.edu/~brams006/selfsign.html

After updating your rails script change the url from http://127.0.0.1:3000 to https://127.0.0.1:3000

隱形的亼 2024-12-22 06:12:11

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

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

http://127.0.0.1

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

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

I get this problem fairly often with Twitter in development.

The issue is likely your callback url in your app settings. Try setting it to:

http://127.0.0.1

And try again. If it doesn't work from http://localhost:3000 then try it from http://127.0.0.1:3000

The problem with Facebook is also likely to be the callback URL in the app settings. For Facebook, my site url setting is: http://localhost:3000/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文