From 9fc897d946b122e52edf869b3e5635fb469c8f25 Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Fri, 13 Nov 2026 11:08:03 +0100 Subject: [PATCH] docs: align auth model example with Identity layers (#385) --- docs/auth-roles.md | 28 +++++++++++++++++++--------- skills/heimdall-identity/SKILL.md | 2 ++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/docs/auth-roles.md b/docs/auth-roles.md index b8798e9..ff63446 100644 --- a/docs/auth-roles.md +++ b/docs/auth-roles.md @@ -34,26 +34,36 @@ Voir la matrice de permissions et la section sur `ICameraAccessService` ci-desso ## 2. Modèle de données ```csharp -// IdentityUser de base — pas de modification -public class User : IdentityUser +// Infrastructure/Identity/IdentityAppUser.cs +// La classe Identity et ses dépendances restent dans Infrastructure. +public sealed class IdentityAppUser : IdentityUser { public string DisplayName { get; set; } = string.Empty; - public ThemeMode Theme { get; set; } = ThemeMode.Auto; + public string? Theme { get; set; } = "Auto"; public string Language { get; set; } = "fr"; - public bool TwoFactorEnabled { get; set; } = false; // TOTP public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + public bool MustChangePassword { get; set; } } -// Relation User → Sites (N-N) +// Domain/Entities/UserSite.cs — aucune navigation vers le type Identity. public class UserSite { - public Guid UserId { get; set; } - public User User { get; set; } = null!; + public Guid UserId { get; private set; } + public Guid SiteId { get; private set; } + public Site Site { get; private set; } = null!; - public Guid SiteId { get; set; } - public Site Site { get; set; } = null!; + private UserSite() { } // EF Core + + public UserSite(Guid userId, Guid siteId) + { + UserId = userId; + SiteId = siteId; + } } +// Infrastructure/Data/Configurations/UserSiteConfiguration.cs — relation seulement. +builder.HasOne().WithMany().HasForeignKey(us => us.UserId); + // Rôles prédéfinis public static class AppRoles { diff --git a/skills/heimdall-identity/SKILL.md b/skills/heimdall-identity/SKILL.md index b997c8d..c3cc402 100644 --- a/skills/heimdall-identity/SKILL.md +++ b/skills/heimdall-identity/SKILL.md @@ -9,6 +9,8 @@ Read `AGENTS.md`, the focused Gitea issue and [the Gitea ticket workflow](../git When maintaining `docs/auth-roles.md`, verify its role names and default permission summaries against `Infrastructure/Security/AppPermissions.cs` and `Domain/Enums/UserRole.cs`. Heimdall has `Admin`, `Supervisor`, and `Viewer`; site/camera access is separately enforced through resource-access services, not represented by a generic `User` role. Keep the authentication summary in `docs/README.md` aligned with that guide and model. +Verify identity model examples against `Infrastructure/Identity/IdentityAppUser.cs`, `Domain/Entities/UserSite.cs`, and `Infrastructure/Data/Configurations/UserSiteConfiguration.cs`. Keep ASP.NET Identity in Infrastructure; `UserSite` stores the user ID without an Identity navigation, and Infrastructure maps that foreign key. + - Identity owns password hashing, normalized account lookup, role membership, lockout, authenticator tokens, and email/password tokens. Do not duplicate password or token cryptography in Heimdall. - Keep ASP.NET Core Identity packages and types inside Infrastructure. Domain must not reference Identity; Application uses `IIdentityAccountService` and `IdentityAccount` only. Put Identity EF entities (`IdentityAppUser`, `IdentityAppRole`) and `UserManager`/`RoleManager` adapters in Infrastructure. Keep user-related Domain relationships keyed by `Guid UserId`; configure their foreign keys to the Infrastructure user entity. - When creating an Identity user, copy the generated `SecurityStamp` back into the application account before building the first session/JWT. Cover bootstrap and regular user creation with a relational session validation test.