Commit 5491f6fb authored by Alex Lossent's avatar Alex Lossent

Add an option to automatically sign-in with an Omniauth provider without...

Add an option to automatically sign-in with an Omniauth provider without showing the GitLab sign-in page

This is useful when integrating with existing SSO environments and we want to use a single Omniauth provider for
all user authentication.
parent a3b60982
......@@ -34,6 +34,7 @@ v 7.12.0 (unreleased)
- You can not remove user if he/she is an only owner of group
- User should be able to leave group. If not - show him proper message
- User has ability to leave project
- Add an option to automatically sign-in with an Omniauth provider
v 7.11.4
- Fix missing bullets when creating lists
......@@ -2,6 +2,7 @@ class SessionsController < Devise::SessionsController
include AuthenticatesWithTwoFactor
prepend_before_action :authenticate_with_two_factor, only: [:create]
before_action :auto_sign_in_with_provider, only: [:new]
def new
redirect_path =
......@@ -75,6 +76,21 @@ def authenticate_with_two_factor
def auto_sign_in_with_provider
provider = Gitlab.config.omniauth.auto_sign_in_with_provider
return unless provider.present?
# Auto sign in with an Omniauth provider only if the standard "you need to sign-in" alert is
# registered or no alert at all. In case of another alert (such as a blocked user), it is safer
# to do nothing to prevent redirection loops with certain Omniauth providers.
return unless flash[:alert].blank? || flash[:alert] == I18n.t('devise.failure.unauthenticated')
# Prevent alert from popping up on the first page shown after authentication.
flash[:alert] = nil
redirect_to omniauth_authorize_path(:user, provider.to_sym)
def valid_otp_attempt?(user)
user.valid_otp?(user_params[:otp_attempt]) ||
......@@ -182,6 +182,10 @@ production: &base
# Allow login via Twitter, Google, etc. using OmniAuth providers
enabled: false
# Uncomment this to automatically sign in with a specific omniauth provider's without
# showing GitLab's sign-in page (default: show the GitLab sign-in page)
# auto_sign_in_with_provider: saml
# This allows users to login without having a user account first (default: false).
# User accounts will be created automatically when authentication was successful.
......@@ -87,6 +87,8 @@ def verify_constant(modul, current, default)
Settings['omniauth'] ||={})
Settings.omniauth['enabled'] = false if Settings.omniauth['enabled'].nil?
Settings.omniauth['auto_sign_in_with_provider'] = false if Settings.omniauth['auto_sign_in_with_provider'].nil?
Settings.omniauth['providers'] ||= []
Settings['issues_tracker'] ||= {}
......@@ -12,6 +12,8 @@ module OmniAuth::Strategies
OmniAuth.config.allowed_request_methods = [:post]
#In case of auto sign-in, the GET method is used (users don't get to click on a button)
OmniAuth.config.allowed_request_methods << :get if Gitlab.config.omniauth.auto_sign_in_with_provider.present?
OmniAuth.config.before_request_phase do |env|
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment