2015-09-11 14:41:01 +05:30
|
|
|
module Gitlab
|
|
|
|
module OAuth
|
|
|
|
class Provider
|
2015-11-26 14:37:03 +05:30
|
|
|
LABELS = {
|
|
|
|
"github" => "GitHub",
|
|
|
|
"gitlab" => "GitLab.com",
|
|
|
|
"google_oauth2" => "Google"
|
|
|
|
}.freeze
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
def self.providers
|
|
|
|
Devise.omniauth_providers
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.enabled?(name)
|
|
|
|
providers.include?(name.to_sym)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.ldap_provider?(name)
|
|
|
|
name.to_s.start_with?('ldap')
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def self.sync_profile_from_provider?(provider)
|
|
|
|
return true if ldap_provider?(provider)
|
|
|
|
|
|
|
|
providers = Gitlab.config.omniauth.sync_profile_from_provider
|
|
|
|
|
|
|
|
if providers.is_a?(Array)
|
|
|
|
providers.include?(provider)
|
|
|
|
else
|
|
|
|
providers
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
def self.config_for(name)
|
|
|
|
name = name.to_s
|
|
|
|
if ldap_provider?(name)
|
2017-09-10 17:25:29 +05:30
|
|
|
if Gitlab::LDAP::Config.valid_provider?(name)
|
|
|
|
Gitlab::LDAP::Config.new(name).options
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
else
|
|
|
|
Gitlab.config.omniauth.providers.find { |provider| provider.name == name }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.label_for(name)
|
2015-11-26 14:37:03 +05:30
|
|
|
name = name.to_s
|
2015-09-11 14:41:01 +05:30
|
|
|
config = config_for(name)
|
2015-11-26 14:37:03 +05:30
|
|
|
(config && config['label']) || LABELS[name] || name.titleize
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|