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

Attempt to fix lost oauth token issue

Pavel Balashou950c779a823c
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/oauth_user_token.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/oauth_user_token.rb
index 792fc640004..ac17b430704 100644
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/oauth_user_token.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/authentication_strategies/oauth_user_token.rb
@@ -77,8 +77,11 @@ module Storages
return Failures::Builder.call(code: :error, log_message:, data:)
end
- current_token = OAuthClientToken.find_by(user: @user,
- oauth_client: storage.oauth_configuration.oauth_client)
+ # Uncached block is used here because in case of concurrent update on the second try we need a fresh token.
+ # Otherwise token ends up in an invalid state which leads to an undesired token deletion.
+ current_token = OAuthClientToken.uncached do
+ OAuthClientToken.find_by(user: @user, oauth_client: storage.oauth_configuration.oauth_client)
+ end
if current_token.nil?
Failures::Builder.call(code: :unauthorized,
log_message: "Authorization failed. No user access token found.",