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
[#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.rbindex 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 Storagesenddef 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)endendenddiff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication.rbindex 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 Storageswhen :oauth_user_tokenAuthenticationStrategies::OAuthUserToken.new(strategy.user)when :oauth_client_credentials- AuthenticationStrategies::OAuthClientCredentials.new+ AuthenticationStrategies::OAuthClientCredentials.new(strategy.use_cache)elseraise "Invalid authentication strategy '#{strategy}'"enddiff --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.rbindex 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 StoragesStrategy.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_configreturn 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 }+ .resultoperation_result = yield http+ return operation_result unless @use_cache+case operation_resultin success: truewrite_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.rbindex 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 Storagesmodule StorageInteractionmodule AuthenticationStrategiesclass Strategy- attr_reader :key, :user+ attr_reader :key, :user, :use_cachedef initialize(key)@key = key+ # per default authorization strategies are using the cache+ # to reduce the number authentication requests+ @use_cache = trueenddef with_user(user)@user = userselfend++ def with_cache(use_cache)+ @use_cache = use_cache+ self+ endendendend