Getting Claims or Priority Claims from within ASP.NET Dependency Injection Kernel

I have a class with ClaimsIdentity as a dependency:

public ClaimsIdentityDecorator (ClaimsIdentity identifier)

This is assumed to be the Claimsidentity ID of the current user. I get it both through IHttpContextAccessor like this:

 services.AddScoped( x=> { var context = x.GetService<IHttpContextAccessor>(); return context.HttpContext.User.Identity as ClaimsIdentity; }); 

I need to check user requirements, and it would seem that for me ClaimsIdentity or ClaimsPrincipal or some other authentication object will be automatically entered. Extracting it from the HttpContext and adding it in order. However, if there is another object or interface that has claims to it that already exist, I would like to design my classes to accept this dependency.

In addition, I just want to make sure that this needs to be entered at the area level.

+5
source share
1 answer

There is no built-in way to provide the ClaimsIdentity that I know of, but you probably want AddTransient . If the user logs off, but the instance was created at the beginning of the AddScoped request, this will not affect this change.

+3
source

Source: https://habr.com/ru/post/1273215/


All Articles