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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Request voluntary groups claim when group sync is enabled
Jan Sandbrink674c6ac29df7
diff --git a/modules/openid_connect/app/models/openid_connect/provider.rb b/modules/openid_connect/app/models/openid_connect/provider.rbindex 7cfbc2da754..5362f64fc17 100644--- a/modules/openid_connect/app/models/openid_connect/provider.rb+++ b/modules/openid_connect/app/models/openid_connect/provider.rb@@ -158,7 +158,14 @@ module OpenIDConnectdef to_hclaims = self.claims.presence || "{}"+ claims = add_groups_claim(JSON.parse(claims)).to_jsonsuper.merge(claims:, acr_values:)end++ def add_groups_claim(claims)+ claims = { "id_token" => { groups_claim => nil } }.deep_merge(claims) if sync_groups++ claims+ endendenddiff --git a/modules/openid_connect/spec/models/provider_spec.rb b/modules/openid_connect/spec/models/provider_spec.rbindex abda679a65d..6f960b5786b 100644--- a/modules/openid_connect/spec/models/provider_spec.rb+++ b/modules/openid_connect/spec/models/provider_spec.rb@@ -31,11 +31,14 @@ require "spec_helper"RSpec.describe OpenIDConnect::Provider dolet(:provider) do- create(:oidc_provider, options: {- "grant_types_supported" => supported_grant_types- })+ create(:oidc_provider, options: { "grant_types_supported" => supported_grant_types },+ claims:,+ sync_groups:,+ groups_claim: "the-groups")endlet(:supported_grant_types) { %w[authorization_code implicit] }+ let(:claims) { "" }+ let(:sync_groups) { false }describe "#token_exchange_capable?" dosubject { provider.token_exchange_capable? }@@ -103,4 +106,44 @@ RSpec.describe OpenIDConnect::Provider doendendend++ describe "#to_h" do+ subject { provider.to_h }++ it "includes empty claims by default" do+ expect(subject[:claims]).to eq("{}")+ end++ context "when claims were defined" do+ let(:claims) { '{"id_token":{"taste":null}}' }++ it "includes the defined claims" do+ expect(subject[:claims]).to eq(claims)+ end+ end++ context "when group sync is enabled" do+ let(:sync_groups) { true }++ it "requests the groups claim as voluntary" do+ expect(subject[:claims]).to eq('{"id_token":{"the-groups":null}}')+ end++ context "and when other claims were defined manually" do+ let(:claims) { '{"id_token":{"taste":null}}' }++ it "merges the manual claims and the groups claim" do+ expect(subject[:claims]).to eq('{"id_token":{"the-groups":null,"taste":null}}')+ end+ end++ context "and when the groups claim was defined manually" do+ let(:claims) { '{"id_token":{"the-groups":{"essential":true}}}' }++ it "takes the manual definition of the groups claim with precedence" do+ expect(subject[:claims]).to eq(claims)+ end+ end+ end+ endend