Commit 60b480fe authored by James Edwards-Jones's avatar James Edwards-Jones

OmniauthInitializer refactoring

parent 97cf5d73
...@@ -4,18 +4,19 @@ module Gitlab ...@@ -4,18 +4,19 @@ module Gitlab
@devise_config = devise_config @devise_config = devise_config
end end
def config
@devise_config
end
def execute(providers) def execute(providers)
initialize_providers(providers) providers.each do |provider|
add_provider(provider['name'].to_sym, *arguments_for(provider))
end
end end
private private
def initialize_providers(providers) def add_provider(*args)
providers.each do |provider| @devise_config.omniauth(*args)
end
def arguments_for(provider)
provider_arguments = [] provider_arguments = []
%w[app_id app_secret].each do |argument| %w[app_id app_secret].each do |argument|
...@@ -27,28 +28,25 @@ module Gitlab ...@@ -27,28 +28,25 @@ module Gitlab
# An Array from the configuration will be expanded. # An Array from the configuration will be expanded.
provider_arguments.concat provider['args'] provider_arguments.concat provider['args']
when Hash when Hash
set_provider_specific_defaults(provider) hash_arguments = provider['args'].merge(provider_defaults(provider))
# A Hash from the configuration will be passed as is. # A Hash from the configuration will be passed as is.
provider_arguments << provider['args'].symbolize_keys provider_arguments << hash_arguments.symbolize_keys
end end
config.omniauth provider['name'].to_sym, *provider_arguments provider_arguments
end
end
def set_provider_specific_defaults(provider)
# Add procs for handling SLO
if provider['name'] == 'cas3'
provider['args'][:on_single_sign_out] = cas3_signout_handler
end end
if provider['name'] == 'authentiq' def provider_defaults(provider)
provider['args'][:remote_sign_out_handler] = authentiq_signout_handler case provider['name']
end when 'cas3'
{ on_single_sign_out: cas3_signout_handler }
if provider['name'] == 'shibboleth' when 'authentiq'
provider['args'][:fail_with_empty_uid] = true { remote_sign_out_handler: authentiq_signout_handler }
when 'shibboleth'
{ fail_with_empty_uid: true }
else
{}
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment