U3 password-reset (backend): wachtwoord vergeten en opnieuw instellen

POST auth/forgot-password antwoordt altijd hetzelfde (202) en handelt de mail na het antwoord
af; POST auth/reset-password zet een nieuw wachtwoord met de link uit de mail. Alleen een
voltooide reset trekt alle refresh tokens in (en beeindigt eerdere access tokens via de
security stamp); het aanvragen raakt niets. Link eenmalig en tijdsbeperkt (standaard 60 minuten),
cooldown van 5 minuten per adres in het geheugen, beide endpoints onder de login-limiter.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 19:21:29 +01:00
co-authored by Claude Sonnet 5.5
parent 3cba2facb3
commit c8e23826c3
11 changed files with 901 additions and 9 deletions
@@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
using SlpModularCms.Core.Availability;
@@ -52,7 +54,9 @@ public static class ServiceCollectionExtensions
})
.AddRoles<ApplicationRole>()
.AddRoleManager<RoleManager<ApplicationRole>>()
.AddEntityFrameworkStores<ApplicationDbContext>();
.AddEntityFrameworkStores<ApplicationDbContext>()
// Needed for the password-reset token (stateless, single use through the security stamp).
.AddDefaultTokenProviders();
// 3. Auth & Identity Services
var jwtSettings = configuration.GetSection("JwtSettings").Get<JwtSettings>()
@@ -67,6 +71,21 @@ public static class ServiceCollectionExtensions
$"{InvitationSettings.SectionName}:ExpiryHours must be between 1 and {InvitationSettings.MaxExpiryHours}.")
.ValidateOnStart();
services.AddOptions<PasswordResetSettings>()
.Bind(configuration.GetSection(PasswordResetSettings.SectionName))
.Validate(
PasswordResetSettings.IsValid,
$"{PasswordResetSettings.SectionName}: TokenLifetimeMinutes must be 5..1440 and CooldownMinutes 1..60.")
.ValidateOnStart();
// The reset link lifetime is the data-protection token lifetime.
services.AddOptions<DataProtectionTokenProviderOptions>()
.Configure<IOptions<PasswordResetSettings>>((o, reset) => o.TokenLifespan = TimeSpan.FromMinutes(reset.Value.TokenLifetimeMinutes));
services.TryAddSingleton(TimeProvider.System);
services.TryAddSingleton(sp =>
new ResetCooldown(sp.GetRequiredService<TimeProvider>(), TimeSpan.FromMinutes(sp.GetRequiredService<IOptions<PasswordResetSettings>>().Value.CooldownMinutes)));
services.AddScoped<IPasswordResetService, PasswordResetService>();
services.AddSingleton<IPasswordResetDispatcher, BackgroundPasswordResetDispatcher>();
services.AddCmsEmail(configuration);
services.AddScoped<IAuthService, AuthService>();