Merge remote-tracking branch 'origin/main' into feature/web-zavady

This commit is contained in:
PatTheEvil committed 2026-12-04 15:44:41 +01:00
commit 1550c0343b
45 files changed
+1516 -169

No files matched your search

@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.HttpOverrides;
namespace Helpdesk.Web.Api;
internal sealed class ForwardedClientIpHandler(IHttpContextAccessor accessor) : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var header = ForwardedHeadersDefaults.XForwardedForHeaderName;
request.Headers.Remove(header);
if (accessor.HttpContext?.Connection.RemoteIpAddress is { } address)
request.Headers.Add(header, address.ToString());
return base.SendAsync(request, cancellationToken);
}
}
@@ -8,6 +8,13 @@ namespace Helpdesk.Web.Api;
/// <summary>Endpointy API pro přihlášeného uživatele; access token přidává <see cref="BearerTokenHandler"/>.</summary>
public sealed class HelpdeskApiClient(HttpClient http)
{
public async Task<string> GetOpenApiAsync(CancellationToken ct)
{
using var response = await http.GetAsync("api/v1/admin/openapi/v1.json", ct);
await ApiResponse.EnsureSuccessAsync(response, ct);
return await response.Content.ReadAsStringAsync(ct);
}
public async Task<UserDto> GetMeAsync(CancellationToken ct)
{
using var response = await http.GetAsync("users/me", ct);
@@ -0,0 +1,15 @@
using Helpdesk.Web.Api;
using Helpdesk.Web.Auth;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Helpdesk.Web.Controllers;
[Authorize(Roles = UserRoles.Admin)]
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
public sealed class SwaggerController(HelpdeskApiClient api) : Controller
{
[HttpGet("/swagger/v1/swagger.json")]
public async Task<IActionResult> Document(CancellationToken ct) =>
Content(await api.GetOpenApiAsync(ct), "application/json");
}
+1
View File
@@ -11,6 +11,7 @@
<ItemGroup>
<InternalsVisibleTo Include="Helpdesk.Web.Tests" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" />
</ItemGroup>
</Project>
+13 -2
View File
@@ -37,8 +37,12 @@ static void ConfigureApiClient(IServiceProvider services, HttpClient http)
builder.Services.AddHttpContextAccessor();
builder.Services.AddTransient<BearerTokenHandler>();
builder.Services.AddHttpClient<AuthApiClient>(ConfigureApiClient);
builder.Services.AddHttpClient<HelpdeskApiClient>(ConfigureApiClient).AddHttpMessageHandler<BearerTokenHandler>();
builder.Services.AddTransient<ForwardedClientIpHandler>();
builder.Services.AddHttpClient<AuthApiClient>(ConfigureApiClient)
.AddHttpMessageHandler<ForwardedClientIpHandler>();
builder.Services.AddHttpClient<HelpdeskApiClient>(ConfigureApiClient)
.AddHttpMessageHandler<ForwardedClientIpHandler>()
.AddHttpMessageHandler<BearerTokenHandler>();
// Přihlášení: tokeny API v šifrované HttpOnly cookie, obnova access tokenu při ověření cookie.
builder.Services.AddSingleton(TimeProvider.System);
@@ -111,6 +115,13 @@ app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapSwaggerUI("swagger", options =>
{
options.SwaggerEndpoint("v1/swagger.json", "Helpdesk API v1");
options.DocumentTitle = "Helpdesk API";
options.CacheLifetime = null;
}).RequireAuthorization(policy => policy.RequireRole(UserRoles.Admin));
app.MapStaticAssets();
app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}").WithStaticAssets();
@@ -9,6 +9,10 @@
<ul class="dropdown-menu dropdown-menu-end">
<li><span class="dropdown-item-text small text-body-secondary">@User.FindFirst(ClaimTypes.Email)?.Value</span></li>
<li><a class="dropdown-item" asp-controller="Profile" asp-action="Index">Můj profil</a></li>
@if (User.IsInRole(UserRoles.Admin))
{
<li><a class="dropdown-item" href="~/swagger">Swagger API</a></li>
}
<li><hr class="dropdown-divider" /></li>
<li>
<form method="post" asp-controller="Account" asp-action="Logout">