Добавил обработку отказа от авторизации
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user