| | | 1 | | namespace ArturRios.Heimdall.Command.Services; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Settings for password reset token issuance (UC-12, FR-PR-02). <see cref="TokenLifetime" /> is |
| | | 5 | | /// read from the environment (seconds) with a one-hour default — far shorter than the |
| | | 6 | | /// verification token's day, since this one is what stands between an intercepted mailbox and a |
| | | 7 | | /// changed password. |
| | | 8 | | /// </summary> |
| | | 9 | | public class PasswordResetOptions |
| | | 10 | | { |
| | | 11 | | private const string LifetimeVariable = "HEIMDALL_PASSWORD_RESET_TOKEN_EXPIRATION_IN_SECONDS"; |
| | | 12 | | private const double DefaultLifetimeSeconds = 3600; |
| | | 13 | | |
| | 1952 | 14 | | public TimeSpan TokenLifetime { get; init; } = TimeSpan.FromSeconds(DefaultLifetimeSeconds); |
| | | 15 | | |
| | | 16 | | public static PasswordResetOptions FromEnvironment() |
| | | 17 | | { |
| | 899 | 18 | | var seconds = double.TryParse(Environment.GetEnvironmentVariable(LifetimeVariable), out var configured) |
| | 899 | 19 | | ? configured |
| | 899 | 20 | | : DefaultLifetimeSeconds; |
| | | 21 | | |
| | 899 | 22 | | return new PasswordResetOptions { TokenLifetime = TimeSpan.FromSeconds(seconds) }; |
| | | 23 | | } |
| | | 24 | | } |