What is the use of IClaims Transformer?

In the ASP.Net core, you can use the implementation of IClaimsTransformer.

You register it as follows:

app.UseClaimsTransformation(o => o.Transformer = new MyClaimsTransformer());

Implementation

public class MyClaimsTransformer : IClaimsTransformer
{
    public Task<ClaimsPrincipal> TransformAsync(ClaimsTransformationContext context)
    {
        var identity = context.Principal.Identity as ClaimsIdentity;

        foreach (var claim in ci.Claims)
        {
           // you cannot modify claim.Type or claim.Value here
        }
    }
}

However ClaimsIdentity.Claims, the property is read-only. Also Claim.Type, Claim.Valueare readonly properties.

This means that during the implementation IClaimsTransformeryou can add only new claims. You cannot delete or modify existing claims.

So what is the real use of IClaims Transformer?

+4
source share
2 answers

Have you noticed the return type? This is ClaimsPrincipal.

ClaimsPrincipal, , , .

+4

, , cookie .

, cookie, , .

, , . , , cookie. , cookie, IClaimsPrincipalFactory.

+2

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


All Articles