diff --git a/PARR.API/Authentication/ParrAuthenticationHandler.cs b/PARR.API/Authentication/ParrAuthenticationHandler.cs index 6574e7fc..bdd960f2 100644 --- a/PARR.API/Authentication/ParrAuthenticationHandler.cs +++ b/PARR.API/Authentication/ParrAuthenticationHandler.cs @@ -25,7 +25,7 @@ namespace PARR.API.Authentication var ipClient = Request.HttpContext.Connection.RemoteIpAddress?.MapToIPv4().ToString(); if (ipClient == null) - return AuthenticateResult.Fail($"IP address not defined."); + return AuthenticateResult.Fail($"IP address not defined. IP: {ipClient}"); // Аутентификация - просто проверка, есть ли у нас такой пользователь using (var scope = serviceProvider.CreateScope()) @@ -34,11 +34,11 @@ namespace PARR.API.Authentication var userIsBlocked = await authService.UserIsBlockedAsync(ipClient); if (userIsBlocked) - return AuthenticateResult.Fail($"IP address is on the blocking list."); + return AuthenticateResult.Fail($"IP address is on the blocking list. IP: {ipClient}"); var user = await authService.GetUserAsync(ipClient); if (user == null) - return AuthenticateResult.Fail($"IP address not defined."); + return AuthenticateResult.Fail($"IP address not defined. IP: {ipClient}"); // пользователь найден, аутентификация пройдена diff --git a/PARR.API/Program.cs b/PARR.API/Program.cs index d18a05e3..01e0232e 100644 --- a/PARR.API/Program.cs +++ b/PARR.API/Program.cs @@ -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(); +// При использовании балансировщика (haproxy, перенаправлять заголовки) +builder.Services.Configure(options => +{ + options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; + + options.KnownNetworks.Clear(); + options.KnownProxies.Clear(); +}); + builder.Services.AddHttpContextAccessor();