omniauth.rb 952B

123456789101112131415161718192021222324
  1. LOADED_OMNIAUTH_STRATEGIES = {
  2. 'twitter' => defined?(OmniAuth::Strategies::Twitter),
  3. '37signals' => defined?(OmniAuth::Strategies::ThirtySevenSignals),
  4. 'github' => defined?(OmniAuth::Strategies::GitHub)
  5. }
  6. def has_oauth_configuration_for?(provider)
  7. LOADED_OMNIAUTH_STRATEGIES[provider.to_s] && ENV["#{provider.upcase}_OAUTH_KEY"].present? && ENV["#{provider.upcase}_OAUTH_SECRET"].present?
  8. end
  9. Rails.application.config.middleware.use OmniAuth::Builder do
  10. if has_oauth_configuration_for?('twitter')
  11. provider 'twitter', ENV['TWITTER_OAUTH_KEY'], ENV['TWITTER_OAUTH_SECRET'], authorize_params: {force_login: 'true', use_authorize: 'true'}
  12. end
  13. if has_oauth_configuration_for?('37signals')
  14. provider '37signals', ENV['THIRTY_SEVEN_SIGNALS_OAUTH_KEY'], ENV['THIRTY_SEVEN_SIGNALS_OAUTH_SECRET']
  15. end
  16. if has_oauth_configuration_for?('github')
  17. provider 'github', ENV['GITHUB_OAUTH_KEY'], ENV['GITHUB_OAUTH_SECRET']
  18. end
  19. end