Issue
I am trying to leverage the AuthorizeView component in Blazor to hide/show different parts of the page based on a users role. I am using OIDC connected to OKTA as the auth provider.
By default, OKTA return the Roles scope as a Groups claim within the id_token. I have attempted to force authentication provider to look at the groups claim for the roles as seen in the code below.
My test account has the appropriate permissions, as I can see it within the Groups claim. I am unable to get this mapping to work.
Has anyone had any similar issues and/or found a solution to this?
Sample Code
-- Program.cs --
public static async Task Main(string[] args)
{
...
builder.Services.AddOidcAuthentication(options =>
{
options.ProviderOptions.Authority = "***";
options.ProviderOptions.ClientId = "***";
options.ProviderOptions.DefaultScopes.Add("roles");
options.ProviderOptions.ResponseType = "token id_token";
options.UserOptions.RoleClaim = "groups";
options.UserOptions.NameClaim = "name";
});
....
}
-- MyPage.razor --
<AuthorizeView Roles="Admin">
<Authorized>
Authorized
</Authorized>
<NotAuthorized>
Not Authorized
</NotAuthorized>
</AuthorizeView>