From e0b0297c153daeae9c624d3dcb6389002f17e6ad Mon Sep 17 00:00:00 2001 From: Mikhail Trubnikov Date: Mon, 4 Dec 2023 08:48:13 +1000 Subject: [PATCH] =?UTF-8?q?feat(api):=20=D0=B0=D1=83=D1=82=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D1=8F,=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D0=BC=D0=BD=D1=8B=D0=B9=20BaseSimpleRoleProv?= =?UTF-8?q?ider,=20=D1=80=D0=BE=D0=BB=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D1=8F=D1=8E=D1=82=D1=81=D1=8F=20=D0=B2=20ParrAuthe?= =?UTF-8?q?nticationHandler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PARR.API/Authentication/ParrAuthenticationHandler.cs | 2 ++ PARR.API/Controllers/V1/TestController.cs | 4 ++-- PARR.API/Program.cs | 3 ++- PARR.API/RoleProvider/BaseSimpleRoleProvider.cs | 2 ++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/PARR.API/Authentication/ParrAuthenticationHandler.cs b/PARR.API/Authentication/ParrAuthenticationHandler.cs index cb3b845c..6574e7fc 100644 --- a/PARR.API/Authentication/ParrAuthenticationHandler.cs +++ b/PARR.API/Authentication/ParrAuthenticationHandler.cs @@ -46,6 +46,8 @@ namespace PARR.API.Authentication var claims = new List { new Claim(ClaimTypes.Name, user.UserIp) }; + // добавляем роли + user.Roles.ForEach(r => claims.Add(new Claim(ClaimTypes.Role, r.Name))); var claimsIdentity = new ClaimsIdentity(claims, Scheme.Name); var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); diff --git a/PARR.API/Controllers/V1/TestController.cs b/PARR.API/Controllers/V1/TestController.cs index 3d98381e..0db12bc7 100644 --- a/PARR.API/Controllers/V1/TestController.cs +++ b/PARR.API/Controllers/V1/TestController.cs @@ -28,8 +28,8 @@ namespace PARR.API.Controllers.V1 /// Получить мой ip /// /// - //[Authorize(Roles = ParrRoles.Administrator.Role)] - [Authorize] + [Authorize(Roles = ParrRoles.Administrator.Role)] + //[Authorize] [HttpGet(ApiRoutes.Test.GetMyIp)] public IActionResult GetMyIp() { diff --git a/PARR.API/Program.cs b/PARR.API/Program.cs index f2923431..d18a05e3 100644 --- a/PARR.API/Program.cs +++ b/PARR.API/Program.cs @@ -35,7 +35,8 @@ builder.Services.AddDallSettings(builder.Configuration); // Auth builder.Services.AddAuthentication(ParrAuthenticationOptions.DefaultScheme) .AddScheme(ParrAuthenticationOptions.DefaultScheme, opt => { }); -builder.Services.AddSimpleRoleAuthorization(); +// не используем, так как проверка ролей остается прежней, а роли подставляем в ParrAuthenticationHandler +//builder.Services.AddSimpleRoleAuthorization(); builder.Services.AddHttpContextAccessor(); diff --git a/PARR.API/RoleProvider/BaseSimpleRoleProvider.cs b/PARR.API/RoleProvider/BaseSimpleRoleProvider.cs index be304f49..ecc82c8a 100644 --- a/PARR.API/RoleProvider/BaseSimpleRoleProvider.cs +++ b/PARR.API/RoleProvider/BaseSimpleRoleProvider.cs @@ -13,6 +13,8 @@ namespace PARR.API.RoleProvider public async Task> GetUserRolesAsync(string ipClient) { + // это всё не используем, так как проверка ролей остается прежней, а роли подставляем в ParrAuthenticationHandler + // Авторизация - проверка на разрешения // В данном случае, получаем все разрешения (роли)