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

Better option mapping

Oliver Günther6ac6af4a4b69
diff --git a/modules/openid_connect/app/contracts/openid_connect/providers/base_contract.rb b/modules/openid_connect/app/contracts/openid_connect/providers/base_contract.rb
index 8c7df80628a..e61b68fd0d4 100644
--- a/modules/openid_connect/app/contracts/openid_connect/providers/base_contract.rb
+++ b/modules/openid_connect/app/contracts/openid_connect/providers/base_contract.rb
@@ -60,7 +60,6 @@ module OpenIDConnect
url: { allow_blank: true, allow_nil: true, schemes: %w[http https] },
if: -> { model.post_logout_redirect_uri_changed? }
-
OpenIDConnect::Provider::MAPPABLE_ATTRIBUTES.each do |attr|
attribute :"mapping_#{attr}"
end
diff --git a/modules/openid_connect/app/services/openid_connect/configuration_mapper.rb b/modules/openid_connect/app/services/openid_connect/configuration_mapper.rb
index 546916d048b..5ee45847c19 100644
--- a/modules/openid_connect/app/services/openid_connect/configuration_mapper.rb
+++ b/modules/openid_connect/app/services/openid_connect/configuration_mapper.rb
@@ -35,7 +35,7 @@ module OpenIDConnect
end
def call! # rubocop:disable Metrics/AbcSize
- options = mapped_options(configuration.deep_stringify_keys)
+ options = configuration.deep_stringify_keys
{
"slug" => options["name"],
@@ -57,7 +57,12 @@ module OpenIDConnect
"token_endpoint" => extract_url(options, "token_endpoint"),
"userinfo_endpoint" => extract_url(options, "userinfo_endpoint"),
"end_session_endpoint" => extract_url(options, "end_session_endpoint"),
- "jwks_uri" => extract_url(options, "jwks_uri")
+ "jwks_uri" => extract_url(options, "jwks_uri"),
+ "mapping_login" => options.dig("attribute_map", "login"),
+ "mapping_mail" => options.dig("attribute_map", "email"),
+ "mapping_firstname" => options.dig("attribute_map", "first_name"),
+ "mapping_lastname" => options.dig("attribute_map", "last_name"),
+ "mapping_admin" => options.dig("attribute_map", "admin")
}.compact
end
@@ -102,21 +107,5 @@ module OpenIDConnect
scheme: options["scheme"] || "https"
).to_s
end
-
- def mapped_options(options)
- extract_mapping(options)
-
- options.compact
- end
-
- def extract_mapping(options)
- return unless options["attribute_map"]
-
- options["mapping_login"] = options["attribute_map"]["login"]
- options["mapping_mail"] = options["attribute_map"]["email"]
- options["mapping_firstname"] = options["attribute_map"]["first_name"]
- options["mapping_lastname"] = options["attribute_map"]["last_name"]
- options["mapping_admin"] = options["attribute_map"]["admin"]
- end
end
end