1
0

omniauth.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. OMNIAUTH_PROVIDERS = {}.tap { |providers|
  2. if defined?(OmniAuth::Strategies::Twitter) &&
  3. (key = ENV["TWITTER_OAUTH_KEY"]).present? &&
  4. (secret = ENV["TWITTER_OAUTH_SECRET"]).present?
  5. providers['twitter'] = {
  6. omniauth_params: [key, secret, authorize_params: {force_login: 'true', use_authorize: 'true'}]
  7. }
  8. end
  9. if defined?(OmniAuth::Strategies::ThirtySevenSignals) &&
  10. (key = ENV["THIRTY_SEVEN_SIGNALS_OAUTH_KEY"]).present? &&
  11. (secret = ENV["THIRTY_SEVEN_SIGNALS_OAUTH_SECRET"]).present?
  12. providers['37signals'] = {
  13. omniauth_params: [key, secret]
  14. }
  15. end
  16. if defined?(OmniAuth::Strategies::GitHub) &&
  17. (key = ENV["GITHUB_OAUTH_KEY"]).present? &&
  18. (secret = ENV["GITHUB_OAUTH_SECRET"]).present?
  19. providers['github'] = {
  20. omniauth_params: [key, secret]
  21. }
  22. end
  23. }
  24. def has_oauth_configuration_for?(provider)
  25. OMNIAUTH_PROVIDERS.key?(provider.to_s)
  26. end
  27. Rails.application.config.middleware.use OmniAuth::Builder do
  28. OMNIAUTH_PROVIDERS.each { |name, config|
  29. provider name, *config[:omniauth_params]
  30. }
  31. end