henalbrod / Blazor.Auth0

The library for using Auth0 in Blazor applications.
https://github.com/henalbrod/Blazor.Auth0
MIT License
110 stars 29 forks source link

Clientside | Claims based #29

Closed indcoder closed 5 years ago

indcoder commented 5 years ago

In the previous version we had permissions appended before the claim. While following Example.Clientside, I have been testing the claims based fetch data. But I cannot see the permissions in the claims of the User Identity and hence the page is displayed the UnAuthorized message..

So while the example has @attribute [Authorize("read:weather_forecast")] , on the MS doc @attribute [Authorize( Policy = "read:weather_forecast")]

This was working for preview 8 codebase On the Auth0 dashboard , the relevant API had the RBAC enabled and the User has the Permission ["read:weather_forecast] set .

henalbrod commented 5 years ago

As you may notice, appending "permissions" before the claim name is not required anymore, so if this is the case please remove it.

options.AddPolicy("read:weather_forecast", policy => policy.RequireClaim("read:weather_forecast"));

For the example projects to run it is needed to have an API in Auth0 configured as follows:

image

Also, I recommend using the new Universal Login version, especially if you're testing against Google or Facebook:

image

henalbrod commented 5 years ago

Hi, any update regarding this issue?

indcoder commented 5 years ago

Hi @henalbrod , my Auth0 app already had RBAC enabled API since we tested this successfully with the preview 8 code. But I was iterating through the list of claims that was sent across but the permissions are not visible. I'm not sure if Auth0 is not sending them across or the Blazor.Auth0 is not displaying them.


if (user.Identity.IsAuthenticated)
        {
            // Since the user is a ClaimsPrincipal, you can also enumerate claims,
            // evaluate membership in roles, etc.
            Console.WriteLine($"Hello, {user.Identity.Name}");

            var claimsIdentity = (ClaimsIdentity)user.Identity;
            foreach(var claim in claimsIdentity.Claims)
            {
                Console.WriteLine($"User has {claim} claim");
            }

            currentCount++;
        }
indcoder commented 5 years ago

My bad. An error on my part during configuration

indcoder commented 5 years ago

My bad. An error on my part during configuration