title: User.FindFirst(ClaimTypes.NameIdentifier) doesn't retrieve anything when called from frontend (Angular)
body: <p>I'm facing a new problem - just like the title says. I'll managed to check where the problem happens but I can't resolve it. I'll start from the top.</p>
  
  <p>In the backend (ASP.NET 3.0) I have a class <code>AuthController</code> with login method it does look like that: </p>
  
  <pre><code>        [HttpPost("login")]
          public async Task&lt;IActionResult&gt; Login(LoginedUserDTO loginedUser)
          {
              var userToLogin = await _authService.Login(loginedUser.Username.ToLower(), loginedUser.Password);
  
              if (userToLogin is null)
                  return Unauthorized();
  
              var claims = new[]
              {
                  new Claim(ClaimTypes.NameIdentifier, userToLogin.Id.ToString()),
                  new Claim(ClaimTypes.Name, userToLogin.Username)
              };
  
              var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration.GetSection("AppSettings:Token").Value));
  
              var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);
  
              var tokenDescriptor = new SecurityTokenDescriptor
              {
                  Subject = new ClaimsIdentity(claims),
                  Expires = DateTime.Now.AddDays(1),
                  SigningCredentials = creds
              };
  
              var tokenHandler = new JwtSecurityTokenHandler();
  
              var token = tokenHandler.CreateToken(tokenDescriptor);
  
              return Ok(new
              {
                  token = tokenHandler.WriteToken(token)
              });
          }
  </code></pre>
  
  <p>Long story short it creates claims after the user was logged in - everything seems fine from the frontend site - the token is put in the LocalStorage on the browser after that.</p>
  
  <p>Now there's a method that causing trouble: </p>
  
  <pre><code>        [HttpPost]
          public async Task&lt;IActionResult&gt; CreateTicket(TicketBody ticketBody)
          {
              //var userId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
  
              if (ticketBody.CurrentUserId != Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
                  return Unauthorized();
  
              var ticket = await _ticketService.CreateTicket(ticketBody.Id, ticketBody.CurrentUserId);
  
              return new JsonResult(ticket);
          }
  </code></pre>
  
  <p>As you can see there's this method <code>User.FindFirst(ClaimTypes.NameIdentifier)</code> which should get the local token and find the user but it's not even starting or finding anything. The problem is rather weird because when I use the same method without Angular but using just only Postman and putting the exact same token just as in Angular - this very method with finding claim types to resolve if the user is a valid user is working perfectly. But when I'm trying to reach out this whole post method from the frontend the ClaimTypes thing isn't working at all.</p>
  
  <p>What am I missing? Something from the frontend side? But the methods from the frontend are rather simple. The userId from frontend is passed without problems to the post method - it breaks just when it has to get claims but as I said - when the same thing goes through postman it works. Might it be the problem that I'm not using [Authorize] over these methods? But when I do how should I change the frontend (or backend) so it could go through the [Authorize] from the Angular side - so far I wasn't sure what should I do.</p>
  
  <p>EDIT: As requested by @Papa Kojo - I am adding some frontend code which is relevent at the momemnt I suppose:</p>
  
  <p>Login method from frontend - token is added to the localStorage.</p>
  
  <pre><code>login(model: any) {
    return this.http.post(this.baseUrl + 'login', model)
      .pipe(
        map((response: any) =&gt; {
          const user = response;
          if (user) {
            localStorage.setItem('token', user.token);
            this.decodedToken = this.jwtHelper.decodeToken(user.token);
            console.log(this.decodedToken);
          }
        })
      );
  }
  </code></pre>
  
  <p>There's a little fragment of the code where post method is called, it's part of the paypal API. </p>
  
  <pre><code>onApprove: async (data, actions) =&gt; {
                const order = await actions.order.capture();
                this.paidFor = true;
                console.log(order);
                this.trackIdBody.id = this.trackObj.trackId;
                this.trackIdBody.currentUserId = this.authService.decodedToken.nameid;
                console.log(this.trackIdBody);
                this.http.post('http://localhost:5000/tickets/', this.trackIdBody).subscribe(response =&gt; {
                  console.log(response);
                }, error =&gt; {
                  console.log(error);
              });
  </code></pre>
  
  <p><code>this.trackIdBody</code> from above snippet is JSON with two values - it's being properly recived by the backend in the  HttpPost CreateTicket method.</p>
  
  <p>Maybe putting token into localStorage from the frontend side is not enough? But also these claims are beeing properly made in the login method from the backend side when the frontend calls it.</p>