Rails omniauth-twitter dynamic client id and secret

282 views Asked by At

for omniuath-twiiter i want to set multiple developers accounts But i am not able set enviroment variable at run time

Please Help

1

There are 1 answers

1
Zoker On

you can add the id and secret into config file like config.yml and ignore the config.yml in .gitignore , track a config.example.yml file to make every developers easy to use.

omniauth:
   providers:
       - { name: 'google_oauth2', app_id: 'YOUR_APP_ID',
           app_secret: 'YOUR_APP_SECRET',
           args: { access_type: 'offline', approval_prompt: '' } }
       - { name: 'twitter', app_id: 'YOUR_APP_ID',
           app_secret: 'YOUR_APP_SECRET'}

and config omniuath-twiiter just use params in config.yml via Settingslogic gem , it is easy to use, put the code into a file in config/initializers/

class Settings < Settingslogic
  source "#{Rails.root}/config/config.yml
  namespace Rails.env
end

module Foobar
  def self.config
    Settings
  end
end

then config the omniauth like below:

Foobar.config.omniauth.providers.each do |provider|
   config.omniauth provider['name'].to_sym, provider['app_id'], provider['app_secret'], provider['args']
end

that's it