fix(api): получения ip адреса за балансировщиком

This commit is contained in:
Mikhail Trubnikov
2023-12-04 10:56:29 +10:00
parent 68e15021ec
commit 9de290aca6
2 changed files with 13 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
using Elastic.CommonSchema.Serilog;
using FluentValidation;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Server.HttpSys;
using PARR.API.Authentication;
using PARR.API.Installers;
@@ -38,6 +39,15 @@ builder.Services.AddAuthentication(ParrAuthenticationOptions.DefaultScheme)
// не используем, так как проверка ролей остается прежней, а роли подставляем в ParrAuthenticationHandler
//builder.Services.AddSimpleRoleAuthorization<BaseSimpleRoleProvider>();
// При использовании балансировщика (haproxy, перенаправлять заголовки)
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
options.KnownNetworks.Clear();
options.KnownProxies.Clear();
});
builder.Services.AddHttpContextAccessor();