2
votes

Net core application. Through swagger I am authenticating against my web api app. I am sending JWT token in each request from swagger. This jwt token contains Azure user objectid. I want to retrieve it. I tried as below.

userId = _httpContextAccessor.HttpContext.User.Claims.First(i => i.Type == ClaimTypes.NameIdentifier).Value;

this is not giving me correct object identifier. I can see object identifier in my token as showed below.

jwt token

In below image there is object identifier but I am not able to retrieve it. Can someone help me on this? Any help would be appreciated. Thanks

1
Umm, change your claim type filter to get the other claim?juunas

1 Answers

2
votes

If you know the name of claim you look for, you can just use it instead of the ones defined in ClaimTypes class.

userId = _httpContextAccessor.HttpContext.User.Claims.First(i => i.Type == "CLAIM_NAME").Value;

The ClaimTypes class is not an enum, it just contains some predefined const string values.

enter image description here