Class: OmniauthCallbacksController

Inherits:
Devise::OmniauthCallbacksController
  • Object
show all
Includes:
AcceptsPendingInvitations, AuthHelper, AuthenticatesWithTwoFactorForAdminMode, Devise::Controllers::Rememberable, InitializesCurrentUserMode, KnownSignIn, Onboarding::Redirectable
Defined in:
app/controllers/omniauth_callbacks_controller.rb

Direct Known Subclasses

Ldap::OmniauthCallbacksController

Constant Summary

Constants included from KnownSignIn

KnownSignIn::KNOWN_SIGN_IN_COOKIE, KnownSignIn::KNOWN_SIGN_IN_COOKIE_EXPIRY

Constants included from CookiesHelper

CookiesHelper::COOKIE_TYPE_ENCRYPTED, CookiesHelper::COOKIE_TYPE_PERMANENT

Constants included from AuthHelper

AuthHelper::LDAP_PROVIDER, AuthHelper::POPULAR_PROVIDERS, AuthHelper::PROVIDERS_WITH_ICONS

Instance Method Summary collapse

Methods included from AcceptsPendingInvitations

#accept_pending_invitations, #after_pending_invitations_hook

Methods included from CookiesHelper

#set_secure_cookie

Methods included from InitializesCurrentUserMode

#current_user_mode

Methods included from AuthHelper

#allow_admin_mode_password_authentication_for_web?, #any_form_based_providers_enabled?, #auth_active?, #auth_app_owner_text, #auth_providers, #auth_strategy_class, #button_based_providers, #button_based_providers_enabled?, #crowd_enabled?, #display_providers_on_profile?, #enabled_button_based_providers, #form_based_auth_provider_has_active_class?, #form_based_provider?, #form_based_provider_priority, #form_based_provider_with_highest_priority, #form_based_providers, #form_enabled_for_sign_in?, #google_tag_manager_enabled?, #google_tag_manager_id, #icon_for_provider, #label_for_provider, #ldap_enabled?, #ldap_sign_in_enabled?, #link_provider_allowed?, #omniauth_enabled?, #popular_enabled_button_based_providers, #provider_has_builtin_icon?, #provider_has_custom_icon?, #provider_has_icon?, #provider_image_tag, #providers_for_base_controller, #qa_selector_for_provider, #saml_providers, #unlink_provider_allowed?

Methods included from AuthenticatesWithTwoFactorForAdminMode

#admin_mode_authenticate_with_two_factor, #admin_mode_authenticate_with_two_factor_via_otp, #admin_mode_authenticate_with_two_factor_via_webauthn, #admin_mode_prompt_for_two_factor

Instance Method Details

#atlassian_oauth2Object



83
84
85
# File 'app/controllers/omniauth_callbacks_controller.rb', line 83

def atlassian_oauth2
  omniauth_flow(Gitlab::Auth::Atlassian)
end

#auth0Object



67
68
69
70
71
72
73
# File 'app/controllers/omniauth_callbacks_controller.rb', line 67

def auth0
  if oauth['uid'].blank?
    
  else
    handle_omniauth
  end
end

#failureObject

Extend the standard implementation to also increment the number of failed sign in attempts



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/omniauth_callbacks_controller.rb', line 37

def failure
  (failed_strategy.name, 'failed')

  if params[:username].present? && AuthHelper.form_based_provider?(failed_strategy.name)
    user = User.(params[:username])

    user&.increment_failed_attempts!
    (params[:username], failed_strategy.name)
  end

  super
end

#failure_messageObject

Extend the standard message generation to accept our custom exception



51
52
53
54
55
56
57
58
59
# File 'app/controllers/omniauth_callbacks_controller.rb', line 51

def failure_message
  exception = request.env["omniauth.error"]
  error = exception.error_reason if exception.respond_to?(:error_reason)
  error ||= exception.error        if exception.respond_to?(:error)
  error ||= exception.message      if exception.respond_to?(:message)
  error ||= request.env["omniauth.error.type"].to_s

  error.to_s.humanize if error
end

#handle_omniauthObject



18
19
20
21
22
23
24
# File 'app/controllers/omniauth_callbacks_controller.rb', line 18

def handle_omniauth
  if ::AuthHelper.saml_providers.include?(oauth['provider'].to_sym)
    saml
  else
    omniauth_flow(Gitlab::Auth::OAuth)
  end
end

#openid_connectObject

overridden in EE



31
32
33
# File 'app/controllers/omniauth_callbacks_controller.rb', line 31

def openid_connect
  handle_omniauth
end

#salesforceObject



75
76
77
78
79
80
81
# File 'app/controllers/omniauth_callbacks_controller.rb', line 75

def salesforce
  if oauth.dig('extra', 'email_verified')
    handle_omniauth
  else
    
  end
end

#samlObject



61
62
63
64
65
# File 'app/controllers/omniauth_callbacks_controller.rb', line 61

def saml
  omniauth_flow(Gitlab::Auth::Saml)
rescue Gitlab::Auth::Saml::IdentityLinker::UnverifiedRequest
  redirect_unverified_saml_initiation
end