title: How to get Identity User from his authentication JWT token in .Net Core API?
body: <p>I'm using <strong>.Net Core</strong> for my API, so no views or whatsoever. I'm also using <strong>ASP.net Core Identity</strong> framework to authorize users in my database.
  For logging in users, I use this code:</p>
  
  <pre><code>private string GenerateAuthenticationResult(ApplicationUser user)
          {
              var tokenHandler = new JwtSecurityTokenHandler();
              var key = Encoding.ASCII.GetBytes(_jwtSettings.Secret);
              var tokenDescriptor = new SecurityTokenDescriptor
              {
                  // Things to be included and encoded in the token
                  Subject = new ClaimsIdentity(new[]
                  {
                      new Claim(JwtRegisteredClaimNames.Sub, user.Email),
                      new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                      new Claim(JwtRegisteredClaimNames.Email, user.Email),
                      new Claim("id", user.Id)
                  }),
                  // Token will expire 2 hours from which it was created
                  Expires = DateTime.UtcNow.AddHours(2),
                  //
                  SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
              };
  
              var token = tokenHandler.CreateToken(tokenDescriptor);
  
              return tokenHandler.WriteToken(token);
          }
  </code></pre>
  
  <p>This works like a charm for authenticating user actions, but how can I know whom my server is talking to provided that the user used the token I provided earlier for logging in in his request header (Bearer).</p>
  
  <p><strong>TL;dr</strong></p>
  
  <p>I want to extract user ID or user Email from the token provided in the request header.</p>
  
  <p>Thanks.</p>