forked from External/greenlight
GRN2-30: Add custom ldap sign in page (#619)
* Add custom ldap signin page * Remove old omniauth-ldap gem * Use new bn gems
This commit is contained in:
committed by
Jesus Federico
parent
09afd9154f
commit
523d9a38f2
@ -15,9 +15,6 @@ Rails.application.config.omniauth_google = ENV['GOOGLE_OAUTH2_ID'].present? && E
|
||||
Rails.application.config.omniauth_office365 = ENV['OFFICE365_KEY'].present? &&
|
||||
ENV['OFFICE365_SECRET'].present?
|
||||
|
||||
# If LDAP is enabled, override and disable allow_user_signup.
|
||||
Rails.application.config.allow_user_signup = false if Rails.application.config.omniauth_ldap
|
||||
|
||||
SETUP_PROC = lambda do |env|
|
||||
SessionsController.helpers.omniauth_options env
|
||||
end
|
||||
@ -29,19 +26,9 @@ Rails.application.config.middleware.use OmniAuth::Builder do
|
||||
client_secret: ENV['CLIENT_SECRET'],
|
||||
client_options: { site: ENV['BN_LAUNCHER_URI'] || ENV['BN_LAUNCHER_REDIRECT_URI'] },
|
||||
setup: SETUP_PROC
|
||||
elsif Rails.configuration.omniauth_ldap
|
||||
Rails.application.config.providers << :ldap
|
||||
|
||||
provider :ldap,
|
||||
host: ENV['LDAP_SERVER'],
|
||||
port: ENV['LDAP_PORT'] || '389',
|
||||
method: ENV['LDAP_METHOD'].blank? ? :plain : ENV['LDAP_METHOD'].to_sym,
|
||||
allow_username_or_email_login: true,
|
||||
uid: ENV['LDAP_UID'],
|
||||
base: ENV['LDAP_BASE'],
|
||||
bind_dn: ENV['LDAP_BIND_DN'],
|
||||
password: ENV['LDAP_PASSWORD']
|
||||
else
|
||||
Rails.application.config.providers << :ldap if Rails.configuration.omniauth_ldap
|
||||
|
||||
if Rails.configuration.omniauth_twitter
|
||||
Rails.application.config.providers << :twitter
|
||||
|
||||
@ -69,27 +56,3 @@ end
|
||||
OmniAuth.config.on_failure = proc { |env|
|
||||
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
|
||||
}
|
||||
|
||||
# Work around beacuse callback_url option causes
|
||||
# omniauth.auth to be nil in the authhash when
|
||||
# authenticating with LDAP.
|
||||
module OmniAuthLDAPExt
|
||||
def request_phase
|
||||
rel_root = ENV['RELATIVE_URL_ROOT'].present? ? ENV['RELATIVE_URL_ROOT'] : '/b'
|
||||
|
||||
@callback_path = nil
|
||||
path = options[:callback_path]
|
||||
options[:callback_path] = "#{rel_root if Rails.env == 'production'}/auth/ldap/callback"
|
||||
form = super
|
||||
options[:callback_path] = path
|
||||
form
|
||||
end
|
||||
end
|
||||
|
||||
module OmniAuth
|
||||
module Strategies
|
||||
class LDAP
|
||||
prepend OmniAuthLDAPExt
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user