Module: AuthHelper

Extended by:
AuthHelper
Included in:
AuthHelper
Defined in:
app/helpers/auth_helper.rb

Constant Summary collapse

PROVIDERS_WITH_ICONS =
%w(twitter github gitlab bitbucket google_oauth2 facebook azure_oauth2).freeze
FORM_BASED_PROVIDERS =
[/\Aldap/, 'crowd'].freeze

Instance Method Summary collapse

Instance Method Details

#auth_active?(provider) ⇒ Boolean

Returns:

  • (Boolean)

53
54
55
# File 'app/helpers/auth_helper.rb', line 53

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

#auth_providersObject


17
18
19
# File 'app/helpers/auth_helper.rb', line 17

def auth_providers
  Gitlab::OAuth::Provider.providers
end

#button_based_providersObject


37
38
39
# File 'app/helpers/auth_helper.rb', line 37

def button_based_providers
  auth_providers.reject { |provider| form_based_provider?(provider) }
end

#crowd_enabled?Boolean

Returns:

  • (Boolean)

33
34
35
# File 'app/helpers/auth_helper.rb', line 33

def crowd_enabled?
  auth_providers.include? :crowd
end

#form_based_provider?(name) ⇒ Boolean

Returns:

  • (Boolean)

25
26
27
# File 'app/helpers/auth_helper.rb', line 25

def form_based_provider?(name)
  FORM_BASED_PROVIDERS.any? { |pattern| pattern === name.to_s }
end

#form_based_providersObject


29
30
31
# File 'app/helpers/auth_helper.rb', line 29

def form_based_providers
  auth_providers.select { |provider| form_based_provider?(provider) }
end

#label_for_provider(name) ⇒ Object


21
22
23
# File 'app/helpers/auth_helper.rb', line 21

def label_for_provider(name)
  Gitlab::OAuth::Provider.label_for(name)
end

#ldap_enabled?Boolean

Returns:

  • (Boolean)

5
6
7
# File 'app/helpers/auth_helper.rb', line 5

def ldap_enabled?
  Gitlab.config.ldap.enabled
end

#omniauth_enabled?Boolean

Returns:

  • (Boolean)

9
10
11
# File 'app/helpers/auth_helper.rb', line 9

def omniauth_enabled?
  Gitlab.config.omniauth.enabled
end

#provider_has_icon?(name) ⇒ Boolean

Returns:

  • (Boolean)

13
14
15
# File 'app/helpers/auth_helper.rb', line 13

def provider_has_icon?(name)
  PROVIDERS_WITH_ICONS.include?(name.to_s)
end

#provider_image_tag(provider, size = 64) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/auth_helper.rb', line 41

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"

    image_tag("auth_buttons/#{file_name}", alt: label, title: "Sign in with #{label}")
  else
    label
  end
end

#two_factor_grace_period_expired?Boolean

Returns:

  • (Boolean)

64
65
66
67
# File 'app/helpers/auth_helper.rb', line 64

def two_factor_grace_period_expired?
  current_user.otp_grace_period_started_at &&
    (current_user.otp_grace_period_started_at + current_application_settings.two_factor_grace_period.hours) < Time.current
end

#two_factor_skippable?Boolean

Returns:

  • (Boolean)

57
58
59
60
61
62
# File 'app/helpers/auth_helper.rb', line 57

def two_factor_skippable?
  current_application_settings.require_two_factor_authentication &&
    !current_user.two_factor_enabled &&
    current_application_settings.two_factor_grace_period &&
    !two_factor_grace_period_expired?
end