How do I get UserId from Keycloak using ASP.NET Web Api?

Currently I’m working on pet project.
I’ve already done configuring to Angular + ASP.NET Project. But I tried search for information on the internet, nothing but configuring your project to your realm and client-scopes, etc.
How to do I get userId like service, repo or api, to use it in controller to store and get some user wishlist, or get orders for example?

To do an authentication using JWT bearer Tokens in ASP.NET Web API, you need the Microsoft.AspNetCore.Authentication.JwtBearer package:

Annotate the controller class with [Authorize] attribute to secure all endpoints within the controller, e.g.

[Route("api/[controller]")]
[ApiController]
[Authorize]
public class MySuperDuperController : ControllerBase
{
//
}

Within your endpoint implementation methods, you can access a ClaimsPrincipal object using this.UserThis ClaimsPricipal object holds the claims released by Keycloak.

[HttpGet("")]
public async Task<ActionResult<IEnumerable<Object>>> GetSomething()
{
this.User.Claims
}