Na most működig SWAGGER és 5000 porton publishban is !
This commit is contained in:
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user