Skip to content

Instantly share code, notes, and snippets.

@dj-nitehawk
Last active June 6, 2024 09:02
Show Gist options
  • Save dj-nitehawk/83a2a863a12f84e65fc4d565657c8673 to your computer and use it in GitHub Desktop.
Save dj-nitehawk/83a2a863a12f84e65fc4d565657c8673 to your computer and use it in GitHub Desktop.
Middleware setup for MS Identity API Endpoints
public class MyDbContext(DbContextOptions<MyDbContext> opts) : IdentityDbContext<IdentityUser>(opts);
using FastEndpoints;
using FastEndpoints.Swagger;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
var bld = WebApplication.CreateBuilder(args);
bld.Services
.AddIdentityApiEndpoints<IdentityUser>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<MyDbContext>()
.Services
.AddDbContext<MyDbContext>(o => o.UseInMemoryDatabase("MyDatabase"))
.AddAuthorization()
.AddFastEndpoints()
.SwaggerDocument();
var app = bld.Build();
app.UseAuthentication()
.UseAuthorization();
app.MapGroup("/api").WithTags("Identity").MapIdentityApi<IdentityUser>();
app.UseFastEndpoints()
.UseSwaggerGen();
app.Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment