2018-06-26 10:29:46 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-09 13:54:15 -04:00
|
|
|
require 'office365'
|
|
|
|
|
2018-05-11 15:57:31 -04:00
|
|
|
# List of supported Omniauth providers.
|
2019-04-05 14:54:36 -04:00
|
|
|
Rails.application.config.providers = []
|
2018-05-07 16:06:01 -04:00
|
|
|
|
|
|
|
# Set which providers are configured.
|
2019-04-05 14:54:36 -04:00
|
|
|
Rails.application.config.omniauth_bn_launcher = Rails.configuration.loadbalanced_configuration
|
2018-07-20 14:20:14 -04:00
|
|
|
Rails.application.config.omniauth_ldap = ENV['LDAP_SERVER'].present? && ENV['LDAP_UID'].present? &&
|
|
|
|
ENV['LDAP_BASE'].present? && ENV['LDAP_BIND_DN'].present? &&
|
|
|
|
ENV['LDAP_PASSWORD'].present?
|
2019-04-05 14:54:36 -04:00
|
|
|
Rails.application.config.omniauth_twitter = ENV['TWITTER_ID'].present? && ENV['TWITTER_SECRET'].present?
|
|
|
|
Rails.application.config.omniauth_google = ENV['GOOGLE_OAUTH2_ID'].present? && ENV['GOOGLE_OAUTH2_SECRET'].present?
|
2019-07-09 13:54:15 -04:00
|
|
|
Rails.application.config.omniauth_office365 = ENV['OFFICE365_KEY'].present? &&
|
|
|
|
ENV['OFFICE365_SECRET'].present?
|
2018-07-09 13:17:23 -04:00
|
|
|
|
|
|
|
SETUP_PROC = lambda do |env|
|
2019-07-09 13:54:15 -04:00
|
|
|
SessionsController.helpers.omniauth_options env
|
2018-07-09 13:17:23 -04:00
|
|
|
end
|
|
|
|
|
2018-05-07 16:06:01 -04:00
|
|
|
# Setup the Omniauth middleware.
|
|
|
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
2018-07-09 13:17:23 -04:00
|
|
|
if Rails.configuration.omniauth_bn_launcher
|
2018-07-10 15:05:50 -04:00
|
|
|
provider :bn_launcher, client_id: ENV['CLIENT_ID'],
|
2018-07-20 14:20:14 -04:00
|
|
|
client_secret: ENV['CLIENT_SECRET'],
|
2019-07-09 16:46:25 -04:00
|
|
|
client_options: { site: ENV['BN_LAUNCHER_URI'] || ENV['BN_LAUNCHER_REDIRECT_URI'] },
|
2018-07-20 14:20:14 -04:00
|
|
|
setup: SETUP_PROC
|
2019-04-05 14:54:36 -04:00
|
|
|
else
|
2019-07-10 11:26:43 -04:00
|
|
|
Rails.application.config.providers << :ldap if Rails.configuration.omniauth_ldap
|
|
|
|
|
2019-04-05 14:54:36 -04:00
|
|
|
if Rails.configuration.omniauth_twitter
|
|
|
|
Rails.application.config.providers << :twitter
|
2018-05-07 16:06:01 -04:00
|
|
|
|
2019-04-05 14:54:36 -04:00
|
|
|
provider :twitter, ENV['TWITTER_ID'], ENV['TWITTER_SECRET']
|
|
|
|
end
|
|
|
|
if Rails.configuration.omniauth_google
|
|
|
|
Rails.application.config.providers << :google
|
2018-07-20 14:20:14 -04:00
|
|
|
|
2019-04-05 14:54:36 -04:00
|
|
|
provider :google_oauth2, ENV['GOOGLE_OAUTH2_ID'], ENV['GOOGLE_OAUTH2_SECRET'],
|
|
|
|
scope: %w(profile email),
|
|
|
|
access_type: 'online',
|
|
|
|
name: 'google',
|
|
|
|
setup: SETUP_PROC
|
|
|
|
end
|
2019-07-09 13:54:15 -04:00
|
|
|
if Rails.configuration.omniauth_office365
|
|
|
|
Rails.application.config.providers << :office365
|
2018-10-16 12:58:06 -04:00
|
|
|
|
2019-07-09 13:54:15 -04:00
|
|
|
provider :office365, ENV['OFFICE365_KEY'], ENV['OFFICE365_SECRET'],
|
|
|
|
setup: SETUP_PROC
|
2019-04-05 14:54:36 -04:00
|
|
|
end
|
|
|
|
end
|
2018-06-26 10:29:46 -04:00
|
|
|
end
|
2018-07-20 14:20:14 -04:00
|
|
|
|
|
|
|
# Redirect back to login in development mode.
|
|
|
|
OmniAuth.config.on_failure = proc { |env|
|
|
|
|
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
|
|
|
|
}
|