oauth_helper.rb 873 Bytes
Newer Older
1 2
module OauthHelper
  def ldap_enabled?
3
    Gitlab.config.ldap.enabled
4 5 6
  end

  def default_providers
Douwe Maan's avatar
Douwe Maan committed
7
    [:twitter, :github, :gitlab, :bitbucket, :google_oauth2, :ldap]
8 9 10 11 12
  end

  def enabled_oauth_providers
    Devise.omniauth_providers
  end
13 14 15

  def enabled_social_providers
    enabled_oauth_providers.select do |name|
16
      [:saml, :twitter, :gitlab, :github, :bitbucket, :google_oauth2].include?(name.to_sym)
17 18
    end
  end
Valery Sizov's avatar
Valery Sizov committed
19 20 21 22

  def additional_providers
    enabled_oauth_providers.reject{|provider| provider.to_s.starts_with?('ldap')}
  end
23 24 25 26 27 28 29 30 31 32

  def oauth_image_tag(provider, size = 64)
    file_name = "#{provider.to_s.split('_').first}_#{size}.png"
    image_tag(image_path("authbuttons/#{file_name}"), alt: "Sign in with #{provider.to_s.titleize}")
  end

  def oauth_active?(provider)
    current_user.identities.exists?(provider: provider.to_s)
  end

33
  extend self
34
end