mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 10:04:44 +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.Repository;
|
||||||
using Features.Auth.Services;
|
using Features.Auth.Services;
|
||||||
using Infrastructure.PasswordHashing;
|
using Infrastructure.PasswordHashing;
|
||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Features.Auth.DependencyInjection;
|
namespace Features.Auth.DependencyInjection;
|
||||||
@@ -9,14 +11,43 @@ namespace Features.Auth.DependencyInjection;
|
|||||||
public static class FeaturesAuthServiceCollectionExtensions
|
public static class FeaturesAuthServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds <see cref="IAuthRepository" />, <see cref="ITokenService" />, and the Argon2 password hashing
|
/// Adds <see cref="IAuthRepository" />, <see cref="ITokenService" />, the Argon2 password hashing
|
||||||
/// infrastructure as scoped services.
|
/// infrastructure, and ASP.NET Core Identity (<see cref="UserManager{TUser}" /> backed by
|
||||||
|
/// <see cref="DapperUserStore" />) as scoped services.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static IServiceCollection AddFeaturesAuth(this IServiceCollection services)
|
public static IServiceCollection AddFeaturesAuth(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddScoped<IAuthRepository, AuthRepository>();
|
services.AddScoped<IAuthRepository, AuthRepository>();
|
||||||
services.AddScoped<ITokenService, TokenService>();
|
services.AddScoped<ITokenService, TokenService>();
|
||||||
services.AddScoped<IPasswordInfrastructure, Argon2Infrastructure>();
|
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;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user