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

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.rb
index 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 OpenIDConnect
super.presence || "openid_connect/auth_provider-custom.png"
end
end
+
+ def scopes
+ (scope || "").split
+ end
end
end
diff --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.rb
index 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 Storages
def 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_user
non_oidc_provisioned_user
token_negotiable
user_bound_request
+ offline_access
end
def non_provisioned_user
@@ -116,6 +123,14 @@ module Storages
fail_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
+ end
end
end
end
diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.yml
index 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 token
header: Authentication
non_provisioned_user: User provisioned by IDP
+ offline_access: Configured OIDC offline_access scope
provisioned_user_provider: User provisioned by OIDC
token_negotiable: User token capabilities
user_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.rb
index 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 Storages
let(: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 do
User.current = user
@@ -97,7 +98,7 @@ module Storages
expect(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 })
end
it "returns a warning if the user is not provisioned by an oidc provider" do
@@ -108,7 +109,22 @@ module Storages
expect(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 })
+ end
end
end
@@ -161,7 +177,7 @@ module Storages
end
context "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