Open
Description
Background and Motivation
To provide an abstraction of registering both authentication and authorization-related middlewares/services in an app with fewer lines of code and build on the foundation of automatically registering middlewares/services that we started in preview5, we would like to add extension methods for registering both authentication and authorization-related middlewares/services via one overload.
Proposed API
namespace Microsoft.Extensions.DependencyInjection;
public static class AuthServiceCollectionExtensions
{
public static IServiceCollection AddAuthenticationAndAuthorization(this IServiceCollection services);
public static IServiceCollection AddAuthenticationAndAuthorization(
this IServiceCollection services,
Action<AuthorizationOptions> configureAuthorizationOptions);
public static IServiceCollection AddAuthenticationAndAuthorization(
this IServiceCollection services,
Action<AuthenticationOptions> configureAuthenticationOptions);
public static IServiceCollection AddAuthenticationAndAuthorization(
this IServiceCollection services,
Action<AuthenticationOptions> configureAuthenticationOptions,
Action<AuthorizationOptions> configureAuthorizationOptions);
}
namespace Microsoft.AspNetCore.Builder;
public static class AuthAppBuilderExtensions
{
public static IApplicationBuilder UseAuthenticationAndAuthorization(this IApplicationBuilder app)
}
Usage Examples
Before
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthentication();
builder.Services.AddAuthorization();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
After
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthenticationAndAuthorization();
var app = builder.Build();
app.UseAuthenticationAndAuthorization();
After with Options
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthenticationAndAuthorization(options => {
options.DefaultScheme = "foobar";
});
var app = builder.Build();
app.UseAuthenticationAndAuthorization();