title: Why does UserManager.GetUserAsync return null when using JWT?
body: <p>I have some issues with my .NET CORE 2.1 web api. Im using Identity framework and JWT-tokens for authentication, but whenever I try to get the current user in a controller I get a null reference error.</p>
  
  <p>All settings look fine from what I can see, and I've tried to manually set the key for Identity, but still getting the same error. Any ideas?</p>
  
  <p>Controller:</p>
  
  <pre><code>        var user = await _userManager.GetUserAsync(User);
  </code></pre>
  
  <p>Startup.cs:</p>
  
  <pre><code>    public void ConfigureServices(IServiceCollection services)
      {
        services.AddIdentity&lt;LoginUser, IdentityRole&gt;(options =&gt; {
              options.ClaimsIdentity.UserIdClaimType = 
              ClaimTypes.NameIdentifier;
              })
              .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;()
              .AddDefaultTokenProviders();
      }
  </code></pre>
  
  <p>Claims in token-generation:</p>
  
  <pre><code>        var claims = new List&lt;Claim&gt;
          {
              new Claim(JwtRegisteredClaimNames.Sub, user.Id),
              new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
              new Claim(JwtRegisteredClaimNames.Email, email),
              new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
          };
  </code></pre>