diff --git a/Conductor/Client/Authentication/TokenHandler.cs b/Conductor/Client/Authentication/TokenHandler.cs index 7fa978c..7b78aa9 100644 --- a/Conductor/Client/Authentication/TokenHandler.cs +++ b/Conductor/Client/Authentication/TokenHandler.cs @@ -10,6 +10,7 @@ public class TokenHandler { private static int REFRESH_TOKEN_RETRY_COUNTER_LIMIT = 5; private static readonly object _lockObject = new object(); + private static readonly object _getTokenlockObject = new object(); private readonly MemoryCache _memoryCache; private static ILogger _logger; @@ -18,7 +19,6 @@ public TokenHandler() _memoryCache = new MemoryCache(new MemoryCacheOptions()); _logger = ApplicationLogging.CreateLogger(); } - public string GetToken(OrkesAuthenticationSettings authenticationSettings, TokenResourceApi tokenClient) { string token = (string)_memoryCache.Get(authenticationSettings); @@ -26,7 +26,12 @@ public string GetToken(OrkesAuthenticationSettings authenticationSettings, Token { return token; } - return RefreshToken(authenticationSettings, tokenClient); + + lock (_getTokenlockObject) + { + token = (string)_memoryCache.Get(authenticationSettings); + return token != null ? token : RefreshToken(authenticationSettings, tokenClient); + } } public string RefreshToken(OrkesAuthenticationSettings authenticationSettings, TokenResourceApi tokenClient)