From de28834d4b39993b37c530430fb62215a096fc13 Mon Sep 17 00:00:00 2001 From: Freek Gruntjes Date: Fri, 17 Mar 2023 14:43:32 +0100 Subject: [PATCH] chore: Made Security:ProtectionCertificate configuration optional --- App.Lib/src/AppWebApplication.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/App.Lib/src/AppWebApplication.cs b/App.Lib/src/AppWebApplication.cs index 62c8ad4..8c7e84b 100644 --- a/App.Lib/src/AppWebApplication.cs +++ b/App.Lib/src/AppWebApplication.cs @@ -188,9 +188,11 @@ private static void ConfigureDataProtection(WebApplicationBuilder builder) return; } - var certificate = builder.Configuration.MustGetValue("Security:ProtectionCertificate"); - - builder.Services.AddDataProtection() - .ProtectKeysWithCertificate(new X509Certificate2(certificate)); + var dataProtectionBuilder = builder.Services.AddDataProtection(); + var certificate = builder.Configuration.GetValue("Security:ProtectionCertificate"); + if (certificate != null) + { + dataProtectionBuilder.ProtectKeysWithCertificate(new X509Certificate2(certificate)); + } } }