开发者

omniauth with facebook not working on production

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 si开发者_Python百科te 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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜