Blazor WebAssembly Role-based Authorization - won't recognize JWT roles with Keycloak

Viewed 70

I'm having an issue with a Blazor WebAssembly app, and Keycloak. What's basically hapenning is, the <AuthorizeView> tags don't work when I specify roles with <AuthorizeView Roles="Role">. I have already configured Keycloak so the roles are brought into the JWT as first level objects, like so (corroborated with jwt.io):

{
  "...": "..."
  "role": "role1"
  "role": "role2"
  "role": "role3"
  "...": "..."
}

this should in theory allow Blazor to detect the role claims to apply them in razor pages, but it's not working. I tried several methods but I can't get this role detection working, it always falls back to <NotAuthorized>'s contents, like this test over here:

<AuthorizeView Context="QuestionsManagement" Roles="Recruiter">
   <Authorized>
      <li class="nav-item px-3">
         <NavLink class="nav-link" href="/selection-processes" Match="NavLinkMatch.All">
            <span class="oi oi-book" aria-hidden="true"></span> Manage Questions
         </NavLink>
      </li>
   </Authorized>
   <NotAuthorized>
      <li class="nav-item px-3">
         <NavLink class="nav-link" href="/selection-processes" Match="NavLinkMatch.All">
            <span class="oi oi-book" aria-hidden="true"></span> Test not authorized
         </NavLink>
      </li>
   </NotAuthorized>
</AuthorizeView>

What should I be paying attention to? What could be missing/misconfigured?

0 Answers
Related