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

Add mapping

Oliver Günthere857bcdaf56c
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9ac82e45a97..68e065616e0 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2374,6 +2374,7 @@ en:
label_custom_favicon: "Custom favicon"
label_custom_touch_icon: "Custom touch icon"
label_logout: "Sign out"
+ label_mapping_for: "Mapping for: %{attribute}"
label_main_menu: "Side Menu"
label_manage: "Manage"
label_manage_groups: "Manage groups"
diff --git a/modules/auth_saml/app/forms/saml/providers/mapping_form.rb b/modules/auth_saml/app/forms/saml/providers/mapping_form.rb
index fa1be96a479..518a680a774 100644
--- a/modules/auth_saml/app/forms/saml/providers/mapping_form.rb
+++ b/modules/auth_saml/app/forms/saml/providers/mapping_form.rb
@@ -32,7 +32,7 @@ module Saml
form do |f|
f.text_area(
name: :mapping_login,
- label: I18n.t("saml.providers.label_mapping_for", attribute: User.human_attribute_name(:login)),
+ label: I18n.t("label_mapping_for", attribute: User.human_attribute_name(:login)),
caption: I18n.t("saml.instructions.mapping_login"),
required: true,
disabled: provider.seeded_from_env?,
@@ -41,7 +41,7 @@ module Saml
)
f.text_area(
name: :mapping_mail,
- label: I18n.t("saml.providers.label_mapping_for", attribute: User.human_attribute_name(:mail)),
+ label: I18n.t("label_mapping_for", attribute: User.human_attribute_name(:mail)),
caption: I18n.t("saml.instructions.mapping_mail"),
required: true,
disabled: provider.seeded_from_env?,
@@ -50,7 +50,7 @@ module Saml
)
f.text_area(
name: :mapping_firstname,
- label: I18n.t("saml.providers.label_mapping_for", attribute: User.human_attribute_name(:first_name)),
+ label: I18n.t("label_mapping_for", attribute: User.human_attribute_name(:first_name)),
caption: I18n.t("saml.instructions.mapping_firstname"),
required: true,
disabled: provider.seeded_from_env?,
@@ -59,7 +59,7 @@ module Saml
)
f.text_area(
name: :mapping_lastname,
- label: I18n.t("saml.providers.label_mapping_for", attribute: User.human_attribute_name(:last_name)),
+ label: I18n.t("label_mapping_for", attribute: User.human_attribute_name(:last_name)),
caption: I18n.t("saml.instructions.mapping_lastname"),
required: true,
disabled: provider.seeded_from_env?,
@@ -68,7 +68,7 @@ module Saml
)
f.text_field(
name: :mapping_uid,
- label: I18n.t("saml.providers.label_mapping_for", attribute: I18n.t("saml.providers.label_uid")),
+ label: I18n.t("label_mapping_for", attribute: I18n.t("saml.providers.label_uid")),
caption: I18n.t("saml.instructions.mapping_uid"),
disabled: provider.seeded_from_env?,
rows: 8,
diff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.yml
index 62be3e7ff8f..00d78f16416 100644
--- a/modules/auth_saml/config/locales/en.yml
+++ b/modules/auth_saml/config/locales/en.yml
@@ -54,7 +54,7 @@ en:
label_edit: Edit SAML identity provider %{name}
label_uid: Internal user id
label_mapping: Mapping
- label_mapping_for: "Mapping for: %{attribute}"
+
label_requested_attribute_for: "Requested attribute for: %{attribute}"
no_results_table: No SAML identity providers have been defined yet.
plural: SAML identity providers
diff --git a/modules/openid_connect/app/components/openid_connect/providers/attribute_mapping_form.rb b/modules/openid_connect/app/components/openid_connect/providers/attribute_mapping_form.rb
new file mode 100644
index 00000000000..2c9717ba860
--- /dev/null
+++ b/modules/openid_connect/app/components/openid_connect/providers/attribute_mapping_form.rb
@@ -0,0 +1,48 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2024 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-2013 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 COPYRIGHT and LICENSE files for more details.
+#++
+
+module OpenIDConnect
+ module Providers
+ class AttributeMappingForm < BaseForm
+ form do |f|
+ OpenIDConnect::Provider::MAPPABLE_ATTRIBUTES.each do |attr|
+ attribute_name = User.human_attribute_name(attr == :email ? :mail : attr)
+
+ f.text_field(
+ name: "#{attr}_mapping",
+ label: I18n.t("label_mapping_for", attribute: attribute_name),
+ caption: I18n.t("openid_connect.instructions.mapping_#{attr}"),
+ disabled: provider.seeded_from_env?,
+ required: false,
+ input_width: :medium
+ )
+ end
+ end
+ end
+ end
+end
diff --git a/modules/openid_connect/app/components/openid_connect/providers/view_component.html.erb b/modules/openid_connect/app/components/openid_connect/providers/view_component.html.erb
index fd1337d1bd2..2db8e067f9f 100644
--- a/modules/openid_connect/app/components/openid_connect/providers/view_component.html.erb
+++ b/modules/openid_connect/app/components/openid_connect/providers/view_component.html.erb
@@ -159,7 +159,7 @@
provider,
form_class: ns::MetadataDetailsForm,
edit_state:,
- next_edit_state: :client_details,
+ next_edit_state: :attribute_mapping,
edit_mode:,
banner: provider.metadata_configured? ? t("openid_connect.providers.section_texts.configuration_metadata") : nil,
banner_scheme: :default,
@@ -178,6 +178,29 @@
end
end
+ component.with_row(scheme: :default) do
+ if edit_state == :attribute_mapping
+ render(ns::Sections::FormComponent.new(
+ provider,
+ form_class: ns::AttributeMappingForm,
+ edit_state:,
+ next_edit_state: :client_details,
+ edit_mode:,
+ heading: nil
+ ))
+ else
+ render(ns::Sections::ShowComponent.new(
+ provider,
+ target_state: :attribute_mapping,
+ view_mode:,
+ heading: t("openid_connect.providers.label_attribute_mapping"),
+ description: t("openid_connect.providers.section_texts.attribute_mapping"),
+ label: provider.metadata_configured? ? t(:label_completed) : nil,
+ label_scheme: provider.metadata_configured? ? :success : :secondary
+ ))
+ end
+ end
+
component.with_row(scheme: :default) do
if edit_state == :client_details
render(ns::Sections::FormComponent.new(
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 03f909a67bc..afafe6c84da 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
@@ -71,6 +71,10 @@ module OpenIDConnect
validates :jwks_uri,
url: { allow_blank: true, allow_nil: true, schemes: %w[http https] },
if: -> { model.jwks_uri_changed? }
+
+ OpenIDConnect::Provider::MAPPABLE_ATTRIBUTES.each do |attr|
+ attribute :"mapping_#{attr}"
+ end
end
end
end
diff --git a/modules/openid_connect/app/models/openid_connect/provider.rb b/modules/openid_connect/app/models/openid_connect/provider.rb
index dd446950ecb..9d6ac05bd26 100644
--- a/modules/openid_connect/app/models/openid_connect/provider.rb
+++ b/modules/openid_connect/app/models/openid_connect/provider.rb
@@ -10,11 +10,18 @@ module OpenIDConnect
DISCOVERABLE_ATTRIBUTES_OPTIONAL = %i[end_session_endpoint].freeze
DISCOVERABLE_ATTRIBUTES_MANDATORY = DISCOVERABLE_ATTRIBUTES_ALL - %i[end_session_endpoint jwks_uri]
+ MAPPABLE_ATTRIBUTES = %i[login email first_name last_name].freeze
+
store_attribute :options, :oidc_provider, :string
store_attribute :options, :metadata_url, :string
+
DISCOVERABLE_ATTRIBUTES_ALL.each do |attribute|
store_attribute :options, attribute, :string
end
+ MAPPABLE_ATTRIBUTES.each do |attribute|
+ store_attribute :options, "#{attribute}_mapping", :string
+ end
+
store_attribute :options, :client_id, :string
store_attribute :options, :client_secret, :string
store_attribute :options, :tenant, :string
diff --git a/modules/openid_connect/config/locales/de.yml b/modules/openid_connect/config/locales/de.yml
deleted file mode 100644
index b7a30641707..00000000000
--- a/modules/openid_connect/config/locales/de.yml
+++ /dev/null
@@ -1,27 +0,0 @@
-de:
- logout_warning: >
- Sie wurden ausgeloggt. Inhalte von Formularen, die sie abschicken möchten,
- können verloren gehen. Bitte [loggen Sie sich wieder ein].
- activemodel:
- attributes:
- openid_connect/provider:
- name: Name
- display_name: Angezeigter Name
- identifier: Identifier
- secret: Secret
- scope: Scope
- limit_self_registration: Selbstregistrierung einschränken
- openid_connect:
- menu_title: OpenID-Provider
- providers:
- label_add_new: Einen neuen OpenID-Provider hinzufügen
- label_edit: OpenID-Provider %{name} bearbeiten
- no_results_table: Es wurden noch keine OpenID-Provider konfiguriert.
- plural: OpenID-Provider
- singular: OpenID-Provider
- upsale:
- description: Use existing OpenID credentials with OpenProject for easier access and interoperability with a range of other providers.
- setting_instructions:
- limit_self_registration: >
- Wenn diese Option aktiv ist, können sich neue Nutzer mit diesem OpenID-Provider nur registrieren,
- wenn die Selbstregistrierungs-Einstellung es erlaubt.
diff --git a/modules/openid_connect/config/locales/en.yml b/modules/openid_connect/config/locales/en.yml
index 7bede7ed339..83965c96b13 100644
--- a/modules/openid_connect/config/locales/en.yml
+++ b/modules/openid_connect/config/locales/en.yml
@@ -21,7 +21,6 @@ en:
end_session_endpoint: End session endpoint
jwks_uri: JWKS URI
issuer: Issuer
- limit_self_registration: Limit self-registration
tenant: Tenant
metadata_url: Metadata URL
activerecord:
@@ -46,6 +45,14 @@ en:
limit_self_registration: If enabled, users can only register using this provider if configuration on the prvoder's end allows it.
display_name: Then name of the provider. This will be displayed as the login button and in the list of providers.
tenant: Please replace the default tenant with your own if applicable. See <a href=" https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc#find-your-apps-openid-configuration-document-uri">this</a>.
+ mapping_login: >
+ Provide a custom mapping in the userinfo response to be used for the login attribute.
+ mapping_email: >
+ Provide a custom mapping in the userinfo response to be used for the email attribute.
+ mapping_first_name: >
+ Provide a custom mapping in the userinfo response to be used for the first name.
+ mapping_last_name: >
+ Provide a custom mapping in the userinfo response to be used for the last name.
settings:
metadata_none: I don't have this information
metadata_url: I have a discovery endpoint URL
@@ -68,6 +75,7 @@ en:
label_advanced_configuration: Advanced configuration
label_configuration_details: Metadata
label_client_details: Client details
+ label_attribute_mapping: Attribute mapping
client_details_description: Configuration details of OpenProject as an OIDC client
no_results_table: No providers have been defined yet.
plural: OpenID providers
@@ -80,6 +88,7 @@ en:
configuration_metadata: The information has been pre-filled using the supplied discovery endpoint. In most cases, they do not require editing.
configuration: Configuration details of the OpenID Connect provider
display_name: The display name visible to users.
+ attribute_mapping: Configure the mapping of attributes between OpenProject and the OpenID Connect provider.
setting_instructions:
limit_self_registration: >
If enabled users can only register using this provider if the self registration setting allows for it.