Digamos que temos a configuração do Devise:
/config/initializers/devise.rb
Devise.setup do |config|
# ...
config.omniauth :facebook, "App ID/API Key", "App Secret",
scope: 'email,user_photos,user_relationships,publish_actions',
strategy_class: OmniAuth::Strategies::Facebook
config.omniauth :twitter, "Consumer Key", "Consumer Secret",
strategy_class: OmniAuth::Strategies::Twitter
# ...
end
e queremos ler esses valores em qualquer lugar do nosso aplicativo. Por exemplo, ao criar Twitter :: Client, a solução se parece com:
auth = user.authentications.where(provider: 'twitter').first # or something like
strategy = Devise.omniauth_configs[:twitter].strategy
twitter = Twitter::Client.new(consumer_key: strategy.consumer_key,
consumer_secret: strategy.consumer_secret,
oauth_token: auth.token,
oauth_token_secret: auth.secret_token)
e para o facebook:
strategy = Devise.omniauth_configs[:facebook].strategy
strategy.client_id
strategy.client_secret