dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.32k stars 9.97k forks source link

Split MapIdentityApi<TUser>() into multiple APIs and allow selective end points to be enabled #55792

Open VasuInukollu opened 4 months ago

VasuInukollu commented 4 months ago

Background and Motivation

The Identity API endpoints are a much need addition to Identity framework. The current API endpoint route implementation (IdentityApiEndpointRouteBuilderExtensions.cs) has a single API to add all/multiple endpoints to the pipeline.

It would great to have control on which endpoints will be available if we don't want to have some functionality in the application.

A way to allow individual API endpoints to be added will help in plenty of scenarios.

Proposed API

namespace Microsoft.AspNetCore.Routing;

public static class IdentityApiEndpointRouteBuilderExtensions
{

    public static IEndpointConventionBuilder MapIdentityApi<TUser>(this IEndpointRouteBuilder endpoints)

+    public static IEndpointConventionBuilder MapIdentityRegisterApi<TUser>(this IEndpointRouteBuilder endpoints)
+    public static IEndpointConventionBuilder MapIdentityLoginApi<TUser>(this IEndpointRouteBuilder endpoints)
+    public static IEndpointConventionBuilder MapIdentityRefreshApi<TUser>(this IEndpointRouteBuilder endpoints)

}

Usage Examples

We can add the required mapping for each endpoint.


app.MapIdentityLoginApi<IdentityUser>();
app.MapIdentityRefreshApi<IdentityUser>();

Alternative Designs

We have the option of adding the full code from this URL into the project and remove the unwanted parts. But that's not a great experience.

https://github.com/dotnet/aspnetcore/blob/main/src/Identity/Core/src/IdentityApiEndpointRouteBuilderExtensions.cs

Risks

Nothing that I can think of.

MackinnonBuck commented 4 months ago

Seems related to https://github.com/dotnet/aspnetcore/issues/55529