Compare commits

...

2 Commits

Author SHA1 Message Date
d726e28876 Улучшил логгирование
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 4m58s
2025-10-24 12:58:15 +03:00
fd6942960c Добавил обработку отказа от авторизации 2025-10-24 12:39:38 +03:00
2 changed files with 35 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ using X.Extensions.Logging.Telegram.Extensions;
using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.ApplicationParts;
using SfeduSchedule.Auth; using SfeduSchedule.Auth;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@@ -66,6 +67,36 @@ builder.Services.AddAuthorization();
builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration); builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration);
builder.Services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.Events.OnRemoteFailure = context =>
{
context.HandleResponse();
if (context.Failure != null && context.Failure.Message.Contains("AADSTS65004"))
{
context.Response.Redirect("/?error_msg=Вы отклонили запрос на вход в систему.");
}
else
{
var redirectUri = context.Properties?.RedirectUri;
context.Response.Redirect(string.IsNullOrEmpty(redirectUri) ? "/" : redirectUri);
}
return Task.CompletedTask;
};
options.Events.OnAuthenticationFailed = context =>
{
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<Program>>();
logger.LogError(context.Exception, "OIDC authentication failed");
context.HandleResponse();
var redirectUri = context.Properties?.RedirectUri;
context.Response.Redirect(string.IsNullOrEmpty(redirectUri) ? "/" : redirectUri);
return Task.CompletedTask;
};
});
// Загружаем плагины (изолированно), даём им зарегистрировать DI и подключаем контроллеры // Загружаем плагины (изолированно), даём им зарегистрировать DI и подключаем контроллеры
var loadedPlugins = PluginLoader.LoadPlugins(pluginsPath); var loadedPlugins = PluginLoader.LoadPlugins(pluginsPath);
Console.WriteLine("Plugins count: " + loadedPlugins.Count); Console.WriteLine("Plugins count: " + loadedPlugins.Count);

View File

@@ -126,13 +126,13 @@ namespace SfeduSchedule.Services
break; break;
case { Embedded: null }: case { Embedded: null }:
_logger.LogError( _logger.LogError(
"GetScheduleJsonAsync: scheduleJson.Embedded is null. scheduleJson: {@scheduleJson}\n Request: {msr}", "GetScheduleJsonAsync: scheduleJson.Embedded is null. Response: {@response}\nscheduleJson: {@scheduleJson}\n Request: {msr}",
scheduleJson, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions)); schedule, scheduleJson, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions));
break; break;
case { Embedded.Events: null }: case { Embedded.Events: null }:
_logger.LogError( _logger.LogError(
"GetScheduleJsonAsync: scheduleJson.Embedded.Events is null. Embedded: {@Embedded}\n Request: {msr}", "GetScheduleJsonAsync: scheduleJson.Embedded.Events is null. Response: {@response}\nEmbedded: {@Embedded}\n Request: {msr}",
scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions)); schedule, scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions));
break; break;
case { Embedded.Events.Length: 0 }: case { Embedded.Events.Length: 0 }:
_logger.LogWarning( _logger.LogWarning(