C
C#2mo ago
IcyIme

✅ ClaimTypes.NameIdentifier not retruning id of current user

i want to get id of current user but ClaimTypes.NameIdentifier not working and i dont know why
@page "/profile"
@using System.Security.Claims
@using Microsoft.AspNetCore.Authorization
@using UniCademy.Client.Model
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize]

<PageTitle>Profile</PageTitle>

<h1>@name</h1>
<h2>@userId</h2>

@code {
private string name;
private string userId;

protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;

if (user.Identity.IsAuthenticated)
{
name = user.Identity.Name;
userId = user.FindFirst(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
}
else
{
name = "User not authenticated";
userId = "No ID";
}
}
}
@page "/profile"
@using System.Security.Claims
@using Microsoft.AspNetCore.Authorization
@using UniCademy.Client.Model
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize]

<PageTitle>Profile</PageTitle>

<h1>@name</h1>
<h2>@userId</h2>

@code {
private string name;
private string userId;

protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;

if (user.Identity.IsAuthenticated)
{
name = user.Identity.Name;
userId = user.FindFirst(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
}
else
{
name = "User not authenticated";
userId = "No ID";
}
}
}
13 Replies
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
IcyIme
IcyIme2mo ago
Yes i tried If you Want i will send you a git repo
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
IcyIme
IcyIme2mo ago
Yes But name identifier not
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
IcyIme
IcyIme2mo ago
Where I found the token?
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
IcyIme
IcyIme2mo ago
GitHub
GitHub - IcyIme/UniCademyProject
Contribute to IcyIme/UniCademyProject development by creating an account on GitHub.
IcyIme
IcyIme2mo ago
I sended the git repo
Anton
Anton2mo ago
put your token in jwt.io and see what's there the token is probably in a cookie and is sent with each request
IcyIme
IcyIme2mo ago
No description
IcyIme
IcyIme2mo ago
i founded but ist bearer token
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server