QuietFoundation
QuietFoundation

Reputation: 11

Rails omniauth + Facebook works in development over http, but not in Production over HTTPS

I have a Rails 3.1 application which uses omniauth + Facebook for login auth.

omniauth (1.1.0)
  hashie (~> 1.2)
  rack
omniauth-facebook (1.2.0)
  omniauth-oauth2 (~> 1.0.0)
omniauth-oauth2 (1.0.0)
  oauth2 (~> 0.5.0)
  omniauth (~> 1.0)

When I've set up the Facebook settings to use localhost:3000/users/auth/facebook, it works great. When I deploy the code into production it doesn't work at all. The main differences are that locally, I'm only using HTTP, and in production Nginx is configured to force HTTPS (by redirecting).

initializers/devise.rb
config.omniauth :facebook, '1705xxxxxxxxx586', '173b59ba3xxxxxxxxxxxx893e2e697', :scope => 'email,user_birthday'

initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  #provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET']
  provider :facebook, '1705xxxxxxxxx586', '173b59ba3xxxxxxxxxxxx893e2e697',
        :scope => 'email,user_birthday',
        :client_options => {:ssl => {:ca_path => '/etc/nginx/certs/cacert.pem'}}
end

Has anyone run into this problem before? It appears like the key/secret is not being read in production, but that doesn't make any sense to me.

Upvotes: 1

Views: 797

Answers (1)

QuietFoundation
QuietFoundation

Reputation: 11

We traced the problem to an "extra" "?" in the nginx rewrite in its config. In case someone else has this trouble at some point in the future, nginx does exactly what you tell it to do. :)

Upvotes: 0

Related Questions