provider.rb 880 字节
Newer Older
1 2 3
module Gitlab
  module OAuth
    class Provider
D
Douwe Maan 已提交
4 5 6 7 8 9
      LABELS = {
        "github"         => "GitHub",
        "gitlab"         => "GitLab.com",
        "google_oauth2"  => "Google"
      }.freeze

10 11 12
      def self.providers
        Devise.omniauth_providers
      end
13

14 15 16
      def self.enabled?(name)
        providers.include?(name.to_sym)
      end
17

18 19 20 21 22 23 24 25 26 27
      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 }
28
        end
29
      end
30

31
      def self.label_for(name)
D
Douwe Maan 已提交
32
        name = name.to_s
33
        config = config_for(name)
D
Douwe Maan 已提交
34
        (config && config['label']) || LABELS[name] || name.titleize
35 36 37 38
      end
    end
  end
end