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
[#54558] fixed handling in user token strategy
Eric Schubert5c501814b183
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/o_auth_user_token.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/o_auth_user_token.rbindex 9c6911fa093..1ff70eb573c 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/o_auth_user_token.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/o_auth_user_token.rb@@ -43,25 +43,18 @@ module Storages# rubocop:disable Metrics/AbcSizedef call(storage:, http_options: {}, &)- config = storage.oauth_configuration- current_token = OAuthClientToken.find_by(user: @user, oauth_client: config.oauth_client)- if current_token.nil?- data = ::Storages::StorageErrorData.new(source: self.class)- return Failures::Builder.call(code: :unauthorized,- log_message: "Authorization failed. No user access token found.",- data:)- end+ token = current_token(storage).on_failure { |failure| return failure }- opts = http_options.deep_merge({ headers: { "Authorization" => "Bearer #{current_token.access_token}" } })+ opts = http_options.deep_merge({ headers: { "Authorization" => "Bearer #{token.result.access_token}" } })response_with_current_token = yield OpenProject.httpx.with(opts)if response_with_current_token.success? || response_with_current_token.result != :unauthorizedresponse_with_current_tokenelse- httpx_oauth_config = config.to_httpx_oauth_config+ httpx_oauth_config = storage.oauth_configuration.to_httpx_oauth_configreturn build_failure(storage) unless httpx_oauth_config.valid?- refresh_and_retry(httpx_oauth_config, http_options, current_token, &)+ refresh_and_retry(httpx_oauth_config, http_options, token.result, &)endend@@ -69,6 +62,25 @@ module Storagesprivate+ def current_token(storage)+ data = ::Storages::StorageErrorData.new(source: self.class)++ if storage.oauth_client.blank?+ log_message = "Authorization failed. Storage has no configured oauth client credentials."+ return Failures::Builder.call(code: :unauthorized, log_message:, data:)+ end++ current_token = OAuthClientToken.find_by(user: @user,+ oauth_client: storage.oauth_configuration.oauth_client)+ if current_token.nil?+ Failures::Builder.call(code: :unauthorized,+ log_message: "Authorization failed. No user access token found.",+ data:)+ else+ ServiceResult.success(result: current_token)+ end+ end+# rubocop:disable Metrics/AbcSizedef refresh_and_retry(config, http_options, token, &)begin