Design with omniauth - setting up a separate configuration for dev and production

I am using omniauth, with development, to enable Facebook subscription in my application.

My devise.rb file has the following line

config.omniauth :facebook, 'MY_DEV_APP_ID', 'MY_DEV_APP_SECRET' 

I have 2 facebook apps, one pointing to my live url and the other pointing to my dev url.

How to add two separate omniauth configurations to rb development file?

sort of -

if ENV['RAILS_ENV'] = "production"
    config.omniauth :facebook, 'MY_LIVE_APP_ID', 'MY_LIVE_APP_SECRET'  
else
    config.omniauth :facebook, 'MY_DEV_APP_ID', 'MY_DEV_APP_SECRET' 
end

More importantly . Should I put it in a devise.tb file or should it be split into my production.rb and devleopment.rb files? If so, how do I link in my devise.rb file?

+5
source share
1 answer

My method for this is to store them in a yaml file. I call mineconfig/api_keys.yml

defaults: &defaults
  twitter:
    api_key: "KEY"
    api_secret: "SECRET"
  facebook:
    api_key: "KEY"
    api_secret: "SECRET"

development:
  <<: *defaults

test:
  <<: *defaults

production:
  twitter:
    api_key: "KEY2"
    api_secret: "SECRET2"
  facebook:
    api_key: "KEY2"
    api_secret: "SECRET2"

devise.rb :

API_KEYS = YAML::load_file("#{Rails.root}/config/api_keys.yml")[Rails.env]
config.omniauth :facebook , API_KEYS['facebook']['api_key'], API_KEYS['facebook']['api_secret']
config.omniauth :twitter , API_KEYS['twitter']['api_key'], API_KEYS['twitter']['api_secret']

, , , API . script, , database.yml

+11

All Articles