ASP.NET Identity API in .NET 8
Somnath Shukla
Digital Transformation Expert | Intelligent Edge | IoT | Data & AI Specialist
I am fond of ASP.NET Identity and using it for Authentication(IDP) from very long times, have used it for multiple enterprise apps. This is out of box feature of .NET framework and tried and tested by Microsoft(Now Open source). One of the challenge I face with this feature is coupling of UI and API. In Case DMZ of NON DMZ I over come this feature by writing the custom API and hosting it in NON DMZ.
With .NET 8 Microsoft has released ASP.NET Identity API which supports Identity as api and now UI can be written in any SPA framework and independent of Database.
Now you can deploy this in any enterprise app without exposing your database to DMZ.
How to enable the ASP.NET Identity API
builder.Services.AddAuthorization();
// Add EF Core
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services
.AddIdentityApiEndpoints<AppUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<AppDbContext>();
app.MapGroup("/account").MapIdentityApi<AppUser>();
app.UseHttpsRedirection();
app.UseAuthorization();
app.Run();
Now you can integrate these API with any SPA UI framework.
Sample app: som-nitjsr/aspnetidentityapi (github.com)