From 950c779a823cc7f7f90faafec35969cf5fe80049 Mon Sep 17 00:00:00 2001 From: Pavel Balashou Date: Tue, 10 Sep 2024 18:12:50 +0200 Subject: [PATCH] Attempt to fix lost oauth token issue --- .../authentication_strategies/oauth_user_token.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 792fc6400044..ac17b4307047 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 @@ def current_token(storage) 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.",