简体   繁体   中英

omniauth with facebook not working on production

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM