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
Fix omission in token exchange implementation
Jan Sandbrink06a0917c216a
diff --git a/modules/openid_connect/app/models/openid_connect/provider.rb b/modules/openid_connect/app/models/openid_connect/provider.rbindex d74b6c00410..0ab643a9c91 100644--- a/modules/openid_connect/app/models/openid_connect/provider.rb+++ b/modules/openid_connect/app/models/openid_connect/provider.rb@@ -34,8 +34,6 @@ module OpenIDConnecthas_many :remote_identities, as: :auth_source, dependent: :destroy- TOKEN_EXCHANGE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:token-exchange"-OIDC_PROVIDERS = %w[google microsoft_entra custom].freezeDISCOVERABLE_STRING_ATTRIBUTES_MANDATORY = %i[authorization_endpointuserinfo_endpoint@@ -118,7 +116,7 @@ module OpenIDConnectdef token_exchange_capable?return false if grant_types_supported.blank?- grant_types_supported.include?(TOKEN_EXCHANGE_GRANT_TYPE)+ grant_types_supported.include?(OpenProject::OpenIDConnect::TOKEN_EXCHANGE_GRANT_TYPE)enddef icondiff --git a/modules/openid_connect/app/services/openid_connect/user_tokens/token_request.rb b/modules/openid_connect/app/services/openid_connect/user_tokens/token_request.rbindex 36be64a145b..ed679d05ba6 100644--- a/modules/openid_connect/app/services/openid_connect/user_tokens/token_request.rb+++ b/modules/openid_connect/app/services/openid_connect/user_tokens/token_request.rb@@ -45,8 +45,9 @@ module OpenIDConnectdef exchange(access_token, audience)request_token(form: {- grant_type: OpenIDConnect::Provider::TOKEN_EXCHANGE_GRANT_TYPE,+ grant_type: OpenProject::OpenIDConnect::TOKEN_EXCHANGE_GRANT_TYPE,subject_token: access_token,+ subject_token_type: OpenProject::OpenIDConnect::ACCESS_TOKEN_TYPE,audience:})enddiff --git a/modules/openid_connect/lib/open_project/openid_connect.rb b/modules/openid_connect/lib/open_project/openid_connect.rbindex 4516474df1f..e64deb8e14e 100644--- a/modules/openid_connect/lib/open_project/openid_connect.rb+++ b/modules/openid_connect/lib/open_project/openid_connect.rb@@ -34,6 +34,9 @@ require "open_project/openid_connect/engine"module OpenProjectmodule OpenIDConnect+ ACCESS_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:access_token"+ TOKEN_EXCHANGE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:token-exchange"+def self.configurationproviders = ::OpenIDConnect::Provider.where(available: true)diff --git a/modules/openid_connect/spec/factories/oidc_provider_factory.rb b/modules/openid_connect/spec/factories/oidc_provider_factory.rbindex 3f385241eb0..906fa0d7a35 100644--- a/modules/openid_connect/spec/factories/oidc_provider_factory.rb+++ b/modules/openid_connect/spec/factories/oidc_provider_factory.rb@@ -52,7 +52,7 @@ FactoryBot.define dotrait :token_exchange_capable docallback(:after_build) do |provider|provider.options["grant_types_supported"] ||= []- provider.options["grant_types_supported"] << OpenIDConnect::Provider::TOKEN_EXCHANGE_GRANT_TYPE+ provider.options["grant_types_supported"] << OpenProject::OpenIDConnect::TOKEN_EXCHANGE_GRANT_TYPEendendenddiff --git a/modules/openid_connect/spec/services/openid_connect/user_tokens/exchange_service_spec.rb b/modules/openid_connect/spec/services/openid_connect/user_tokens/exchange_service_spec.rbindex bd52fb83499..e4596ae34e6 100644--- a/modules/openid_connect/spec/services/openid_connect/user_tokens/exchange_service_spec.rb+++ b/modules/openid_connect/spec/services/openid_connect/user_tokens/exchange_service_spec.rb@@ -57,7 +57,7 @@ RSpec.describe OpenIDConnect::UserTokens::ExchangeService, :webmock douser.oidc_user_tokens.create!(access_token: idp_access_token, audiences: [OpenIDConnect::UserToken::IDP_AUDIENCE])user.oidc_user_tokens.create!(access_token:, refresh_token:, audiences: [existing_audience])stub_request(:post, provider.token_endpoint)- .with(body: hash_including(grant_type: OpenIDConnect::Provider::TOKEN_EXCHANGE_GRANT_TYPE))+ .with(body: hash_including(grant_type: OpenProject::OpenIDConnect::TOKEN_EXCHANGE_GRANT_TYPE)).to_return(**exchange_response)enddiff --git a/modules/openid_connect/spec/services/openid_connect/user_tokens/token_request_spec.rb b/modules/openid_connect/spec/services/openid_connect/user_tokens/token_request_spec.rbindex 9d1c6d70f44..48559d695a7 100644--- a/modules/openid_connect/spec/services/openid_connect/user_tokens/token_request_spec.rb+++ b/modules/openid_connect/spec/services/openid_connect/user_tokens/token_request_spec.rb@@ -121,7 +121,12 @@ RSpec.describe OpenIDConnect::UserTokens::TokenRequest, :webmock doit "uses a properly formatted request body" dosubjectexpect(WebMock).to have_requested(:post, provider.token_endpoint)- .with(body: { grant_type: OpenIDConnect::Provider::TOKEN_EXCHANGE_GRANT_TYPE, subject_token: token, audience: })+ .with(body: {+ grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",+ subject_token: token,+ subject_token_type: "urn:ietf:params:oauth:token-type:access_token",+ audience:+ })endit "authenticates the request via HTTP Basic auth using Client ID and Client Secret" dodiff --git a/modules/storages/spec/common/storages/peripherals/connection_validators/nextcloud/authentication_validator_spec.rb b/modules/storages/spec/common/storages/peripherals/connection_validators/nextcloud/authentication_validator_spec.rbindex b89415600cf..1caef612c63 100644--- a/modules/storages/spec/common/storages/peripherals/connection_validators/nextcloud/authentication_validator_spec.rb+++ b/modules/storages/spec/common/storages/peripherals/connection_validators/nextcloud/authentication_validator_spec.rb@@ -178,12 +178,13 @@ module Storagescontext "when the server supports token exchange" dolet(:oidc_provider) { create(:oidc_provider, :token_exchange_capable, scope: "offline_access") }- let(:exchangeable_token) { create(:oidc_user_token, user:, refresh_token: nil) }+ let!(:exchangeable_token) { create(:oidc_user_token, user:, refresh_token: nil) }it "favors token exchange when refreshing" doexchange_request = stub_request(:post, oidc_provider.token_endpoint)- .with(body: { audience: storage.audience, subject_token: exchangeable_token.access_token,- grant_type: OpenIDConnect::Provider::TOKEN_EXCHANGE_GRANT_TYPE })+ .with(body: hash_including(+ grant_type: OpenProject::OpenIDConnect::TOKEN_EXCHANGE_GRANT_TYPE+ )).and_return_json(status: 200, body: { access_token: "NEW_TOKEN" })expect(validator.call).to be_success@@ -192,8 +193,9 @@ module Storagesit "fails if the exchange is met with an unexpected body" doexchange_request = stub_request(:post, oidc_provider.token_endpoint)- .with(body: { audience: storage.audience, subject_token: exchangeable_token.access_token,- grant_type: OpenIDConnect::Provider::TOKEN_EXCHANGE_GRANT_TYPE })+ .with(body: hash_including(+ grant_type: OpenProject::OpenIDConnect::TOKEN_EXCHANGE_GRANT_TYPE+ )).and_return_json(status: 200, body: { error: "failed " })result = validator.call@@ -205,8 +207,9 @@ module Storagesit "fails if the exchange fails" doexchange_request = stub_request(:post, oidc_provider.token_endpoint)- .with(body: { audience: storage.audience, subject_token: exchangeable_token.access_token,- grant_type: OpenIDConnect::Provider::TOKEN_EXCHANGE_GRANT_TYPE })+ .with(body: hash_including(+ grant_type: OpenProject::OpenIDConnect::TOKEN_EXCHANGE_GRANT_TYPE+ )).and_return(status: 401)result = validator.call