docs: align auth model example with Identity layers #386

Merged
arnaud.dartois merged 1 commits from docs/auth-identity-model-385 into main 2026-11-13 11:09:20 +01:00
2 changed files with 21 additions and 9 deletions

No files matched your search

+19 -9
View File
@@ -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<Guid>
// Infrastructure/Identity/IdentityAppUser.cs
// La classe Identity et ses dépendances restent dans Infrastructure.
public sealed class IdentityAppUser : IdentityUser<Guid>
{
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<IdentityAppUser>().WithMany().HasForeignKey(us => us.UserId);
// Rôles prédéfinis
public static class AppRoles
{
+2
View File
@@ -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.