Claims transformation support missing in ASP.NET Core 2.0

后端 未结 2 916
[愿得一人]
[愿得一人] 2020-12-31 10:21

I am using JWT Bearer auth in my new asp.net core 2.0 api app and want to add some extra claims to the current identity. This extra info is located in another api which need

2条回答
  •  轮回少年
    2020-12-31 10:49

    IClaimsTransformer has been renamed to IClaimsTransformation in ASP.NET Core 2.0.

    Claims Transformation Simpler, new IClaimsTransformation service with a single method: Task TransformAsync(ClaimsPrincipal principal) We call this on any successful AuthenticateAsync call.

    services.AddSingleton();
    
    private class ClaimsTransformer : IClaimsTransformation {
        // Can consume services from DI as needed, including scoped DbContexts
        public ClaimsTransformer(IHttpContextAccessor httpAccessor) { }
        public Task TransformAsync(ClaimsPrincipal p) {
            p.AddIdentity(new ClaimsIdentity());
            return Task.FromResult(p);
        }
    }
    

    See https://github.com/aspnet/Security/issues/1310

提交回复
热议问题