Not even the Id which holds the hash, this is so Mickey Mouse.
The userId (sub) is in the claims collection.
@page "/getuser"
@inject AuthenticationStateProvider authProvider
@attribute [Authorize]
<h3>GetUser</h3>
<div>
<ul>
@foreach (var claim in authState.User.Claims)
{
<li><b>@claim.Type</b>: @claim.Value</li>
}
</ul>
</div>
<div>
UserId = @(userId ?? "No sub found!")
</div>
@code {
private Models.WeatherForecast[] forecasts;
AuthenticationState authState;
private string userId;
protected override async Task OnInitializedAsync()
{
authState = await authProvider.GetAuthenticationStateAsync();
userId = authState.User.Claims.FirstOrDefault(c => c.Type == "sub").Value;
}
}
And since we are on the subject, I was expecting all the razor pages necessary to do CRUD against this Identity db to be available for me to use. I only have Login, Logout and Register. Where is the rest?
The identity server project contains the account related data and UI. If I recall it's the standard Identity Razor Page Class. Scaffold the pages you want if you need make changes to the code or just view the code. It might be a good idea to create a test project and scaffold Identity. I'm not sure if scaffold pages contains the CRUD you're looking for but the default Identity configuration exposes all the APIs. For example, adding a role to the Roles table. You'll have to write the UI bits yourself but the RoleManager API has everything you need to create and fetch roles from the DB.
It is up to you to write code if you want to manage accounts from the Blazor application. That UI does have account maintenance logic which makes sense because Identity Server manages accounts. Someone might have created a GitHub repo. Just do an internet search. You might get lucky. To roll your own, host Web API on the Identity Server then expose the logic via Web API. Copy Razor Page code paste it into an API action. You're only interested in the data not the Razor Page UI.