title: Using Claims Transformation with Windows Authentication
body: <p>Using Windows Authentication in an ASP.NET Core 2.1 application. In the database we have a <code>User</code> table that stores users along with their Sid. It has a 1-1 relationship with <code>UserProfile</code> which has information I want to use for Claims.</p>
  
  <p>I added a this service for Claims Transformation:</p>
  
  <pre><code>public class UserStatusClaimsTransformation : IClaimsTransformation
  {
      private readonly MyDbContext _context;
  
      public UserStatusClaimsTransformation(MyDbContext context)
      {
          _context = context;
      }
  
      public async Task&lt;ClaimsPrincipal&gt; TransformAsync(ClaimsPrincipal principal)
      {
          if (principal.Identity is WindowsIdentity identity)
          {
              User user = await _context.User
                  .Include(u =&gt; u.UserProfile)
                  .Where(u =&gt; new SecurityIdentifier(u.WindowsSid, 0) == identity.User)
                  .SingleOrDefaultAsync();
  
              if (user != null)
              {
                  identity.AddClaim(new Claim("Status", user.UserProfile));
              }
          }
  
          return principal;
      }
  }
  </code></pre>
  
  <p>My issue is, once this service is registered, the <code>IPrincipal</code> accessed elsewhere in the pipeline is now a <code>ClaimsPrincipal</code> instead of a <code>WindowsPrincipal</code>. Example, in <code>MyDbContext</code> I inject <code>IPrincipal</code> via DI:</p>
  
  <pre><code>public MyDbContext(DbContextOptions&lt;MyDbContext&gt; options, IPrincipal principal) : base(options)
  {
      _principal = principal;
  }
  </code></pre>
  
  <p>Previously, this was a <code>WindowsPrincipal</code> and I could get the Username from <code>_principal.Identity.Name</code>, but after registering my Claims Transformer it is a <code>ClaimsPrincipal</code> and <code>_principal.Identity.Name</code> is null. Is there a way to keep the <code>IPrincipal</code> provided through DI as a <code>WindowsPrincipal</code> after using the Claims Transformation?</p>