Added swagger authorization check

This commit is contained in:
2025-12-31 03:58:18 +01:00
parent aa95308f61
commit 7dfe945a48

View File

@@ -136,6 +136,26 @@ app.MapHealthChecks("/healthz/AIProvider", new Microsoft.AspNetCore.Diagnostics.
bool IsDevelopment = app.Environment.IsDevelopment(); bool IsDevelopment = app.Environment.IsDevelopment();
app.Use(async (context, next) =>
{
if (context.Request.Path.StartsWithSegments("/swagger"))
{
if (!context.User.Identity?.IsAuthenticated ?? true)
{
context.Response.Redirect("/Account/Login");
return;
}
if (!context.User.IsInRole("Admin"))
{
context.Response.StatusCode = StatusCodes.Status403Forbidden;
return;
}
}
await next();
});
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(options => app.UseSwaggerUI(options =>
{ {