title: Connect a JWT to the User property in the Controller
body: <p>I have a Web API .NET Core 3.0 Service.  It gets a header that contains a JWT with claims.</p>
  
  <p>I added the following to <code>ConfigureServices</code> in Startup.cs to map my JWT to the .NET Core Authentication system:</p>
  
  <pre><code>services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
  .AddJwtBearer(configureOptions =&gt;
  {
      configureOptions.Events = new JwtBearerEvents()
      {
          OnMessageReceived = context =&gt;
          {
              context.Token = context.HttpContext.Request.Headers["X-JWT-Assertion"];
              return Task.CompletedTask;
          }
      };
  });
  </code></pre>
  
  <p>I also added <code>app.UseAuthentication();</code> to <code>Configure</code> in Startup.cs.</p>
  
  <p>I then fire up my service and call an HTTP GET operation on it.  When I do, I can see that the <code>context.Token</code> is set to my JWT.  If I take that JWT over to <a href="https://JWT.io" rel="nofollow noreferrer">https://JWT.io</a> it shows that it has many claims.</p>
  
  <p><strong>But a break point in the GET operation shows that <code>User.Claims</code> is empty.</strong>  What ever is needed to connect the JWT to the User is not happening.</p>
  
  <p>Here are variations that I have tried:</p>
  
  <ul>
  <li>Add <code>[Authorize]</code> above my controller:<br>
  <em>Result:</em> 401 Error: Unauthorized</li>
  <li>Add <code>[Authorize(JwtBearerDefaults.AuthenticationScheme)]</code> above my controller<br>
  <em>Result:</em> The AuthorizationPolicy named: 'Bearer' was not found.</li>
  <li>Add <code>services.AddAuthorization()</code> in ConfigureServices and <code>[Authorize]</code> above my controller<br>
  <em>Result:</em> 401 Error: Unauthorized</li>
  <li>Add <code>[Authorize(JwtBearerDefaults.AuthenticationScheme)]</code> above my controller and code below to ConfigureServices :  </li>
  </ul>
  
  <pre>    services.AddAuthorization(auth =>
      {
          auth.AddPolicy(JwtBearerDefaults.AuthenticationScheme, 
              new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build());
      });
  </pre>  
  
  <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>Result:</em> 401 Error: Unauthorized</p>
  
  <p>To be clear, I don't want to do any Authorization, but I read that adding it may be needed to map the claims to the user.</p>
  
  <p><strong>What do I need to do to get the User property (that is part of the Controller base class) to be populated with my claims?</strong></p>