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.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);
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user