Compare commits
2 Commits
ad5576958f
...
d726e28876
| Author | SHA1 | Date | |
|---|---|---|---|
| d726e28876 | |||
| fd6942960c |
@@ -9,6 +9,7 @@ using X.Extensions.Logging.Telegram.Extensions;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
||||
using SfeduSchedule.Auth;
|
||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -66,6 +67,36 @@ builder.Services.AddAuthorization();
|
||||
|
||||
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 и подключаем контроллеры
|
||||
var loadedPlugins = PluginLoader.LoadPlugins(pluginsPath);
|
||||
Console.WriteLine("Plugins count: " + loadedPlugins.Count);
|
||||
|
||||
@@ -126,13 +126,13 @@ namespace SfeduSchedule.Services
|
||||
break;
|
||||
case { Embedded: null }:
|
||||
_logger.LogError(
|
||||
"GetScheduleJsonAsync: scheduleJson.Embedded is null. scheduleJson: {@scheduleJson}\n Request: {msr}",
|
||||
scheduleJson, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions));
|
||||
"GetScheduleJsonAsync: scheduleJson.Embedded is null. Response: {@response}\nscheduleJson: {@scheduleJson}\n Request: {msr}",
|
||||
schedule, scheduleJson, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions));
|
||||
break;
|
||||
case { Embedded.Events: null }:
|
||||
_logger.LogError(
|
||||
"GetScheduleJsonAsync: scheduleJson.Embedded.Events is null. Embedded: {@Embedded}\n Request: {msr}",
|
||||
scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions));
|
||||
"GetScheduleJsonAsync: scheduleJson.Embedded.Events is null. Response: {@response}\nEmbedded: {@Embedded}\n Request: {msr}",
|
||||
schedule, scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions));
|
||||
break;
|
||||
case { Embedded.Events.Length: 0 }:
|
||||
_logger.LogWarning(
|
||||
|
||||
Reference in New Issue
Block a user