Na most működig SWAGGER és 5000 porton publishban is !

This commit is contained in:
2025-01-15 17:26:09 +01:00
parent a2906cc113
commit 6a46975cfd
7 changed files with 55 additions and 28 deletions
+5 -1
View File
@@ -4,16 +4,19 @@
{
private readonly RequestDelegate _next;
private const string ApiKeyHeaderName = "X-Api-Key";
private readonly ILogger<ApiKeyMiddleware> _logger;
public ApiKeyMiddleware(RequestDelegate next)
public ApiKeyMiddleware(RequestDelegate next, ILogger<ApiKeyMiddleware> logger)
{
_next = next;
_logger = logger;
}
public async Task InvokeAsync(HttpContext context)
{
if (!context.Request.Headers.TryGetValue(ApiKeyHeaderName, out var extractedApiKey))
{
_logger.LogWarning("API Key is missing.");
context.Response.StatusCode = 401; // Unauthorized
context.Response.ContentType = "text/html; charset=utf-8";
await context.Response.WriteAsync("API Key hiányzik.");
@@ -25,6 +28,7 @@
if (!apiKey.Equals(extractedApiKey))
{
_logger.LogWarning("Invalid API Key.");
context.Response.StatusCode = 403; // Forbidden
context.Response.ContentType = "text/html; charset=utf-8";
await context.Response.WriteAsync("Helytelen API Key.");