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

[#54558] guard oauth configuration init for incomplete storages

Eric Schubert59a15e07dce2
diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb
index faafbcdf59f..78d22ce075a 100644
--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb
+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/configuration_interface.rb
@@ -39,7 +39,7 @@ module Storages
def to_httpx_oauth_config = raise ::Storages::Errors::SubclassResponsibility
def authorization_uri(state: nil)
- basic_rack_oauth_client&.authorization_uri(scope:, state:)
+ basic_rack_oauth_client.authorization_uri(scope:, state:)
end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb
index 5b0eb0250c0..191f49cdd47 100644
--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb
+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/nextcloud_configuration.rb
@@ -39,6 +39,9 @@ module Storages
# rubocop:disable Lint/MissingSuper
def initialize(storage)
@uri = storage.uri
+
+ raise(ArgumentError, "Storage must have configured OAuth client credentials") if storage.oauth_client.blank?
+
@oauth_client = storage.oauth_client.freeze
end
@@ -62,8 +65,6 @@ module Storages
end
def basic_rack_oauth_client
- return nil if @oauth_client.nil?
-
Rack::OAuth2::Client.new(
identifier: @oauth_client.client_id,
secret: @oauth_client.client_secret,
diff --git a/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb b/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb
index ae650ba6a02..434525a10d5 100644
--- a/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb
+++ b/modules/storages/app/common/storages/peripherals/oauth_configurations/one_drive_configuration.rb
@@ -40,7 +40,13 @@ module Storages
def initialize(storage)
@storage = storage
@uri = storage.uri
- @oauth_client = storage.oauth_client
+
+ raise(ArgumentError, "Storage must have configured OAuth client credentials") if storage.oauth_client.blank?
+
+ @oauth_client = storage.oauth_client.freeze
+
+ raise(ArgumentError, "Storage must have a configured tenant id") if storage.tenant_id.blank?
+
@oauth_uri = URI("https://login.microsoftonline.com/#{@storage.tenant_id}/oauth2/v2.0").normalize
end
@@ -67,8 +73,6 @@ module Storages
end
def basic_rack_oauth_client
- return nil if @oauth_client.nil?
-
Rack::OAuth2::Client.new(
identifier: @oauth_client.client_id,
redirect_uri: @oauth_client.redirect_uri,
diff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rb
index 24c95803d08..4dc51c9f8eb 100644
--- a/modules/storages/lib/api/v3/storages/storage_representer.rb
+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb
@@ -163,7 +163,7 @@ module API::V3::Storages
end
link :authorize do
- next unless authorization_state == :failed_authorization
+ next if hide_authorize_link?
{ href: represented.oauth_configuration.authorization_uri, title: "Authorize" }
end
@@ -213,6 +213,10 @@ module API::V3::Storages
current_user.admin? && represented.provider_type_nextcloud?
end
+ def hide_authorize_link?
+ represented.oauth_client.blank? || authorization_state != :failed_authorization
+ end
+
def storage_projects(storage)
storage.projects.merge(Project.allowed_to(current_user, :manage_file_links))
end