title: MacOS development in ASP.NET Core 3.1 on Rider: Windows Authentication
body: <p>I recently switched from a Windows machine with Visual Studio to a MacBook with Rider. I have a .NET Core 3.1 project that I upgraded from .NET Framework 4.7.2, and I am trying to configure Windows Authentication for it. </p>
  
  <p>My MacBook is connected to a company domain via Enterprise Connect, and I have active kerboros tickets. AKA, I am able to access company resources that use Windows Authentication or otherwise pull my domain credentials. For example, I can login to the published version of my project which runs on IIS and .NET Framework 4.7.2. </p>
  
  <p>However, I am not able to use Windows Authentication when I run the .NET Core 3.1 version locally. I have made the following changes to my project:</p>
  
  <p>In <code>StartUp.cs</code>, added the following to <code>ConfigureServices</code>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
  services.AddAuthorization(options =&gt;
  {
      options.AddPolicy(nameof(Policy.AuthorizedUser), 
          policy =&gt; policy.Requirements.Add(new AuthorizedUserRequirement()));
  });
  
  services.AddSingleton&lt;IAuthorizationHandler, AuthorizedUserHandler&gt;();
  </code></pre>
  
  <p>In <code>StartUp.cs</code>, added the following to <code>Configure</code>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>app.UseAuthentication();
  app.UseAuthorization();
  </code></pre>
  
  <p>I did install the <code>Microsoft.AspNetCore.Authenticate.Negotiate</code> package.</p>
  
  <p>Created the Authorization handler and requirement:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class AuthorizedUserHandler: AuthorizationHandler&lt;AuthorizedUserRequirement&gt;
  {
      private readonly AuthorizationConfiguration _configuration;
  
      public AuthorizedUserHandler(AuthorizationConfiguration configuration)
      {
          _configuration = configuration;
      }
  
      protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, AuthorizedUserRequirement requirement)
      {
          if (context.User.IsInRole(_configuration.User.Group))
          {
              // Call 'Succeed' to mark current requirement as passed
              context.Succeed(requirement);
          }
  
          return Task.CompletedTask;
      }
  }
  </code></pre>
  
  <pre class="lang-cs prettyprint-override"><code>public class AuthorizedUserRequirement: IAuthorizationRequirement { }
  </code></pre>
  
  <p>Then, I apply it to my controller to restrict access:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[Authorize(Policy = nameof(Policy.AuthorizedUser))]
  public class CustomerController : Controller
  {
  }
  </code></pre>
  
  <p>My configuration object is correctly injected. However, <code>context.User</code> is empty. When I debug my project and go to a page that uses this policy (in Google Chrome), I get the HTTP ERROR 401 default error page from Google Chrome.</p>
  
  <p>How can I modify my code to fix this error, or otherwise setup Windows Authentication for local debugging on MacOS? I also tried using the Windows Authentication schema in <code>services.AddAuthentication</code> but that also failed.</p>