48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
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;
|
|
|
|
/// <summary>
|
|
/// Registers all Auth service dependencies in the DI container.
|
|
/// Called from SOR.Host/Program.cs when ENABLED_SERVICES contains "auth".
|
|
/// </summary>
|
|
public static class ServiceRegistration
|
|
{
|
|
public static IServiceCollection AddAuthService(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
// gRPC server infrastructure — required before MapGrpcService<AuthGrpcHandler>.
|
|
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<Account>, password hashing, lockout, etc.
|
|
// SignInManager is not needed here — gRPC handlers validate credentials directly.
|
|
services.AddIdentityCore<Account>(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<IdentityRole<Guid>>()
|
|
.AddEntityFrameworkStores<SorIdentityDbContext>()
|
|
.AddDefaultTokenProviders();
|
|
|
|
return services;
|
|
}
|
|
}
|