I have a component using auto render mode:
@attribute [RenderModeInteractiveAuto]
I inject the AuthenticationStateProvider
:
@inject Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider _auth
Now, in my code, if I do something like this:
var state = await _auth.GetAuthenticationStateAsync();
var user = state.User;
var isAdmin = user.IsInRole("admin");
When this is ran on the server, isAdmin
is true when my logged-in user is in the admin
role. However, on WASM, this is false. Plus, on the server side, the name claim correctly contains the user name whereas in WASM it contains the e-mail address.
Is this still a bug or do I have to tweak some settings to get the correct identity propagated?
Authentication in Blazor 8 WASM is performed by
PersistingServerAuthenticationStateProvider
on the server persisting the Identity using theUserInfo
class to the wasm client via itsPersistentAuthenticationStateProvider
I achieved this and forced everyone to be an "Administrator" for demonstration/testing purposes as follows:
Updated UserInfo to include Roles
On the server project update
PersistingServerAuthenticationStateProvider.cs
Just below these two lines
I added this to persist the role claims
Then in the client to create the ClaimsIdentity update
PersistentAuthenticationStateProvider.cs