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

[#56027] disable token caching for one drive validation

Eric Schubertf59562840c8a
diff --git a/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb b/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb
index 0d53bc9cb96..70f749b328a 100644
--- a/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb
+++ b/modules/storages/app/common/storages/peripherals/one_drive_connection_validator.rb
@@ -155,7 +155,9 @@ module Storages
end
def auth_strategy
- Peripherals::Registry.resolve("#{@storage.short_provider_type}.authentication.userless").call
+ Peripherals::Registry.resolve("#{@storage.short_provider_type}.authentication.userless")
+ .call
+ .with_cache(false)
end
end
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication.rb
index 99489f33798..23bcc2af114 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication.rb
@@ -41,7 +41,7 @@ module Storages
when :oauth_user_token
AuthenticationStrategies::OAuthUserToken.new(strategy.user)
when :oauth_client_credentials
- AuthenticationStrategies::OAuthClientCredentials.new
+ AuthenticationStrategies::OAuthClientCredentials.new(strategy.use_cache)
else
raise "Invalid authentication strategy '#{strategy}'"
end
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/oauth_client_credentials.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/oauth_client_credentials.rb
index a1f791f1a99..b642773bc30 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/oauth_client_credentials.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/oauth_client_credentials.rb
@@ -37,18 +37,26 @@ module Storages
Strategy.new(:oauth_client_credentials)
end
+ def initialize(use_cache)
+ @use_cache = use_cache
+ end
+
def call(storage:, http_options: {})
config = storage.oauth_configuration.to_httpx_oauth_config
return build_failure(storage) unless config.valid?
token_cache_key = cache_key(storage)
- access_token = Rails.cache.read(token_cache_key)
+ access_token = @use_cache ? Rails.cache.read(token_cache_key) : nil
# In ruby 3.4 this can become `return it`
- http = build_http_session(access_token, config, http_options).on_failure { return _1 }.result
+ http = build_http_session(access_token, config, http_options)
+ .on_failure { return _1 }
+ .result
operation_result = yield http
+ return operation_result unless @use_cache
+
case operation_result
in success: true
write_cache(token_cache_key, http) if access_token.blank?
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/strategy.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/strategy.rb
index a95b0d2eef8..9677871783e 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/strategy.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/strategy.rb
@@ -33,16 +33,24 @@ module Storages
module StorageInteraction
module AuthenticationStrategies
class Strategy
- attr_reader :key, :user
+ attr_reader :key, :user, :use_cache
def initialize(key)
@key = key
+ # per default authorization strategies are using the cache
+ # to reduce the number authentication requests
+ @use_cache = true
end
def with_user(user)
@user = user
self
end
+
+ def with_cache(use_cache)
+ @use_cache = use_cache
+ self
+ end
end
end
end