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
Introduce offline_access check for nextcloud SSO
Jan Sandbrink3dcbdb35c01c
diff --git a/modules/openid_connect/app/models/openid_connect/provider.rb b/modules/openid_connect/app/models/openid_connect/provider.rbindex c770cb07b5a..d74b6c00410 100644--- a/modules/openid_connect/app/models/openid_connect/provider.rb+++ b/modules/openid_connect/app/models/openid_connect/provider.rb@@ -131,5 +131,9 @@ module OpenIDConnectsuper.presence || "openid_connect/auth_provider-custom.png"endend++ def scopes+ (scope || "").split+ endendenddiff --git a/modules/storages/app/common/storages/peripherals/connection_validators/nextcloud/authentication_validator.rb b/modules/storages/app/common/storages/peripherals/connection_validators/nextcloud/authentication_validator.rbindex 79dd76df0cb..8c429f2a127 100644--- a/modules/storages/app/common/storages/peripherals/connection_validators/nextcloud/authentication_validator.rb+++ b/modules/storages/app/common/storages/peripherals/connection_validators/nextcloud/authentication_validator.rb@@ -72,12 +72,19 @@ module Storagesdef auth_strategy = Registry["nextcloud.authentication.user_bound"].call(storage: @storage, user: @user)def validate_sso- register_checks(:non_provisioned_user, :provisioned_user_provider, :token_negotiable, :user_bound_request)+ register_checks(+ :non_provisioned_user,+ :provisioned_user_provider,+ :token_negotiable,+ :user_bound_request,+ :offline_access+ )non_provisioned_usernon_oidc_provisioned_usertoken_negotiableuser_bound_request+ offline_accessenddef non_provisioned_user@@ -116,6 +123,14 @@ module Storagesfail_check(:token_negotiable, error_code)end++ def offline_access+ if @user.authentication_provider.scopes.include?("offline_access")+ pass_check(:offline_access)+ else+ warn_check(:offline_access, :offline_access_scope_missing)+ end+ endendendenddiff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex b050b85fc22..375f0022872 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -253,6 +253,7 @@ en:existing_token: User tokenheader: Authenticationnon_provisioned_user: User provisioned by IDP+ offline_access: Configured OIDC offline_access scopeprovisioned_user_provider: User provisioned by OIDCtoken_negotiable: User token capabilitiesuser_bound_request: User-based request authentication@@ -299,6 +300,7 @@ en:od_oauth_token_missing: OpenProject cannot test the user level communication with OneDrive/SharePoint as the user did not yet link their Microsoft account.od_tenant_id_wrong: The configured directory (tenant) id is invalid. Please check the configuration.od_unexpected_content: Unexpected content found in the drive.+ offline_access_scope_missing: It is recommended to configure the OpenID Connect provider to request the offline_access scope. The integration may still work anyways, but make sure that refresh tokens do not expire.oidc_cant_acquire_token: Your OpenID Connect setup doesn't provide the necessary audience, nor provides token exchange capabilities. Please check out our documentation for more information.oidc_cant_exchange_token: There seems to be a problem with the Token Exchange setup on your OpenID Connect Provider. Please check its configuration and try again.oidc_cant_refresh_token: There was an error while trying to check your access to the storage. Please check the server logs for further information.diff --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 d3a518d4ecd..8e06bc355f9 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@@ -73,7 +73,8 @@ module Storageslet(:storage) { create(:nextcloud_storage_configured, :oidc_sso_enabled) }let(:user) { create(:user, authentication_provider: oidc_provider) }- let!(:oidc_provider) { create(:oidc_provider) }+ let!(:oidc_provider) { create(:oidc_provider, scope:) }+ let(:scope) { "openid email profile offline_access" }before doUser.current = user@@ -97,7 +98,7 @@ module Storagesexpect(result[:non_provisioned_user].code).to eq(:oidc_non_provisioned_user)state_count = result.tally- expect(state_count).to eq({ skipped: 3, warning: 1 })+ expect(state_count).to eq({ skipped: 4, warning: 1 })endit "returns a warning if the user is not provisioned by an oidc provider" do@@ -108,7 +109,22 @@ module Storagesexpect(result[:provisioned_user_provider].code).to eq(:oidc_non_oidc_user)state_count = result.tally- expect(state_count).to eq({ success: 1, skipped: 2, warning: 1 })+ expect(state_count).to eq({ success: 1, skipped: 3, warning: 1 })+ end++ context "when the offline_access scope is not configured" do+ let(:scope) { "openid email profile" }++ it "returns a warning", :aggregate_failures do+ create(:oidc_user_token, user:, extra_audiences: storage.audience)+ result = validator.call++ expect(result[:offline_access]).to be_warning+ expect(result[:offline_access].code).to eq(:offline_access_scope_missing)++ state_count = result.tally+ expect(state_count).to eq({ success: 4, warning: 1 })+ endendend@@ -161,7 +177,7 @@ module Storagesendcontext "when the server supports token exchange" do- let(:oidc_provider) { create(:oidc_provider, :token_exchange_capable) }+ let(:oidc_provider) { create(:oidc_provider, :token_exchange_capable, scope: "offline_access") }let(:exchangeable_token) { create(:oidc_user_token, user:, refresh_token: nil) }it "favors token exchange when refreshing" do