facebook 的omniauth 无法用于生产

发布于 2024-11-06 12:52:51 字数 192 浏览 1 评论 0原文

我正在我的rails应用程序中使用omniauth,我已经使用facebook和twitter按钮进行签名,当我将facebook放入网站url归档localhost:3000时,一切正常,但是当我将网站上传到heroku时并将站点 URL 更改为 sitename.heroku.com,twiiter 登录按钮可以工作,但 facebook 按钮不起作用......

i'm working with omniauth in my rails app, i have sign with facebook and twitter button, when i'm putting in facebook in the site url filed localhost:3000, all is working, but when i'm uploading the site to heroku and changing in the site url to sitename.heroku.com, the twiiter login button working but the facebook button don't working...

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

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

发布评论

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

评论(2

一笑百媚生 2024-11-13 12:52:51

您可能需要向我们提供更多信息(Facebook 按钮不起作用是什么意思?您是否收到错误消息?如果是这样,是什么?您的日志说了什么?)

但是,这很可能是您的问题:在heroku 上使用omniauth Facebook 身份验证存在一个已知问题。您需要在 config/initializers/omniauth.rb 文件中添加对 SSL 证书文件的显式引用。更改您的 facebook 配置行以包含“client_options”哈希,如下所示:

provider :facebook, 'YOUR_APP_ID', 'YOUR_SECRET_KEY', 
           {:scope => 'PERMISSION_1, PERMISSION_2, PERMISSION_3...', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}

You probably need to give us more information (What do you mean the facebook button isn't working? Are you getting an error message? If so, what? What are your logs saying?)

BUT, there's a good chance this is your problem: there is a known issue using omniauth facebook authentication on heroku. You need to add an explicit reference to the SSL certificates file in the config/initializers/omniauth.rb file. Change your facebook config line to include the 'client_options' hash like so:

provider :facebook, 'YOUR_APP_ID', 'YOUR_SECRET_KEY', 
           {:scope => 'PERMISSION_1, PERMISSION_2, PERMISSION_3...', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
七色彩虹 2024-11-13 12:52:51

如果您想在本地主机上进行测试并保持生产环境正常运行,您可以:

1- 创建一个仅用于开发目的的新 Facebook 应用程序

2- 将站点 URL 字段设置为:http://localhost:3000/

3- 然后编辑您的 /config/initializers/omniauth.rb 文件以匹配以下内容:

OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do
  if Rails.env.development?
    OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
    provider :facebook, 'DEV_APP_ID', 'DEV_APP_SEVRET'
  else
    provider :facebook, 'DEPLOY_APP_ID', 'DEPLOY_APP_SECRET'
  end
end

最后重新启动 rails server,您应该能够通过新应用程序登录。

If you want to test on local host and keep your production environment working you can:

1- Create a new Facebook app only for development purposes

2- Set the Site URL field to: http://localhost:3000/

3- Then edit your /config/initializers/omniauth.rb file to match the following:

OmniAuth.config.logger = Rails.logger

Rails.application.config.middleware.use OmniAuth::Builder do
  if Rails.env.development?
    OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
    provider :facebook, 'DEV_APP_ID', 'DEV_APP_SEVRET'
  else
    provider :facebook, 'DEPLOY_APP_ID', 'DEPLOY_APP_SECRET'
  end
end

Finally relaunch rails server and you should be able to login through your new app.

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