I added the new identity endpoint from .NET 8 with .MapIdentityApi().
How can I expand the "/register" and "/login" endpoint to allow the username to be passed? When I register a user the username is set as the email.
I expanded the IdentityUser with additional fields and migrated the classes to my MySQL database. That worked fine. All the endpoints stayed the same.
This is what I did. I took the source code @ https://github.com/dotnet/aspnetcore/blob/main/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs
I copied that and put it in my .NET 8 Api Application. Then I changed the line:
public static IEndpointConventionBuilder MapIdentityApi<TUser>(this IEndpointRouteBuilder endpoints)
to
public static IEndpointConventionBuilder MapCustomIdentityApi<TUser>(this IEndpointRouteBuilder endpoints)
There are a couple of references to the class name in the code that you'll need to update. Based on what end points you keep. I removed the register, which is one, the other is the confirm email.
Then I added/removed/customized the endpoints in there.
Then in Program.cs I called:
app.MapCustomIdentityApi<IdentityUser>();
Hopefully, you can take it from there and save the world!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With