feat(api): аутентификация и авторизация. Кастомные ParrAuthenticationHandler и BaseSimpleRoleProvider.

This commit is contained in:
Mikhail Trubnikov
2023-12-01 16:41:37 +10:00
parent 78f2310199
commit d0c309e642
23 changed files with 395 additions and 11 deletions

View File

@@ -1,6 +1,9 @@
using Elastic.CommonSchema.Serilog;
using FluentValidation;
using Microsoft.AspNetCore.Server.HttpSys;
using PARR.API.Authentication;
using PARR.API.Installers;
using PARR.API.RoleProvider;
using PARR.BLL;
using PARR.DAL;
using Serilog;
@@ -29,6 +32,12 @@ builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Configuration.AddDalConfigurations(builder.Services);
builder.Services.AddDallSettings(builder.Configuration);
// Auth
builder.Services.AddAuthentication(ParrAuthenticationOptions.DefaultScheme)
.AddScheme<ParrAuthenticationOptions, ParrAuthenticationHandler>(ParrAuthenticationOptions.DefaultScheme, opt => { });
builder.Services.AddSimpleRoleAuthorization<BaseSimpleRoleProvider>();
builder.Services.AddHttpContextAccessor();
builder.Services.AddControllers();
@@ -44,6 +53,7 @@ var app = builder.Build();
// Configure the HTTP request pipeline.
app.InstallSwagger();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();