namespace SOR.Auth; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using SOR.Database; using SOR.Database.Contexts; using SOR.Database.Entities.Identity; /// /// Registers all Auth service dependencies in the DI container. /// Called from SOR.Host/Program.cs when ENABLED_SERVICES contains "auth". /// public static class ServiceRegistration { public static IServiceCollection AddAuthService( this IServiceCollection services, IConfiguration configuration) { // gRPC server infrastructure — required before MapGrpcService. services.AddGrpc(); // ASP.NET Identity token providers depend on Data Protection services. services.AddDataProtection(); // Identity DbContext (identity schema: accounts, sessions, properties, roles…) services.AddIdentityDatabase(configuration); // ASP.NET Core Identity: UserManager, password hashing, lockout, etc. // SignInManager is not needed here — gRPC handlers validate credentials directly. services.AddIdentityCore(options => { options.Password.RequireDigit = true; options.Password.RequireUppercase = true; options.Password.RequireNonAlphanumeric = true; options.Password.RequiredLength = 12; options.Lockout.MaxFailedAccessAttempts = 5; options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.AllowedForNewUsers = true; }) .AddRoles>() .AddEntityFrameworkStores() .AddDefaultTokenProviders(); return services; } }