feat(DisableAPIKeyAuth): Optionen als bool zu appsettings hinzugefügt. Konfiguriert mit app
This commit is contained in:
parent
8038ff74dd
commit
2c1abaaf32
@ -11,7 +11,6 @@ using WorkFlow.API.Models;
|
|||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Web;
|
using NLog.Web;
|
||||||
using WorkFlow.API.Extensions;
|
using WorkFlow.API.Extensions;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using WorkFlow.API.Filters;
|
using WorkFlow.API.Filters;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
@ -39,14 +38,14 @@ try
|
|||||||
Claims = user.ToClaimList().ToDictionary(claim => claim.Type, claim => claim.Value as object)
|
Claims = user.ToClaimList().ToDictionary(claim => claim.Type, claim => claim.Value as object)
|
||||||
});
|
});
|
||||||
|
|
||||||
var apiKeyAuthSection = config.GetSection("APIKeyAuth");
|
bool disableAPIKeyAuth = config.GetValue<bool>("DisableAPIKeyAuth") && builder.IsDevOrDiP();
|
||||||
var useApiKey = false;
|
if (!disableAPIKeyAuth)
|
||||||
if (apiKeyAuthSection.Get<APIKeyAuthOptions>() is APIKeyAuthOptions options)
|
if (config.GetSection("APIKeyAuth").Get<APIKeyAuthOptions>() is APIKeyAuthOptions options)
|
||||||
{
|
{
|
||||||
builder.Services.Configure<APIKeyAuthOptions>(apiKeyAuthSection);
|
builder.Services.AddAPIKeyAuth(options);
|
||||||
builder.Services.AddAPIKeyAuth(options);
|
}
|
||||||
useApiKey = true;
|
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();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
@ -66,7 +65,7 @@ try
|
|||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen(setupAct =>
|
builder.Services.AddSwaggerGen(setupAct =>
|
||||||
{
|
{
|
||||||
if(useApiKey)
|
if(!disableAPIKeyAuth)
|
||||||
setupAct.OperationFilter<APIKeyAuthHeaderOpFilter>();
|
setupAct.OperationFilter<APIKeyAuthHeaderOpFilter>();
|
||||||
|
|
||||||
if(config.GetSection("OpenApiInfo").Get<OpenApiInfo>() is OpenApiInfo openApiInfo)
|
if(config.GetSection("OpenApiInfo").Get<OpenApiInfo>() is OpenApiInfo openApiInfo)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"DiPMode": true,
|
"DiPMode": true,
|
||||||
"EnableSwagger": true,
|
"EnableSwagger": true,
|
||||||
|
"DisableAPIKeyAuth": false,
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user