debian-mirror-gitlab/app/helpers/auth_helper.rb

77 lines
1.8 KiB
Ruby
Raw Normal View History

2015-09-11 14:41:01 +05:30
module AuthHelper
2017-08-17 22:00:37 +05:30
PROVIDERS_WITH_ICONS = %w(twitter github gitlab bitbucket google_oauth2 facebook azure_oauth2 authentiq).freeze
2018-10-15 14:42:47 +05:30
LDAP_PROVIDER = /\Aldap/
2015-09-11 14:41:01 +05:30
def ldap_enabled?
2018-03-27 19:54:05 +05:30
Gitlab::Auth::LDAP::Config.enabled?
2015-09-11 14:41:01 +05:30
end
2016-04-02 18:10:28 +05:30
def omniauth_enabled?
Gitlab.config.omniauth.enabled
end
2015-09-11 14:41:01 +05:30
def provider_has_icon?(name)
PROVIDERS_WITH_ICONS.include?(name.to_s)
end
def auth_providers
2018-03-27 19:54:05 +05:30
Gitlab::Auth::OAuth::Provider.providers
2015-09-11 14:41:01 +05:30
end
def label_for_provider(name)
2018-03-27 19:54:05 +05:30
Gitlab::Auth::OAuth::Provider.label_for(name)
2015-09-11 14:41:01 +05:30
end
def form_based_provider?(name)
2018-10-15 14:42:47 +05:30
[LDAP_PROVIDER, 'crowd'].any? { |pattern| pattern === name.to_s }
2015-09-11 14:41:01 +05:30
end
def form_based_providers
auth_providers.select { |provider| form_based_provider?(provider) }
end
2015-09-25 12:07:36 +05:30
def crowd_enabled?
auth_providers.include? :crowd
end
2015-09-11 14:41:01 +05:30
def button_based_providers
auth_providers.reject { |provider| form_based_provider?(provider) }
end
2018-10-15 14:42:47 +05:30
def providers_for_base_controller
auth_providers.reject { |provider| LDAP_PROVIDER === provider }
end
2016-06-02 11:05:42 +05:30
def enabled_button_based_providers
2018-03-17 18:26:18 +05:30
disabled_providers = Gitlab::CurrentSettings.disabled_oauth_sign_in_sources || []
2016-06-02 11:05:42 +05:30
button_based_providers.map(&:to_s) - disabled_providers
end
def button_based_providers_enabled?
enabled_button_based_providers.any?
end
2015-09-11 14:41:01 +05:30
def provider_image_tag(provider, size = 64)
label = label_for_provider(provider)
if provider_has_icon?(provider)
file_name = "#{provider.to_s.split('_').first}_#{size}.png"
2015-09-25 12:07:36 +05:30
image_tag("auth_buttons/#{file_name}", alt: label, title: "Sign in with #{label}")
2015-09-11 14:41:01 +05:30
else
label
end
end
def auth_active?(provider)
current_user.identities.exists?(provider: provider.to_s)
end
2017-08-17 22:00:37 +05:30
def unlink_allowed?(provider)
%w(saml cas3).exclude?(provider.to_s)
end
2015-09-11 14:41:01 +05:30
extend self
end