From 042622cb01ad792b58476e155dd6bcf72d02a036 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 10 Jul 2017 11:11:10 -0400 Subject: [PATCH] fix production LDAP routing --- config/initializers/omniauth.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index b08cd1ea..6f4af204 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -25,3 +25,30 @@ end OmniAuth.config.on_failure = Proc.new { |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' + rel_root = '' if Rails.env == 'development' + + @callback_path = nil + path = options[:callback_path] + options[:callback_path] = "#{rel_root}/auth/ldap/callback" + form = super + options[:callback_path] = path + form + end +end + +module OmniAuth + module Strategies + class LDAP + prepend OmniAuthLDAPExt + end + end +end