From 2c1abaaf326b66a7b6eb7e4b706af03e69f68050 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 29 Oct 2024 11:43:25 +0100 Subject: [PATCH] =?UTF-8?q?feat(DisableAPIKeyAuth):=20Optionen=20als=20boo?= =?UTF-8?q?l=20zu=20appsettings=20hinzugef=C3=BCgt.=20Konfiguriert=20mit?= =?UTF-8?q?=20app?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WorkFlow.API/Program.cs | 19 +++++++++---------- WorkFlow.API/appsettings.json | 1 + 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/WorkFlow.API/Program.cs b/WorkFlow.API/Program.cs index d0b7405..3655c3e 100644 --- a/WorkFlow.API/Program.cs +++ b/WorkFlow.API/Program.cs @@ -11,7 +11,6 @@ using WorkFlow.API.Models; using NLog; using NLog.Web; using WorkFlow.API.Extensions; -using Microsoft.Extensions.Configuration; using WorkFlow.API.Filters; using Microsoft.OpenApi.Models; @@ -39,14 +38,14 @@ try Claims = user.ToClaimList().ToDictionary(claim => claim.Type, claim => claim.Value as object) }); - var apiKeyAuthSection = config.GetSection("APIKeyAuth"); - var useApiKey = false; - if (apiKeyAuthSection.Get() is APIKeyAuthOptions options) - { - builder.Services.Configure(apiKeyAuthSection); - builder.Services.AddAPIKeyAuth(options); - useApiKey = true; - } + bool disableAPIKeyAuth = config.GetValue("DisableAPIKeyAuth") && builder.IsDevOrDiP(); + if (!disableAPIKeyAuth) + if (config.GetSection("APIKeyAuth").Get() is APIKeyAuthOptions options) + { + builder.Services.AddAPIKeyAuth(options); + } + else + throw new("The API Key Authorization configuration is not available in the app settings, even though the app is not in development or DiP mode and API Key Authorization is not disabled."); builder.Services.AddControllers(); @@ -66,7 +65,7 @@ try builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(setupAct => { - if(useApiKey) + if(!disableAPIKeyAuth) setupAct.OperationFilter(); if(config.GetSection("OpenApiInfo").Get() is OpenApiInfo openApiInfo) diff --git a/WorkFlow.API/appsettings.json b/WorkFlow.API/appsettings.json index 685932d..615ac6c 100644 --- a/WorkFlow.API/appsettings.json +++ b/WorkFlow.API/appsettings.json @@ -1,6 +1,7 @@ { "DiPMode": true, "EnableSwagger": true, + "DisableAPIKeyAuth": false, "Logging": { "LogLevel": { "Default": "Information",