Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Create separate service to get an active user from Omniauth

Oliver Günther4b0509b197ef
diff --git a/app/contracts/authentication/omniauth_auth_hash_contract.rb b/app/contracts/authentication/omniauth_auth_hash_contract.rb
new file mode 100644
index 00000000000..8459d10f979
--- /dev/null
+++ b/app/contracts/authentication/omniauth_auth_hash_contract.rb
@@ -0,0 +1,68 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2017 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+module Authentication
+ class OmniauthAuthHashContract
+ include ActiveModel::Validations
+
+ attr_reader :auth_hash
+
+ def initialize(auth_hash)
+ @auth_hash = auth_hash
+ end
+
+ validate :validate_auth_hash
+ validate :validate_auth_hash_not_expired
+ validate :validate_authorization_callback
+
+ private
+
+ def validate_auth_hash
+ return if auth_hash&.valid?
+
+ errors.add(:base, I18n.t(:error_omniauth_invalid_auth))
+ end
+
+ def validate_auth_hash_not_expired
+ return unless auth_hash['timestamp']
+
+ if auth_hash['timestamp'] < Time.now - 30.minutes
+ errors.add(:base, I18n.t(:error_omniauth_registration_timed_out))
+ end
+ end
+
+ def validate_authorization_callback
+ return unless auth_hash&.valid?
+
+ decision = OpenProject::OmniAuth::Authorization.authorized?(auth_hash)
+ errors.add(:base, decision.message) unless decision.approve?
+ end
+ end
+end
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 1ffffe6944f..6918ea67e5f 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -320,7 +320,8 @@ class AccountController < ApplicationController
if session[:auth_source_registration]
# on-the-fly registration via omniauth or via auth source
if pending_omniauth_registration?
- register_via_omniauth(@user, session, permitted_params)
+ @user.assign_attributes permitted_params.user_register_via_omniauth
+ register_via_omniauth(session, @user.attributes)
else
register_and_login_via_authsource(@user, session, permitted_params)
end
@@ -457,10 +458,6 @@ class AccountController < ApplicationController
end
end
- def send_activation_email!(token)
- UserMailer.user_signed_up(token).deliver_later
- end
-
def pending_auth_source_registration?
session[:auth_source_registration] && !pending_omniauth_registration?
end
@@ -491,58 +488,6 @@ class AccountController < ApplicationController
render action: 'register'
end
- # Register a user depending on Setting.self_registration
- def register_user_according_to_setting(user, opts = {}, &block)
- return register_automatically(user, opts, &block) if user.invited?
-
- if Setting::SelfRegistration.by_email?
- register_by_email_activation(user, opts, &block)
- elsif Setting::SelfRegistration.automatic?
- register_automatically(user, opts, &block)
- else
- register_manually_by_administrator(user, opts, &block)
- end
- end
-
- # Register a user for email activation.
- #
- # Pass a block for behavior when a user fails to save
- def register_by_email_activation(user, _opts = {})
- token = Token::Invitation.new(user: user)
-
- if user.save and token.save
- send_activation_email! token
- flash[:notice] = I18n.t(:notice_account_register_done)
-
- redirect_to action: 'login'
- elsif block_given?
- yield
- end
- end
-
- # Automatically register a user
- #
- # Pass a block for behavior when a user fails to save
- def register_automatically(user, opts = {})
- if user_limit_reached?
- show_user_limit_activation_error!
- send_activation_limit_notification_about user
-
- return redirect_back fallback_location: signin_path
- end
-
- # Automatic activation
- user.activate
-
- if user.save
- stages = authentication_stages after_activation: true
-
- run_registration_stages stages, user, opts
- elsif block_given?
- yield
- end
- end
-
def run_registration_stages(stages, user, opts)
if stages.empty?
finish_registration! user, opts
@@ -568,24 +513,8 @@ class AccountController < ApplicationController
redirect_after_login user
end
- # Manual activation by the administrator
- #
- # Pass a block for behavior when a user fails to save
- def register_manually_by_administrator(user, _opts = {})
- if user.save
- # Sends an email to the administrators
- admins = User.admin.active
- admins.each do |admin|
- UserMailer.account_activation_requested(admin, user).deliver_later
- end
- account_pending
- elsif block_given?
- yield
- end
- end
-
def self_registration_disabled
- flash[:error] = I18n.t('account.error_self_registration_disabled')
+ flash[:error] = I18n.t(:error_self_registration_disabled)
redirect_to signin_url
end
@@ -615,13 +544,13 @@ class AccountController < ApplicationController
end
end
- def account_pending
- flash[:notice] = l(:notice_account_pending)
- # Set back_url to make sure user is not redirected to an external login page
- # when registering via the external service. This also redirects the user
- # to the original page where the user clicked on the omniauth login link for a provider.
- redirect_to action: 'login', back_url: params[:back_url]
- end
+ # def account_pending
+ #
+ # # Set back_url to make sure user is not redirected to an external login page
+ # # when registering via the external service. This also redirects the user
+ # # to the original page where the user clicked on the omniauth login link for a provider.
+ # redirect_to action: 'login', back_url: params[:back_url]
+ # end
def invited_user
if session.include? :invitation_token
diff --git a/app/controllers/concerns/accounts/omniauth_login.rb b/app/controllers/concerns/accounts/omniauth_login.rb
index d57c1076b86..af420a04ea7 100644
--- a/app/controllers/concerns/accounts/omniauth_login.rb
+++ b/app/controllers/concerns/accounts/omniauth_login.rb
@@ -37,9 +37,9 @@ module Accounts::OmniauthLogin
# disable CSRF protection since that should be covered by the omniauth strategy
# the other filters are not applicable either since OmniAuth is doing authentication
# itself
- [
- :verify_authenticity_token, :user_setup,
- :check_if_login_required, :check_session_lifetime
+ %i[
+ verify_authenticity_token user_setup
+ check_if_login_required check_session_lifetime
]
.each { |key| skip_before_action key, only: [:omniauth_login] }
@@ -47,52 +47,12 @@ module Accounts::OmniauthLogin
end
def omniauth_login
- auth_hash = request.env['omniauth.auth']
-
- Rails.logger.debug { "Returning from omniauth with hash #{auth_hash&.to_hash.inspect} Valid? #{auth_hash.valid?}" }
- return render_400 unless auth_hash.valid?
-
# Set back url to page the omniauth login link was clicked on
params[:back_url] = request.env['omniauth.origin']
- user_attributes = omniauth_hash_to_user_attributes(auth_hash)
- user =
- if session.include? :invitation_token
- tok = Token::Invitation.find_by value: session[:invitation_token]
- u = tok.user
- u.identity_url = user_attributes[:identity_url]
- tok.destroy
- session.delete :invitation_token
- u
- else
- find_or_initialize_user_with(user_attributes)
- end
-
- decision = OpenProject::OmniAuth::Authorization.authorized? auth_hash
- if decision.approve?
- authorization_successful user, auth_hash
- else
- authorization_failed user, decision.message
- end
- end
-
- def find_or_initialize_user_with(user_attributes = {})
- user = User.find_by(identity_url: user_attributes[:identity_url])
- return user unless user.nil?
-
- if Setting.oauth_allow_remapping_of_existing_users?
- # Allow to map existing users with an Omniauth source if the login already exists
- user = User.find_by(login: user_attributes[:login])
- end
-
- if user.nil?
- User.new(identity_url: user_attributes[:identity_url])
- else
- # We might want to update all the attributes from the provider, but for
- # backwards-compatibility only the identity_url is updated here
- user.update_attribute :identity_url, user_attributes[:identity_url]
- user
- end
+ # Extract auth info and perform check / login or activate user
+ auth_hash = request.env['omniauth.auth']
+ handle_omniauth_authentication(auth_hash)
end
def omniauth_failure
@@ -106,21 +66,12 @@ module Accounts::OmniauthLogin
private
- def authorization_successful(user, auth_hash)
- if user.new_record? || user.invited?
- create_user_from_omniauth user, auth_hash
- else
- if user.active?
- user.log_successful_login
- OpenProject::OmniAuth::Authorization.after_login! user, auth_hash, self
- end
- login_user_if_active(user)
- end
- end
+ def redirect_omniauth_register_modal(user, auth_hash)
+ # Store a timestamp so we can later make sure that authentication information can
+ # only be reused for a short time.
+ session_info = auth_hash.merge(omniauth: true, timestamp: Time.new)
- def authorization_failed(user, error)
- logger.warn "Authorization for User #{user.id} failed: #{error}"
- show_error error
+ onthefly_creation_failed(user, session_info)
end
def show_error(error)
@@ -128,100 +79,23 @@ module Accounts::OmniauthLogin
redirect_to action: 'login'
end
- # a user may login via omniauth and (if that user does not exist
- # in our database) will be created using this method.
- def create_user_from_omniauth(user, auth_hash)
- # Self-registration off
- return self_registration_disabled unless Setting.self_registration? || user.invited?
-
- fill_user_fields_from_omniauth user, auth_hash
-
- opts = {
- omni_auth_hash: auth_hash
- }
-
- # only enforce here so user has email filled in for the admin notification
- # about who couldn't register/activate
- return if enforce_activation_user_limit(user: user)
-
- # Create on the fly
- register_user_according_to_setting(user, opts) do
- # Allow registration form to show provider-specific title
- @omniauth_strategy = auth_hash[:provider]
-
- # Store a timestamp so we can later make sure that authentication information can
- # only be reused for a short time.
- session_info = auth_hash.merge(omniauth: true, timestamp: Time.new)
-
- onthefly_creation_failed(user, session_info)
- end
- end
-
- def register_via_omniauth(user, session, permitted_params)
- auth = session[:auth_source_registration]
- return if handle_omniauth_registration_expired(auth)
-
- fill_user_fields_from_omniauth(user, auth)
- user.update(permitted_params.user_register_via_omniauth)
-
- opts = {
- omni_auth_hash: auth
- }
- register_user_according_to_setting user, opts
+ def register_via_omniauth(session, user_attributes)
+ handle_omniauth_authentication(session[:auth_source_registration], user_params: user_attributes)
end
- def fill_user_fields_from_omniauth(user, auth)
- user.assign_attributes omniauth_hash_to_user_attributes(auth)
- user.register unless user.invited?
- user
- end
+ def handle_omniauth_authentication(auth_hash, user_params: nil)
+ call = ::Authentication::OmniauthService
+ .new(strategy: request.env['omniauth.strategy'], auth_hash: auth_hash, session: session)
+ .call(user_params)
- def omniauth_hash_to_user_attributes(auth)
- info = auth[:info]
-
- attribute_map = {
- login: info[:email],
- mail: info[:email],
- firstname: info[:first_name] || info[:name],
- lastname: info[:last_name],
- identity_url: identity_url_from_omniauth(auth)
- }
-
- # Allow strategies to override mapping
- strategy = request.env['omniauth.strategy']
- if strategy.respond_to?(:omniauth_hash_to_user_attributes)
- attribute_map.merge(strategy.omniauth_hash_to_user_attributes(auth))
+ if call.success?
+ login_user_if_active(call.result)
+ elsif call.errors[:user].any?
+ redirect_omniauth_register_modal(call.result, auth_hash)
else
- attribute_map
+ error = call.message
+ Rails.logger.error "Authorization request failed: #{error}"
+ show_error error
end
end
-
- ##
- # Allow strategies to map a value for uid instead
- # of always taking the global UID.
- # For SAML, the global UID may change with every session
- # (in case of transient nameIds)
- def identity_url_from_omniauth(auth)
- identifier = auth[:info][:uid] || auth[:uid]
- "#{auth[:provider]}:#{identifier}"
- end
-
- # if the omni auth registration happened too long ago,
- # we don't accept it anymore.
- def handle_omniauth_registration_expired(auth)
- if auth['timestamp'] < Time.now - 30.minutes
- flash[:error] = I18n.t(:error_omniauth_registration_timed_out)
- redirect_to(signin_url)
- end
- end
-
- def self.url_with_params(url, params = {})
- URI.parse(url).tap do |uri|
- query = URI.decode_www_form(uri.query || '')
- params.each do |key, value|
- query << [key, value]
- end
- uri.query = URI.encode_www_form(query) unless query.empty?
- end.to_s
- end
end
diff --git a/app/controllers/concerns/accounts/user_limits.rb b/app/controllers/concerns/accounts/user_limits.rb
index c43dbd99f11..dd76f35fb49 100644
--- a/app/controllers/concerns/accounts/user_limits.rb
+++ b/app/controllers/concerns/accounts/user_limits.rb
@@ -78,10 +78,6 @@ module Accounts::UserLimits
OpenProject::Enterprise.send_activation_limit_notification_about user
end
- def show_user_limit_activation_error!
- flash[:error] = I18n.t(:error_enterprise_activation_user_limit)
- end
-
def show_user_limit_warning!(flash_now: false)
f = flash_now ? flash.now : flash
diff --git a/app/services/authentication/omniauth_service.rb b/app/services/authentication/omniauth_service.rb
new file mode 100644
index 00000000000..7e8e3dc2460
--- /dev/null
+++ b/app/services/authentication/omniauth_service.rb
@@ -0,0 +1,215 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2017 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+module Authentication
+ class OmniauthService
+ include Contracted
+
+ attr_accessor :auth_hash,
+ :strategy,
+ :session,
+ :contract,
+ :user_attributes,
+ :identity_url,
+ :user
+
+ def initialize(strategy:, auth_hash:, session:)
+ self.strategy = strategy
+ self.auth_hash = auth_hash
+ self.session = session
+ self.contract = ::Authentication::OmniauthAuthHashContract.new(auth_hash)
+ end
+
+ def call(additional_user_params)
+ Rails.logger.debug { "Returning from omniauth with hash #{auth_hash&.to_hash.inspect} Valid? #{auth_hash&.valid?}" }
+
+ unless contract.validate
+ result = ServiceResult.new(success: false, errors: contract.errors)
+ Rails.logger.warn { "Failed to process omniauth response for #{auth_uid}: #{result.message}" }
+
+ result
+ end
+
+ # Create or update the user from omniauth
+ update_user_from_omniauth!(additional_user_params || {})
+
+ # If we have a new or invited user, we still need to register them
+ activation_call = activate_user!
+
+ # The user should be logged in now
+ build_service_result activation_call
+ end
+
+ private
+
+ ##
+ # After login flow
+ def build_service_result(call)
+ return call unless call.success? && user.active?
+
+ user.log_successful_login
+ OpenProject::OmniAuth::Authorization.after_login! user, auth_hash, self
+ ServiceResult.new(success: true, result: user)
+ end
+
+ ##
+ # After validating the omniauth hash
+ # and the authorization is successful,
+ #
+ # login the user by locating or creating it
+ def update_user_from_omniauth!(additional_user_params)
+ # Find or create the user from the auth hash
+ self.user_attributes = build_omniauth_hash_to_user_attributes.merge(additional_user_params)
+ self.identity_url = user_attributes[:identity_url]
+ self.user = lookup_or_initialize_user
+
+ # Assign or update the user with the omniauth attributes
+ update_attributes
+ end
+
+ ##
+ # Try to find or create the user
+ # in the following order:
+ #
+ # 1. Look for an active invitation token
+ # 2. Look for an existing user for the current identity_url
+ # 3. Look for an existing user that we can remap (IF remapping is allowed)
+ # 4. Try to register a new user and activate according to settings
+ def lookup_or_initialize_user
+ find_invited_user ||
+ find_existing_user ||
+ remap_existing_user ||
+ initialize_new_user
+ end
+
+ ##
+ # Return an invited user, if there is a token
+ def find_invited_user
+ return unless session.include?(:invitation_token)
+
+ tok = Token::Invitation.find_by value: session[:invitation_token]
+ return unless tok
+
+ tok.user.tap do |user|
+ user.identity_url = user_attributes[:identity_url]
+ tok.destroy
+ session.delete :invitation_token
+ end
+ end
+
+ ##
+ # Find an existing user by the identity url
+ def find_existing_user
+ User.find_by(identity_url: identity_url)
+ end
+
+ ##
+ # Allow to map existing users with an Omniauth source if the login
+ # already exists, and no existing auth source or omniauth provider is
+ # linked
+ def remap_existing_user
+ return unless Setting.oauth_allow_remapping_of_existing_users?
+
+ User.find_by(login: user_attributes[:login])
+ end
+
+ ##
+ # Create the new user and try to activate it
+ # according to settings and system limits
+ def initialize_new_user
+ User.new(identity_url: user_attributes[:identity_url])
+ end
+
+ ##
+ # Update or assign the user attributes
+ def update_attributes
+ if user.new_record? || user.invited?
+ user.assign_attributes user_attributes
+ user.register unless user.invited?
+ else
+ # Update the user, but never change the admin flag
+ user.update user_attributes.except(:admin)
+ end
+ end
+
+ def activate_user!
+ if user.new_record? || user.invited?
+ ::Users::RegisterUserService
+ .new(user)
+ .call
+ else
+ ServiceResult.new(success: true)
+ end
+ end
+
+ ##
+ # Maps the omniauth attribute hash
+ # to our internal user attributes
+ def build_omniauth_hash_to_user_attributes
+ info = auth_hash[:info]
+
+ attribute_map = {
+ login: info[:email],
+ mail: info[:email],
+ firstname: info[:first_name] || info[:name],
+ lastname: info[:last_name],
+ identity_url: identity_url_from_omniauth(auth_hash)
+ }
+
+ # Allow strategies to override mapping
+ if strategy.respond_to?(:omniauth_hash_to_user_attributes)
+ attribute_map.merge!(strategy.omniauth_hash_to_user_attributes(auth_hash))
+ end
+
+ # Remove any nil values to avoid
+ # overriding existing attributes
+ attribute_map.compact!
+
+ Rails.logger.debug { "Mapped auth_hash user attributes #{attribute_map.inspect}" }
+ attribute_map
+ end
+
+ ##
+ # Allow strategies to map a value for uid instead
+ # of always taking the global UID.
+ # For SAML, the global UID may change with every session
+ # (in case of transient nameIds)
+ def identity_url_from_omniauth(auth)
+ identifier = auth[:info][:uid] || auth[:uid]
+ "#{auth[:provider]}:#{identifier}"
+ end
+
+ ##
+ # Try to provide some context of the auth_hash in case of errors
+ def auth_uid
+ auth_hash.try(:[], :uid) || 'unknown'
+ end
+ end
+end
diff --git a/app/services/users/register_user_service.rb b/app/services/users/register_user_service.rb
new file mode 100644
index 00000000000..bbc20714b0e
--- /dev/null
+++ b/app/services/users/register_user_service.rb
@@ -0,0 +1,139 @@
+#-- encoding: UTF-8
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2017 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+module Users
+ class RegisterUserService
+ attr_reader :user
+
+ def initialize(user)
+ @user = user
+ end
+
+ def call
+ %i[
+ register_invited_user
+ ensure_registration_allowed!
+ ensure_user_limit_not_reached!
+ register_by_email_activation
+ register_automatically
+ register_manually
+ fail_activation
+ ].each do |m|
+ result = send(m)
+ return result if result.is_a?(ServiceResult)
+ end
+ rescue StandardError => e
+ Rails.logger.error { "User #{user.login} failed to activate #{e}." }
+ ServiceResult.new(success: false, message: e.message)
+ end
+
+ private
+
+ ##
+ # Check whether the system allows registration
+ # for non-invited users
+ def ensure_registration_allowed!
+ if Setting::SelfRegistration.disabled?
+ raise I18n.t('account.error_self_registration_disabled')
+ end
+ end
+
+ ##
+ # Ensure the user limit is not reached
+ def ensure_user_limit_not_reached!
+ if OpenProject::Enterprise.user_limit_reached?
+ OpenProject::Enterprise.send_activation_limit_notification_about user
+ raise I18n.t(:error_enterprise_activation_user_limit)
+ end
+ end
+
+ ##
+ # Try to register an invited user
+ # bypassing regular restrictions
+ def register_invited_user
+ return unless user.invited?
+
+ register_automatically
+ end
+
+ def register_by_email_activation
+ return unless Setting::SelfRegistration.by_email?
+
+ with_saved_user_result(success_message: I18n.t(:notice_account_register_done)) do
+ token = Token::Invitation.create!(user: user)
+ UserMailer.user_signed_up(token).deliver_later
+ Rails.logger.info { "Scheduled email activation mail for #{user.login}" }
+ end
+ end
+
+ # Automatically register a user
+ #
+ # Pass a block for behavior when a user fails to save
+ def register_automatically
+ return unless Setting::SelfRegistration.automatic?
+
+ with_saved_user_result do
+ Rails.logger.info { "User #{user.login} was successfully activated." }
+ end
+ end
+
+ def register_manually
+ user.save!
+
+ # Sends an email to the administrators
+ admins = User.admin.active
+ admins.each do |admin|
+ UserMailer.account_activation_requested(admin, user).deliver_later
+ end
+
+ with_saved_user_result(success_message: I18n.t(:notice_account_pending)) do
+ Rails.logger.info { "User #{user.login} was successfully created and is pending admin activation." }
+ end
+ end
+
+ def fail_activation
+ Rails.logger.error { "User #{user.login} could not be activated, all options were exhausted." }
+ raise I18n.t(:notice_activation_failed)
+ end
+
+ ##
+ # Try to save result, return it in case of errors
+ # and add a user error to make sure we can render the account registration form
+ def with_saved_user_result(success_message: I18n.t(:notice_account_activated))
+ if user.save
+ yield if block_given?
+ return ServiceResult.new(success: true, result: user, message: success_message)
+ end
+
+ ServiceResult.new(success: false, result: user).tap do |result|
+ result.errors.add(:user, :invalid)
+ end
+ end
+ end
+end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 843f9fa6820..0d58db5c0b4 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1141,6 +1141,7 @@ en:
error_no_default_work_package_status: "No default work package status is defined. Please check your configuration (Go to \"Administration -> Work package statuses\")."
error_no_type_in_project: "No type is associated to this project. Please check the Project settings."
error_omniauth_registration_timed_out: "The registration via an external authentication provider timed out. Please try again."
+ error_omniauth_invalid_auth: "The authentication information returned from the identity provider was invalid. Please contact your adminstrator for further help."
error_scm_command_failed: "An error occurred when trying to access the repository: %{value}"
error_scm_not_found: "The entry or revision was not found in the repository."
error_unable_delete_status: "The work package status cannot be deleted since it is used by at least one work package."
diff --git a/modules/auth_saml/lib/open_project/auth_saml/engine.rb b/modules/auth_saml/lib/open_project/auth_saml/engine.rb
index ba3069486ea..72f3f5b7d43 100644
--- a/modules/auth_saml/lib/open_project/auth_saml/engine.rb
+++ b/modules/auth_saml/lib/open_project/auth_saml/engine.rb
@@ -75,7 +75,7 @@ module OpenProject
strategy :saml do
OpenProject::AuthSaml.configuration.values.map do |h|
# Remember saml session values when logging in user
- h[:retain_from_session] = %w[saml_uid saml_session_index]
+ h[:retain_from_session] = %w[saml_uid saml_session_index saml_transaction_id]
h[:single_sign_out_callback] = Proc.new do |prev_session, _prev_user|
next unless h[:idp_slo_target_url]