Omniauth with facebook not working on production

I work with omniauth in my rails application, I have a facebook sign and a Twitter button, when I put facebook url filed localhost: 3000 on facebook, everything works, but when I upload the site to the hero and change the site url to sitename. heroku.com, the twitter login button works, but the facebook button doesn't work ...

+3
source share
2 answers

You probably need to provide us with additional information (what do you mean that the facebook button is not working? Are you getting an error message? If so, then what? What do your logs say?)

BUT, there is a good chance, this is your problem: there is a known problem using omniauth facebook authentication on heroku. You need to add an explicit link to the SSL certificate file in the config / initializers / omniauth.rb file. Modify your facebook configuration to include the client_options hash file as follows:

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'}}}
+9
source

If you want to test the local host and maintain a working environment, you can:

1- Create a new Facebook application for development purposes only

2- Set the site URL field: http://localhost:3000/

3- Then edit the file /config/initializers/omniauth.rbto 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, restart rails serverand you will be able to enter your new application.

+3
source

All Articles