2015-06-22 10:53:11 -04:00
|
|
|
module Gitlab
|
|
|
|
module OAuth
|
|
|
|
class Provider
|
2015-11-03 11:58:26 -05:00
|
|
|
LABELS = {
|
|
|
|
"github" => "GitHub",
|
|
|
|
"gitlab" => "GitLab.com",
|
|
|
|
"google_oauth2" => "Google"
|
|
|
|
}.freeze
|
|
|
|
|
2015-07-02 10:33:38 -04:00
|
|
|
def self.providers
|
|
|
|
Devise.omniauth_providers
|
|
|
|
end
|
2015-06-22 10:53:11 -04:00
|
|
|
|
2015-07-02 10:33:38 -04:00
|
|
|
def self.enabled?(name)
|
|
|
|
providers.include?(name.to_sym)
|
|
|
|
end
|
2015-06-22 10:53:11 -04:00
|
|
|
|
2015-07-02 10:33:38 -04:00
|
|
|
def self.ldap_provider?(name)
|
|
|
|
name.to_s.start_with?('ldap')
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.config_for(name)
|
|
|
|
name = name.to_s
|
|
|
|
if ldap_provider?(name)
|
|
|
|
Gitlab::LDAP::Config.new(name).options
|
|
|
|
else
|
|
|
|
Gitlab.config.omniauth.providers.find { |provider| provider.name == name }
|
2015-06-22 10:53:11 -04:00
|
|
|
end
|
2015-07-02 10:33:38 -04:00
|
|
|
end
|
2015-06-22 10:53:11 -04:00
|
|
|
|
2015-07-02 10:33:38 -04:00
|
|
|
def self.label_for(name)
|
2015-11-03 11:58:26 -05:00
|
|
|
name = name.to_s
|
2015-07-02 10:33:38 -04:00
|
|
|
config = config_for(name)
|
2015-11-03 11:58:26 -05:00
|
|
|
(config && config['label']) || LABELS[name] || name.titleize
|
2015-06-22 10:53:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|