mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
Wire ASP.NET Core Identity DI alongside existing AuthRepository
Both stacks coexist until handlers are migrated one by one.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Features.Auth.Identity;
|
||||
using Features.Auth.Repository;
|
||||
using Features.Auth.Services;
|
||||
using Infrastructure.PasswordHashing;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Features.Auth.DependencyInjection;
|
||||
@@ -9,14 +11,43 @@ namespace Features.Auth.DependencyInjection;
|
||||
public static class FeaturesAuthServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds <see cref="IAuthRepository" />, <see cref="ITokenService" />, and the Argon2 password hashing
|
||||
/// infrastructure as scoped services.
|
||||
/// Adds <see cref="IAuthRepository" />, <see cref="ITokenService" />, the Argon2 password hashing
|
||||
/// infrastructure, and ASP.NET Core Identity (<see cref="UserManager{TUser}" /> backed by
|
||||
/// <see cref="DapperUserStore" />) as scoped services.
|
||||
/// </summary>
|
||||
public static IServiceCollection AddFeaturesAuth(this IServiceCollection services)
|
||||
{
|
||||
services.AddScoped<IAuthRepository, AuthRepository>();
|
||||
services.AddScoped<ITokenService, TokenService>();
|
||||
services.AddScoped<IPasswordInfrastructure, Argon2Infrastructure>();
|
||||
|
||||
services
|
||||
.AddIdentityCore<ApplicationUser>(options =>
|
||||
{
|
||||
options.User.RequireUniqueEmail = true;
|
||||
|
||||
// Password/username complexity is already enforced by RegisterUserValidator
|
||||
// (FluentValidation); disable Identity's own checks to avoid duplicated/drifting rules.
|
||||
options.Password.RequireDigit = false;
|
||||
options.Password.RequireLowercase = false;
|
||||
options.Password.RequireUppercase = false;
|
||||
options.Password.RequireNonAlphanumeric = false;
|
||||
options.Password.RequiredLength = 1;
|
||||
})
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
services.AddScoped<DapperUserStore>();
|
||||
services.AddScoped<IUserStore<ApplicationUser>>(sp =>
|
||||
sp.GetRequiredService<DapperUserStore>()
|
||||
);
|
||||
services.AddScoped<IUserEmailStore<ApplicationUser>>(sp =>
|
||||
sp.GetRequiredService<DapperUserStore>()
|
||||
);
|
||||
services.AddScoped<IUserPasswordStore<ApplicationUser>>(sp =>
|
||||
sp.GetRequiredService<DapperUserStore>()
|
||||
);
|
||||
services.AddScoped<IPasswordHasher<ApplicationUser>, Argon2PasswordHasher>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user