Implement Auth service — login, register, sessions, account properties, OAuth stubs
- auth.proto: add account property CRUD messages + OAuthProvider enum + LoginWithOAuth (all OAuth providers disabled via Redis feature flags: oauth_<provider>_enabled) - SOR.Auth: full AuthGrpcHandler — password auth, session tokens (32-byte random, SHA-256 hash in Postgres, raw token in Redis with TTL), ValidateToken with Redis fast-path + Postgres slow-path fallback, Logout with dual revocation - AccountProperty entity: flexible key-value bag per account (snake_case keys, string values); upsert semantics; indexed on (AccountId, Key) - SOR.Auth/ServiceRegistration: registers Identity DbContext + UserManager + roles - SOR.Host/appsettings.json: add Postgres Default connection string - AddAccountProperties migration applied to pg-forge-01 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
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 Auth service dependencies in the DI container.
|
||||
///
|
||||
/// STATUS: Foundation stub only.
|
||||
/// Real registration (DbContext, repositories, IAuthService) will be added
|
||||
/// when Auth business logic is implemented.
|
||||
///
|
||||
/// Currently only registers the gRPC infrastructure so the handler can be
|
||||
/// mapped in SOR.Host.Program.cs via app.MapGrpcService{AuthGrpcHandler}().
|
||||
/// 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
|
||||
{
|
||||
@@ -19,16 +17,27 @@ public static class ServiceRegistration
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
// AddGrpc() registers the gRPC server infrastructure in ASP.NET Core.
|
||||
// Required before MapGrpcService{T} can be called in Program.cs.
|
||||
// Safe to call multiple times — ASP.NET Core deduplicates registrations.
|
||||
// gRPC server infrastructure — required before MapGrpcService<AuthGrpcHandler>.
|
||||
services.AddGrpc();
|
||||
|
||||
// TODO (when implementing Auth business logic):
|
||||
// services.Configure<AuthOptions>(configuration.GetSection("Auth"));
|
||||
// services.AddDbContext<AuthDbContext>(opts => opts.UseNpgsql(...));
|
||||
// services.AddScoped<IAuthRepository, AuthRepository>();
|
||||
// services.AddScoped<IAuthService, AuthService>();
|
||||
// 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(15);
|
||||
options.Lockout.AllowedForNewUsers = true;
|
||||
})
|
||||
.AddRoles<IdentityRole<Guid>>()
|
||||
.AddEntityFrameworkStores<SorIdentityDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user