Ragtox
Ragtox
CC#
Created by Ragtox on 8/23/2024 in #help
Local user accounts with Entra External ID in Blazor WASM BFF application
Wow, how didn't I think of that lol, I was so pre-occupied with moving away from identity that I didn't consider just using Identity but not allowing local account sign-up. Thanks TeBeCo. However, I'm always interested in any other alternatives people have come up with!
4 replies
CC#
Created by Ragtox on 8/23/2024 in #help
Local user accounts with Entra External ID in Blazor WASM BFF application
Oh, I also forgot to mention that my current PoC uses the Microsoft.Identity.Web & Microsoft.Identity.Web.UI packages And also some sample code from how I currently use the OnTokenValidated event. (This is just a PoC of course, so not a lot of validation/fallback stuff is happening)
options.Events = new OpenIdConnectEvents()
{
// Perform logic to store user in database
// Should probably check if a claim is present, "newUser" or something
OnTokenValidated = async context =>
{
if (context.Principal != null)
{
try
{
var dbContext = context.Request.HttpContext.RequestServices.GetRequiredService<IdentityDbContext>();
var oid = context.Principal.FindFirst("oid")!.Value;
var idp = context.Principal.FindFirst("idp")?.Value ?? "";

var user = await dbContext.Users.FirstOrDefaultAsync(u => u.Id == oid);
if (user != null)
{
return;
}

var newUser = new User(oid, idp);

dbContext.Users.Add(newUser);
await dbContext.SaveChangesAsync();
}
catch
{
context.Fail("Something went wrong while persisting this user");
}
}
}
};
options.Events = new OpenIdConnectEvents()
{
// Perform logic to store user in database
// Should probably check if a claim is present, "newUser" or something
OnTokenValidated = async context =>
{
if (context.Principal != null)
{
try
{
var dbContext = context.Request.HttpContext.RequestServices.GetRequiredService<IdentityDbContext>();
var oid = context.Principal.FindFirst("oid")!.Value;
var idp = context.Principal.FindFirst("idp")?.Value ?? "";

var user = await dbContext.Users.FirstOrDefaultAsync(u => u.Id == oid);
if (user != null)
{
return;
}

var newUser = new User(oid, idp);

dbContext.Users.Add(newUser);
await dbContext.SaveChangesAsync();
}
catch
{
context.Fail("Something went wrong while persisting this user");
}
}
}
};
4 replies
CC#
Created by Ragtox on 1/8/2024 in #help
Create low-code / flow builder like application in .NET
That's a nice library, will check it out, thanks!
5 replies