From 47728c46b1378ffbf3dadb54255c21d51740681c Mon Sep 17 00:00:00 2001 From: Anders Abel Date: Wed, 22 May 2024 09:52:08 +0200 Subject: [PATCH] Perform checks in smarter order --- .../ConfigureOpenIdConnectOptions.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/IdentityServer/Configuration/DependencyInjection/ConfigureOpenIdConnectOptions.cs b/src/IdentityServer/Configuration/DependencyInjection/ConfigureOpenIdConnectOptions.cs index b2e09a2be..12128a072 100644 --- a/src/IdentityServer/Configuration/DependencyInjection/ConfigureOpenIdConnectOptions.cs +++ b/src/IdentityServer/Configuration/DependencyInjection/ConfigureOpenIdConnectOptions.cs @@ -34,16 +34,19 @@ public void PostConfigure(string name, OpenIdConnectOptions options) options.StateDataFormat = new DistributedCacheStateDataFormatter(_serviceProvider, name); } - var distributedCacheService = _serviceProvider.GetRequiredService(); - - if (distributedCacheService is MemoryDistributedCache && !warnedInMemory) + if (!warnedInMemory) { - var logger = _serviceProvider - .GetRequiredService>(); + var distributedCacheService = _serviceProvider.GetRequiredService(); + + if (distributedCacheService is MemoryDistributedCache) + { + var logger = _serviceProvider + .GetRequiredService>(); - logger.LogInformation("You have enabled the OidcStateDataFormatterCache but the distributed cache registered is the default memory based implementation. This will store any OIDC state in memory on the server that initiated the request. If the response is processed on another server it will fail. If you are running in production, you want to switch to a real distributed cache that is shared between all nodes."); + logger.LogInformation("You have enabled the OidcStateDataFormatterCache but the distributed cache registered is the default memory based implementation. This will store any OIDC state in memory on the server that initiated the request. If the response is processed on another server it will fail. If you are running in production, you want to switch to a real distributed cache that is shared between all nodes."); - warnedInMemory = true; + warnedInMemory = true; + } } } } \ No newline at end of file