aspnetcore: IClaimsTransformation TransformAsync not working in asp.net core 3.0

IClaimsTransformation TransformAsync not getting hit in netcoreapp3.0

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of ASP.NET Core ‘.3.0.0’
  2. Run this code ‘.’
 public class ClaimsExtender : IClaimsTransformation
    {
        
        public ClaimsExtender()
        {
            
        }

        public async Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal)
        {
             var x = "xxx";
        }
    }

When I Post a Request to my API, this TransformAsync method should always be hit.

This use to work in asp.net core 2.2

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (6 by maintainers)

Most upvoted comments

I am having the same issue and my user is authenticated. I am using Windows authorization and have the typical identity database structure. Users have claims and I have an IClaimsTransformation the adds the appropriate claims from the database to the ClaimsPrincipal.

In 2.2, as soon as the user signs in, the IClaimsTransformation is hit and the claims are added. In 3.0, the IClaimsTransformation is never hit.

I have messed with the order that the services are added, but this has had no impact.

The current order of my services is: ` services.AddControllersWithViews();

        services.AddDbContext<DataDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DataConnection")));

        services.AddDbContext<IDDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("IDConnection")));

        services.AddAuthentication(IISDefaults.AuthenticationScheme);

        string ApplicationName = Configuration.GetSection("ApplicationInformation")["AppDotName"];

        services.AddAuthorization(options =>
            {
                options.AddPolicy("IT", policy => policy.RequireClaim(ApplicationName, "IT"));
                options.AddPolicy("AppUser", policy => policy.RequireClaim(ApplicationName, "Application User - Entry Level"));
            });

        services.Configure<IISOptions>(Options =>
            Options.AutomaticAuthentication = true);

        services.AddTransient<IClaimsTransformation, ClaimsTransformer>();

        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<IDDbContext>();`

I have tried these is several combinations but the IClaimsTransformation is never hit.

Any suggestions?

I was facing the same problem. I just move app.UseAuthentication(); before app.UseRouting(); and then TransformAsync was called without problem.

cc @HaoK can you take a look?

I was having the same problem, services.AddAuthentication(IISServerDefaults.AuthenticationScheme); worked for me.

.net core 3.0 defaults to InProcess hosting model, ctrl-f “When hosting in-process, AuthenticateAsync” at this link: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.2