I have a blazor server app with one page
Index.razor
@page "/"<AuthorizeView Roles="sample_role"> You see this because you have the sample_role</AuthorizeView><p>Everyone sees this</p>Since sample_role does not exist in any Default Active Directory, I wrote a custom authentication provider to inject that role based on a database of existing users.
public class CustomAuth : ServerAutheticationProvider{ public override async Task<AuthenticationState> GetAuthenticationStateAsync() { var state = await base.GetAuthenticationStateAsync(); var currentUserId = state.User.Identity.Name; // now I fetch permissions for this user from a database bool userHasRole = Database.DoesRoleExistFor(currentUserId); if(userHasRole) { var sample_role = new Claim(ClaimTypes.Role, "sample_role"); var identity = new ClaimsIdentity(new Claim[] { sample_role }); state.User.AddIdentity(identity); NotifyAuthenticationStateChanged(Task.From(new AutheticationState(state.User))); } return state; }}I configured this class to be the default AuthenticationStateProvider in Startup.cs
services.AddScoped<AuthenticationStateProvider, CustomAuth>();All of the above works on my development machine where my machine is joined to a domain. The value for currentUserId is something like DOMAIN\USERNAME.
This code also works on my personal machine which is not part of any domain. The value for currentUserId in that case is COMPUTERNAME\USERNAME.
However, when I move my code to a production environment, with a different domain name, I get an exception:
Win32Exception: The trust relationship between the primary domain and the trusted domain failed.
When I change the line:
<AuthorizeView Roles="sample_role">To
<AuthorizeView>The code works, but I lose the ability to decide who gets to see what.
How can I solve this issue?