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

Allow to find omniauth strategy by name

Oliver Günthere5cd25693f81
diff --git a/app/controllers/concerns/accounts/omniauth_login.rb b/app/controllers/concerns/accounts/omniauth_login.rb
index 17bb2a345e5..2edc9870583 100644
--- a/app/controllers/concerns/accounts/omniauth_login.rb
+++ b/app/controllers/concerns/accounts/omniauth_login.rb
@@ -110,6 +110,13 @@ module Accounts::OmniauthLogin
omniauth_start_url(direct_login_provider, params)
end
+ def login_provider_for(user)
+ return unless user.identity_url
+
+ provider_name = user.identity_url.split(':').first
+ ::OpenProject::Plugins::AuthPlugin.find_provider_by_name(provider_name)
+ end
+
private
def authorization_successful(user, auth_hash)
diff --git a/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb b/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb
index 5f9c5aae8ae..46caf4bfda0 100644
--- a/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb
+++ b/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb
@@ -47,7 +47,12 @@ module OpenProject::Plugins
end
def self.providers_for(strategy)
- filtered_strategies strategies[strategy_key(strategy)].map(&:call).flatten.map(&:to_hash)
+ matching = Array(strategies[strategy_key(strategy)])
+ filtered_strategies matching.map(&:call).flatten.map(&:to_hash)
+ end
+
+ def self.find_provider_by_name(provider_name)
+ providers.detect { |hash| hash[:name].to_s == provider_name.to_s }
end
def self.providers
@@ -69,6 +74,7 @@ module OpenProject::Plugins
def self.strategy_key(strategy)
return strategy if strategy.is_a? Symbol
+ return strategy.to_sym if strategy.is_a? String
name = strategy.name.demodulize
camelization = OmniAuth.config.camelizations.select do |_k, v|