C
C#13mo ago
BakaPresident

❔ Getting Identity from [Authorize]

Hey there, since i'm using [Authorize] i thought i should be able to get UserID from var userId = HttpContext.User.FindFirstValue("nameid"); But userId keeps returning null. For context, this is how i build the claims in my AuthService
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Sub, user.Email),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Email, user.Email),
new Claim(JwtRegisteredClaimNames.NameId, user.Id)
}.Union(roleClaims).Union(userClaims);
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Sub, user.Email),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.Email, user.Email),
new Claim(JwtRegisteredClaimNames.NameId, user.Id)
}.Union(roleClaims).Union(userClaims);
2 Replies
JakenVeina
JakenVeina13mo ago
which one of those claims is the user ID you want?
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.