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 post_logout_redirect_uri

Oliver Günther0d15a67a3e7a
diff --git a/modules/openid_connect/app/components/openid_connect/providers/client_details_form.rb b/modules/openid_connect/app/components/openid_connect/providers/client_details_form.rb
index 3c7703b713d..8c945ac679a 100644
--- a/modules/openid_connect/app/components/openid_connect/providers/client_details_form.rb
+++ b/modules/openid_connect/app/components/openid_connect/providers/client_details_form.rb
@@ -40,6 +40,14 @@ module OpenIDConnect
input_width: :large
)
end
+ f.text_field(
+ name: :post_logout_redirect_uri,
+ label: I18n.t("activemodel.attributes.openid_connect/provider.post_logout_redirect_uri"),
+ caption: I18n.t("openid_connect.instructions.post_logout_redirect_uri"),
+ disabled: provider.seeded_from_env?,
+ required: false,
+ input_width: :large
+ )
f.check_box(
name: :limit_self_registration,
label: I18n.t("activemodel.attributes.openid_connect/provider.limit_self_registration"),
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 6f9f1e4b797..8c7df80628a 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
@@ -55,6 +55,12 @@ module OpenIDConnect
if: -> { model.public_send(:"#{attr}_changed?") && !path_attribute?(model.public_send(attr)) }
end
+ attribute :post_logout_redirect_uri
+ validates :post_logout_redirect_uri,
+ 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/models/openid_connect/provider.rb b/modules/openid_connect/app/models/openid_connect/provider.rb
index b443c77f1b7..8e54cf309ea 100644
--- a/modules/openid_connect/app/models/openid_connect/provider.rb
+++ b/modules/openid_connect/app/models/openid_connect/provider.rb
@@ -3,14 +3,12 @@ module OpenIDConnect
include HashBuilder
OIDC_PROVIDERS = %w[google microsoft_entra custom].freeze
- DISCOVERABLE_ATTRIBUTES_ALL = %i[authorization_endpoint
- userinfo_endpoint
- token_endpoint
- end_session_endpoint
- jwks_uri
- issuer].freeze
- DISCOVERABLE_ATTRIBUTES_OPTIONAL = %i[end_session_endpoint].freeze
- DISCOVERABLE_ATTRIBUTES_MANDATORY = DISCOVERABLE_ATTRIBUTES_ALL - %i[end_session_endpoint jwks_uri]
+ DISCOVERABLE_ATTRIBUTES_MANDATORY = %i[authorization_endpoint
+ userinfo_endpoint
+ token_endpoint
+ issuer].freeze
+ DISCOVERABLE_ATTRIBUTES_OPTIONAL = %i[end_session_endpoint jwks_uri].freeze
+ DISCOVERABLE_ATTRIBUTES_ALL = DISCOVERABLE_ATTRIBUTES_MANDATORY + DISCOVERABLE_ATTRIBUTES_OPTIONAL
MAPPABLE_ATTRIBUTES = %i[login email first_name last_name].freeze
@@ -27,6 +25,7 @@ module OpenIDConnect
store_attribute :options, :client_id, :string
store_attribute :options, :client_secret, :string
+ store_attribute :options, :post_logout_redirect_uri, :string
store_attribute :options, :tenant, :string
store_attribute :options, :host, :string
store_attribute :options, :scheme, :string
diff --git a/modules/openid_connect/config/locales/en.yml b/modules/openid_connect/config/locales/en.yml
index 0b839bf25e6..f54137e5ea7 100644
--- a/modules/openid_connect/config/locales/en.yml
+++ b/modules/openid_connect/config/locales/en.yml
@@ -19,6 +19,7 @@ en:
userinfo_endpoint: User information endpoint
token_endpoint: Token endpoint
end_session_endpoint: End session endpoint
+ post_logout_redirect_uri: Post logout redirect URI
jwks_uri: JWKS URI
issuer: Issuer
tenant: Tenant
@@ -62,6 +63,7 @@ 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>.
+ post_logout_redirect_uri: The URL the OpenID Connect provider should redirect to after a logout request.
claims: >
You can request additional claims for the userinfo and id token endpoints. Please see [our OpenID connect documentation](docs_url) for more information.
acr_values: >
diff --git a/modules/openid_connect/spec/migration/migrate_oidc_settings_to_providers_spec.rb b/modules/openid_connect/spec/migration/migrate_oidc_settings_to_providers_spec.rb
new file mode 100644
index 00000000000..50da7de23a7
--- /dev/null
+++ b/modules/openid_connect/spec/migration/migrate_oidc_settings_to_providers_spec.rb
@@ -0,0 +1,68 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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.
+#++
+
+require "spec_helper"
+require_relative "openid_connect_spec_helpers"
+
+require Rails.root.join('db/migrate/20190106184413_remove_email_from_users.rb')
+RSpec.describe RemoveEmailFromUsers do
+ let(:migrations_paths) { ActiveRecord::Migrator.migrations_paths }
+ let(:migrations) { ActiveRecord::MigrationContext.new(migrations_paths).migrations }
+ let(:previous_version) { 20181204143322 }
+ let(:current_version) { 20190106184413 }
+ subject { ActiveRecord::Migrator.new(:up, migrations, current_version).migrate }
+ around do |example|
+ # Silence migrations output in specs report.
+ ActiveRecord::Migration.suppress_messages do
+ # Migrate back to the previous version
+ ActiveRecord::Migrator.new(:down, migrations, ActiveRecord::SchemaMigration, previous_version).migrate
+
+ # If other tests using User table ran before this one, Rails has
+ # stored information about table's columns and we need to reset those
+ # since the migration changed the database structure.
+ User.reset_column_information
+ example.run
+
+ # Re-update column information after the migration has been executed
+ # again in the example. This will make user attributes cache
+ # ready for other tests.
+ User.reset_column_information
+ end
+ end
+ context 'when there are users with email' do
+ let(:user_with_email) { create(:user, email: '[email protected]') }
+ it 'creates an Email associated with the same user' do
+ expect { subject }
+ .to change { Email.all.size }
+ .from(0)
+ .to(1)
+ expect(Email.first.user).to eq user_with_email
+ expect(Email.first.value).to eq '[email protected]'
+ end
+ end
+end