feat(api): аутентификация, отключен кастомный BaseSimpleRoleProvider, роли добавляются в ParrAuthenticationHandler
This commit is contained in:
@@ -46,6 +46,8 @@ namespace PARR.API.Authentication
|
|||||||
var claims = new List<Claim> {
|
var claims = new List<Claim> {
|
||||||
new Claim(ClaimTypes.Name, user.UserIp)
|
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 claimsIdentity = new ClaimsIdentity(claims, Scheme.Name);
|
||||||
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
|
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ namespace PARR.API.Controllers.V1
|
|||||||
/// Получить мой ip
|
/// Получить мой ip
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
//[Authorize(Roles = ParrRoles.Administrator.Role)]
|
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||||
[Authorize]
|
//[Authorize]
|
||||||
[HttpGet(ApiRoutes.Test.GetMyIp)]
|
[HttpGet(ApiRoutes.Test.GetMyIp)]
|
||||||
public IActionResult GetMyIp()
|
public IActionResult GetMyIp()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ builder.Services.AddDallSettings(builder.Configuration);
|
|||||||
// Auth
|
// Auth
|
||||||
builder.Services.AddAuthentication(ParrAuthenticationOptions.DefaultScheme)
|
builder.Services.AddAuthentication(ParrAuthenticationOptions.DefaultScheme)
|
||||||
.AddScheme<ParrAuthenticationOptions, ParrAuthenticationHandler>(ParrAuthenticationOptions.DefaultScheme, opt => { });
|
.AddScheme<ParrAuthenticationOptions, ParrAuthenticationHandler>(ParrAuthenticationOptions.DefaultScheme, opt => { });
|
||||||
builder.Services.AddSimpleRoleAuthorization<BaseSimpleRoleProvider>();
|
// не используем, так как проверка ролей остается прежней, а роли подставляем в ParrAuthenticationHandler
|
||||||
|
//builder.Services.AddSimpleRoleAuthorization<BaseSimpleRoleProvider>();
|
||||||
|
|
||||||
|
|
||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace PARR.API.RoleProvider
|
|||||||
|
|
||||||
public async Task<ICollection<string>> GetUserRolesAsync(string ipClient)
|
public async Task<ICollection<string>> GetUserRolesAsync(string ipClient)
|
||||||
{
|
{
|
||||||
|
// это всё не используем, так как проверка ролей остается прежней, а роли подставляем в ParrAuthenticationHandler
|
||||||
|
|
||||||
// Авторизация - проверка на разрешения
|
// Авторизация - проверка на разрешения
|
||||||
// В данном случае, получаем все разрешения (роли)
|
// В данном случае, получаем все разрешения (роли)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user