From 690a12ceba542e023f95efec3f3e50f93b7c2261 Mon Sep 17 00:00:00 2001 From: Joshua Arts Date: Fri, 20 Jul 2018 16:04:50 -0400 Subject: [PATCH] add relative root to ldap callback path --- config/initializers/omniauth.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 4cfbbcd8..51b9f896 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -47,3 +47,27 @@ 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