omniauth with facebook not working on production

白昼怎懂夜的黑 提交于 2019-11-29 02:38:40

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'}}}

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!