Ajout de l'authentification (compte unique, JWT, reset par email)

Application mono-utilisateur : inscription unique, connexion par JWT (12 h),
protection de toutes les routes de données, réinitialisation de mot de passe
par email avec repli de journalisation, onboarding réorganisé en deux étapes
(inscription → connexion → profil + véhicule).

Backend (SchotzIadKmTracker.Api) :
- Entités Compte (singleton) et ResetPasswordToken + migration AjoutAuthentification.
- Hachage PasswordHasher, JwtService (HS256, durée configurable), IEmailService
  (MailKit + repli LoggingEmailService selon Smtp:Host).
- AuthService (register 409 si compte existant, login 401 générique, forgot-password
  non-divulgation, reset à usage unique + expiration), AuthController (5 endpoints
  publics), DTOs + validateurs FluentValidation.
- Sécurité pipeline : JwtBearer + filtre d'autorisation global, UseAuthentication
  avant UseAuthorization ; /health et /api/auth/* publics.

Frontend (schotziad-km-tracker, zoneless + signals) :
- AuthService (localStorage), authInterceptor (Bearer + purge/redirection 401),
  authGuard, écrans Login/Register/ForgotPassword/ResetPassword, routes publiques
  et protection [authGuard, profilConfigureGuard].

Configuration : .env.example et docker-compose.yml (JWT__SecretKey, durées, Smtp__*).

Tests : 54 tests backend (propriétés FsCheck P1–P14, exemples, intégration
WebApplicationFactory) + tests frontend (AuthService, authGuard, authInterceptor,
ResetPasswordComponent). Suite complète au vert.

Spec : .kiro/specs/authentification (requirements, design, tasks).
This commit is contained in:
2026-09-14 09:07:08 +02:00
parent 0e6a97ca61
commit dd36bbc425
66 changed files with 6282 additions and 27 deletions
@@ -0,0 +1,49 @@
using FluentAssertions;
using FsCheck;
using FsCheck.Xunit;
using Microsoft.AspNetCore.Identity;
using SchotzIadKmTracker.Api.Models.Entities;
namespace SchotzIadKmTracker.Tests.Auth;
/// <summary>
/// Propriété de correction du hachage de mot de passe (feature authentification).
/// Utilise le PasswordHasher&lt;Compte&gt; réel d'ASP.NET Core Identity.
/// </summary>
public class PasswordHasherProperties
{
// Feature: authentification, Property 1: Pour tout mot de passe non vide, le hachage produit une
// valeur différente du clair, VerifyHashedPassword retourne Success, et deux hachages du même
// mot de passe diffèrent (présence de sel).
// Validates: Requirements 1.5, 8.1, 8.3
[Property(MaxTest = 100)]
public Property Le_hachage_est_verifiable_et_sale()
{
// Générateur de mots de passe non vides et bornés (1..64 caractères imprimables).
var arb = Arb.From(
Gen.Choose(1, 64)
.SelectMany(longueur =>
Gen.ArrayOf(longueur, Gen.Choose(33, 126).Select(c => (char)c))
.Select(chars => new string(chars))));
return Prop.ForAll(arb, motDePasse =>
{
var hasher = new PasswordHasher<Compte>();
var compte = new Compte { Id = 1, Email = "test@example.com" };
var hash1 = hasher.HashPassword(compte, motDePasse);
var hash2 = hasher.HashPassword(compte, motDePasse);
// Le hash diffère du clair.
hash1.Should().NotBe(motDePasse);
// La vérification réussit.
hasher.VerifyHashedPassword(compte, hash1, motDePasse)
.Should().BeOneOf(PasswordVerificationResult.Success,
PasswordVerificationResult.SuccessRehashNeeded);
// Deux hachages du même mot de passe diffèrent (sel aléatoire).
hash1.Should().NotBe(hash2);
});
}
}