Last active
June 6, 2024 09:02
-
-
Save dj-nitehawk/83a2a863a12f84e65fc4d565657c8673 to your computer and use it in GitHub Desktop.
Middleware setup for MS Identity API Endpoints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyDbContext(DbContextOptions<MyDbContext> opts) : IdentityDbContext<IdentityUser>(opts); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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