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:
shawn-higgins1
2019-07-10 11:26:43 -04:00
committed by Jesus Federico
parent 09afd9154f
commit 523d9a38f2
14 changed files with 180 additions and 82 deletions

View File

@ -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

View File

@ -302,6 +302,7 @@ en:
google: Google
office365: Office 365
twitter: Twitter
ldap: LDAP
recaptcha:
errors:
recaptcha_unreachable: Oops, we failed to validate your reCAPTCHA response. Please try again.

View File

@ -29,6 +29,7 @@ Rails.application.routes.draw do
get '/signin', to: 'users#signin', as: :signin
get '/signup', to: 'users#new', as: :signup
post '/signup', to: 'users#create', as: :create_user
get '/ldap_signin', to: 'users#ldap_signin', as: :ldap_signin
# Redirect to terms page
match '/terms', to: 'users#terms', via: [:get, :post]
@ -88,6 +89,7 @@ Rails.application.routes.draw do
# Handles Omniauth authentication.
match '/auth/:provider/callback', to: 'sessions#omniauth', via: [:get, :post], as: :omniauth_session
get '/auth/failure', to: 'sessions#omniauth_fail'
post '/auth/ldap', to: 'sessions#ldap', as: :ldap_callback
# Room resources.
resources :rooms, only: [:create, :show, :destroy], param: :room_uid, path: '/'