I have a Blazor server application with Identity setup to utilize a SQL Server. Additionally I'm using IdentityManager2 to assist with ensuring the account/roles are setup and everything works properly everywhere except for AuthorizeView and Authorize.
First of all I'm signed in and the index lists my claims. Shown Here:
On my navmenu I have this section:
<AuthorizeView Policy="@Policies.IsAdmin">
<Authorized>
<li class="nav-item px-3">
<NavLink class="nav-link" href="admin/user/list">
<span class="oi oi-list-rich" aria-hidden="true"></span> Users
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="admin/company/list">
<span class="oi oi-list-rich" aria-hidden="true"></span> Companies
</NavLink>
</li>
</Authorized>
<NotAuthorized>
<div class="alert alert-danger">not auth</div>
</NotAuthorized>
</AuthorizeView>
Additionally I have a page called WaveRiders.razor that contains this line:
@attribute [Authorize(Policy = Policies.IsAdmin)]
Here is the code in my startup.cs
services.AddDbContext<SqlContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("SqlContextConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<SqlContext>();
services.AddAuthorizationCore(config =>
{
config.AddPolicy(Policies.IsAdmin, Policies.IsAdminPolicy());
config.AddPolicy(Policies.IsCompanyOwner, Policies.IsCompanyOwnerPolicy());
});
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();
So even though I am authenticated and I do belong to the Administrator group it appears I'm always unauthorized and my screen appears as:
I've worked on this issues for at least 10 hours and I'm at the end of trying. Does anyone see what is wrong with the code I provided?
Here is proof from IdentityManager that I belong to the roles: