diff --git a/Moonlight.Api/Implementations/ApiKeyScheme/ApiKeySchemeHandler.cs b/Moonlight.Api/Implementations/ApiKeyScheme/ApiKeySchemeHandler.cs index a721be70..dcc9a483 100644 --- a/Moonlight.Api/Implementations/ApiKeyScheme/ApiKeySchemeHandler.cs +++ b/Moonlight.Api/Implementations/ApiKeyScheme/ApiKeySchemeHandler.cs @@ -16,6 +16,8 @@ public class ApiKeySchemeHandler : AuthenticationHandler private readonly DatabaseRepository ApiKeyRepository; private readonly IMemoryCache MemoryCache; + private const string CacheKeyFormat = $"Moonlight.Api.{nameof(ApiKeySchemeHandler)}.{{0}}"; + public ApiKeySchemeHandler( IOptionsMonitor options, ILoggerFactory logger, @@ -38,7 +40,9 @@ public class ApiKeySchemeHandler : AuthenticationHandler if (authHeaderValue.Length > 32) return AuthenticateResult.Fail("Invalid api key specified"); - if (!MemoryCache.TryGetValue(authHeaderValue, out var apiKey)) + var cacheKey = string.Format(CacheKeyFormat, authHeaderValue); + + if (!MemoryCache.TryGetValue(cacheKey, out var apiKey)) { apiKey = await ApiKeyRepository .Query() @@ -49,7 +53,7 @@ public class ApiKeySchemeHandler : AuthenticationHandler if (apiKey == null) return AuthenticateResult.Fail("Invalid api key specified"); - MemoryCache.Set(authHeaderValue, apiKey, Options.LookupCacheTime); + MemoryCache.Set(cacheKey, apiKey, Options.LookupCacheTime); } else {