-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Role claims guidance in standalone WASM w/Identity article #31045
Comments
It would be good with documentation similar to this: https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-identity-server?view=aspnetcore-7.0&tabs=visual-studio#name-and-role-claim-with-api-authorization A lot of hosted Blazor apps with individual user accounts use this. |
I also need some guidance on this. |
I'm mired in cross-link updates for the new 8.0 BWA sample app that just went up this morning. I think it will take a couple of days to get all of these link updates in place. I might be able to reach this at the end of the week, but I can't make any promises on it given the workload right now. If you need assistance for your own implementation in the meantime, we recommend the usual public support forums for discussing code ... If anything significantly delays my reaching this issue by the end of this week, I'll leave a comment here. |
I took a break from the snippet sample app work to START to get something in place for roles. Now, I say "start" because I think the PU is going to need to work on it. I ran into some PITA JSON serializer problems with an ordinary Anyway ... the basics of the approach should be sound and are a good way to get the ball rolling. The really good news thus far is that I'm also adding SEEDED DATA to the mix 🎉🕺💃🍻. NO more having to re-register a test user over and over ... and OVER 😠. I needed that because we want our user to be created with role claims for testing, so it fixes two needs in one shot ... test user(s) and test role claims. 🥁🥁🥁🥁🥁 plz ........ ... and cc: @adrianjcalvert on this, who asked on dotnet/blazor-samples#124 about it. |
Why limit this guidance to roles only? Roles are only one small subset of the many claims that a Blazor WASM client might need to use for authorization purposes. There was something like this in the Identity endpoints implementation before: group.MapGet("/manage/info", async Task<Results<Ok<InfoWithClaimsResponse>, ValidationProblem, NotFound>>
(ClaimsPrincipal claimsPrincipal, UserManager<GameStoreUser> userManager) =>
{
if (await userManager.GetUserAsync(claimsPrincipal) is not { } user)
{
return TypedResults.NotFound();
}
var email = await userManager.GetEmailAsync(user) ?? throw new NotSupportedException("Users must have an email.");
var response = new InfoResponse(
email,
await userManager.IsEmailConfirmedAsync(user),
claimsPrincipal.Claims.ToDictionary(c => c.Type, c => c.Value));
return TypedResults.Ok(response);
}) But it was removed for some security reasons (for which I would love more details). If this new example suggests returning the roles is OK, then we can also return all claims? Or is that not secure? |
AFAIK, all claims can be returned. I think Jeremy will say that it should be done like the PR does (or your example ☝️) from an API endpoint after authentication. I used the user's app.MapGet("/roles", (ClaimsPrincipal user) =>
{
if (user.Identity is not null && user.Identity.IsAuthenticated)
{
var identity = (ClaimsIdentity)user.Identity;
var roles = identity.FindAll(identity.RoleClaimType)
.Select(c =>
new
{
c.Issuer,
c.OriginalIssuer,
c.Type,
c.Value,
c.ValueType
});
return TypedResults.Json(roles);
}
return Results.Unauthorized();
}); ... and IDK if he'll want to do something different. I had trouble working with a We'll see how it plays out. As you see on the other issue, I'm more of HackRex™ 🦖 than a real security guru. I rely heavily on the product unit engineers to tell me when my code/remarks are going off the rails. |
Description
Add some basic guidance for the front-end (web API call) and setting up the web API on the backend with some dummy claims sent down. Then, the dev will merely need to flesh out the web API side given their user data store.
dotnet/blazor-samples#124 (comment)
Page URL
https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/standalone-with-identity?view=aspnetcore-8.0
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/security/webassembly/standalone-with-identity.md
Document ID
c4e6ec41-7bea-e600-6473-c5c870aab082
Article author
guardrex
The text was updated successfully, but these errors were encountered: