<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mindattic.com/wiki/docs/index.php?action=history&amp;feed=atom&amp;title=MindAttic.Authentication%2FAPI</id>
	<title>MindAttic.Authentication/API - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mindattic.com/wiki/docs/index.php?action=history&amp;feed=atom&amp;title=MindAttic.Authentication%2FAPI"/>
	<link rel="alternate" type="text/html" href="https://mindattic.com/wiki/docs/index.php?title=MindAttic.Authentication/API&amp;action=history"/>
	<updated>2026-12-05T10:23:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.3</generator>
	<entry>
		<id>https://mindattic.com/wiki/docs/index.php?title=MindAttic.Authentication/API&amp;diff=539&amp;oldid=prev</id>
		<title>Docs Sync: md2wiki: sync from MindAttic.Docs</title>
		<link rel="alternate" type="text/html" href="https://mindattic.com/wiki/docs/index.php?title=MindAttic.Authentication/API&amp;diff=539&amp;oldid=prev"/>
		<updated>2026-11-29T20:25:16Z</updated>

		<summary type="html">&lt;p&gt;md2wiki: sync from MindAttic.Docs&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= MindAttic.Authentication — Public API Reference =&lt;br /&gt;
&lt;br /&gt;
Exhaustive reference for every public type the library exposes (namespace &amp;lt;code&amp;gt;MindAttic.Authentication.*&amp;lt;/code&amp;gt;). For the &amp;lt;em&amp;gt;why&amp;lt;/em&amp;gt; behind each control see [[MindAttic.Authentication/SECURITY_SPEC|&amp;lt;code&amp;gt;SECURITY_SPEC.md&amp;lt;/code&amp;gt;]]; for wiring see [[MindAttic.Authentication/INTEGRATION|&amp;lt;code&amp;gt;INTEGRATION.md&amp;lt;/code&amp;gt;]]; for config keys see [[MindAttic.Authentication/CONFIGURATION|&amp;lt;code&amp;gt;CONFIGURATION.md&amp;lt;/code&amp;gt;]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;lt;strong&amp;gt;Versioning:&amp;lt;/strong&amp;gt; major-version-only. The assembly/package version is &amp;lt;code&amp;gt;4.0.0&amp;lt;/code&amp;gt;; the next release is &amp;lt;code&amp;gt;6.0.0&amp;lt;/code&amp;gt; — never a minor or patch bump. The frozen behaviors below only change across a major bump. See [[MindAttic.Authentication/VERSIONING|&amp;lt;code&amp;gt;VERSIONING.md&amp;lt;/code&amp;gt;]].&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1. Constants — &amp;lt;code&amp;gt;MindAttic.Authentication&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;public static class MaClaims {&lt;br /&gt;
    public const string UserId        = &amp;quot;ma:uid&amp;quot;;&lt;br /&gt;
    public const string SecurityStamp = &amp;quot;ma:stamp&amp;quot;;&lt;br /&gt;
    public const string SessionId     = &amp;quot;ma:sid&amp;quot;;&lt;br /&gt;
    public const string Amr           = &amp;quot;amr&amp;quot;;        // &amp;quot;pwd&amp;quot;, &amp;quot;mfa&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
public static class MaRoles    { public const string Admin = &amp;quot;Admin&amp;quot;; }&lt;br /&gt;
public static class MaPolicies { public const string Admin = &amp;quot;ma:admin&amp;quot;; }   // RequireRole(Admin) + RequireClaim(amr,&amp;quot;mfa&amp;quot;)&lt;br /&gt;
public static class MaSchemes  {&lt;br /&gt;
    public const string Cookie     = &amp;quot;MindAttic.Auth&amp;quot;;&lt;br /&gt;
    public const string MfaPending = &amp;quot;MindAttic.MfaPending&amp;quot;;   // short-lived, pre-MFA, grants no app access&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 2. Options — &amp;lt;code&amp;gt;MindAttic.Authentication.Options&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type&lt;br /&gt;
! Bound from&lt;br /&gt;
! Key members (defaults)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AuthCryptoOptions&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;MindAttic:Auth:Crypto&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;MemoryKiB=65536&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Iterations=3&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Parallelism=4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SaltBytes=16&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HashBytes=32&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MinPasswordChars=12&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MaxPasswordChars=128&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CurrentPepperKeyId=&amp;quot;v1&amp;quot;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MaxConcurrentHashes=0&amp;lt;/code&amp;gt; (⇒ &amp;lt;code&amp;gt;ProcessorCount&amp;lt;/code&amp;gt;). &amp;lt;code&amp;gt;ValidateOrThrow()&amp;lt;/code&amp;gt; enforces OWASP floors at startup. Floor consts: &amp;lt;code&amp;gt;Floor*&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MfaOptions&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;MindAttic:Auth:Mfa&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;Issuer=&amp;quot;MindAttic&amp;quot;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Digits=6&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PeriodSeconds=30&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;WindowSteps=1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SecretBytes=20&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RecoveryCodeCount=10&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RecoveryCodeBytes=10&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PendingEnrollmentMinutes=10&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RequireForAdmin=true&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AuthPolicyOptions&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;MindAttic:Auth:Policy&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;MinLength=12&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MaxLength=128&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CheckHibp=true&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HibpRangeBaseUrl&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HibpTimeoutMs=2000&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HibpFailOpen=true&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HistoryDepth=5&amp;lt;/code&amp;gt;. Const &amp;lt;code&amp;gt;HibpHttpClient&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AuthSessionOptions&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;MindAttic:Auth:Session&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;AbsoluteTimeout=8h&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;IdleTimeout=30m&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RevalidationInterval=1m&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MindAtticAuthOptions&amp;lt;/code&amp;gt;&lt;br /&gt;
| (host code)&lt;br /&gt;
| &amp;lt;code&amp;gt;AppName=&amp;quot;App&amp;quot;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ConfigureAdditionalPolicies&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ConfigureDataProtection&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DevKeyRingPath&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;IsProduction&amp;lt;/code&amp;gt;.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== 3. Secrets — &amp;lt;code&amp;gt;MindAttic.Authentication.Secrets&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;public interface IAuthSecrets {&lt;br /&gt;
    string  GetRequired(string name);       // throws if blank — fail-closed&lt;br /&gt;
    string? GetOptional(string name);&lt;br /&gt;
    byte[]  GetRequiredBytes(string name);  // base64-decoded&lt;br /&gt;
}&lt;br /&gt;
public sealed class ConfigAuthSecrets : IAuthSecrets {  // reads MindAttic:Vault:Security:&amp;amp;lt;name&amp;gt;, caches&lt;br /&gt;
    public const string SectionPath = &amp;quot;MindAttic:Vault:Security&amp;quot;;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Required secrets: &amp;lt;code&amp;gt;pepper.v1&amp;lt;/code&amp;gt; (≥32 random bytes, base64), &amp;lt;code&amp;gt;bootstrap-token&amp;lt;/code&amp;gt; (≥12 chars). Reserved: &amp;lt;code&amp;gt;dp-kek&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;reset-token-key&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;captcha-secret&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== 4. Crypto — &amp;lt;code&amp;gt;MindAttic.Authentication.Crypto&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;public readonly record struct PasswordHash(string Phc, string PepperKeyId);&lt;br /&gt;
public readonly record struct PasswordVerifyResult(bool Succeeded, bool NeedsRehash);&lt;br /&gt;
&lt;br /&gt;
public interface IPasswordHasher {&lt;br /&gt;
    PasswordHash Hash(string password);&lt;br /&gt;
    PasswordVerifyResult Verify(string password, string storedHash, string? pepperKeyId, string? legacyScheme);&lt;br /&gt;
    void VerifyDecoy(string password);      // uniform-cost no-op for absent users&lt;br /&gt;
}&lt;br /&gt;
public sealed class Argon2idPasswordHasher : IPasswordHasher, IDisposable { }&lt;br /&gt;
&lt;br /&gt;
public readonly record struct PhcArgon2(int Version, int MemoryKiB, int Iterations, int Parallelism, byte[] Salt, byte[] Hash) {&lt;br /&gt;
    public string Encode();&lt;br /&gt;
    public static bool TryParse(string? s, out PhcArgon2 result);&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PHC format: &amp;lt;code&amp;gt;$argon2id$v=19$m=65536,t=3,p=4$&amp;amp;lt;b64salt&amp;gt;$&amp;amp;lt;b64hash&amp;gt;&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;legacyScheme&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;&amp;quot;bcrypt&amp;quot;&amp;lt;/code&amp;gt; &amp;amp;#124; &amp;lt;code&amp;gt;&amp;quot;sha256&amp;quot;&amp;lt;/code&amp;gt; &amp;amp;#124; &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== 5. Entities — &amp;lt;code&amp;gt;MindAttic.Authentication.Entities&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;AuthUser&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AuthUserMfa&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AuthRecoveryCode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AuthSession&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AuthLoginThrottle&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AuthAuditLog&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AuthPasswordHistory&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AuthPasswordResetToken&amp;lt;/code&amp;gt; (full column lists in [[MindAttic.Authentication/SECURITY_SPEC|&amp;lt;code&amp;gt;SECURITY_SPEC.md&amp;lt;/code&amp;gt;]] §&amp;quot;EF Schema&amp;quot;). Enums:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;public enum ThrottleScope : byte { Account = 0, Ip = 1 }&lt;br /&gt;
public enum AuthEventType : byte { Login, Register, PasswordReset, MfaChallenge, ChangePassword,&lt;br /&gt;
                                   MfaEnroll, RecoveryUsed, RecoveryRegen, MfaDisabled, MfaOperatorReset,&lt;br /&gt;
                                   HibpOnlineSkipped, Logout }&lt;br /&gt;
public enum AuthOutcome   : byte { Success, Failure, Throttled, StepUpRequired }&lt;br /&gt;
public enum AuthReasonCode: byte { Ok, UnknownUser, BadPassword, Locked, Unverified,&lt;br /&gt;
                                   MfaRequired, MfaBad, Disabled, TokenInvalid, PolicyRejected }   // server-only&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 6. Data — &amp;lt;code&amp;gt;MindAttic.Authentication.Data&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;public interface IAuthDataContext {                 // the app&amp;#039;s DbContext implements this&lt;br /&gt;
    DbSet&amp;amp;lt;AuthUser&amp;gt; AuthUsers { get; }&lt;br /&gt;
    DbSet&amp;amp;lt;AuthUserMfa&amp;gt; AuthUserMfa { get; }&lt;br /&gt;
    DbSet&amp;amp;lt;AuthRecoveryCode&amp;gt; AuthRecoveryCodes { get; }&lt;br /&gt;
    DbSet&amp;amp;lt;AuthSession&amp;gt; AuthSessions { get; }&lt;br /&gt;
    DbSet&amp;amp;lt;AuthLoginThrottle&amp;gt; AuthLoginThrottles { get; }&lt;br /&gt;
    DbSet&amp;amp;lt;AuthAuditLog&amp;gt; AuthAuditLog { get; }&lt;br /&gt;
    DbSet&amp;amp;lt;AuthPasswordHistory&amp;gt; AuthPasswordHistory { get; }&lt;br /&gt;
    DbSet&amp;amp;lt;AuthPasswordResetToken&amp;gt; AuthPasswordResetTokens { get; }&lt;br /&gt;
    Task&amp;amp;lt;int&amp;gt; SaveChangesAsync(CancellationToken ct = default);&lt;br /&gt;
}&lt;br /&gt;
public static class AuthModel {&lt;br /&gt;
    public const string DefaultSchema = &amp;quot;auth&amp;quot;;&lt;br /&gt;
    public const string ModelFingerprint = &amp;quot;auth-v2&amp;quot;;&lt;br /&gt;
    public const string OrganizationModelFingerprint = &amp;quot;auth-org-v1&amp;quot;;&lt;br /&gt;
    public static ModelBuilder ApplyMindAtticAuthConfiguration(this ModelBuilder b, string schema = DefaultSchema, bool organizations = false);&lt;br /&gt;
    public static ModelBuilder ApplyMindAtticOrganizationConfiguration(this ModelBuilder b, string schema = DefaultSchema);   // opt-in&lt;br /&gt;
}&lt;br /&gt;
public interface IOrganizationDataContext : IAuthDataContext {   // opt-in (docs/ORGANIZATIONS.md)&lt;br /&gt;
    DbSet&amp;amp;lt;AuthOrganization&amp;gt; AuthOrganizations { get; }&lt;br /&gt;
    DbSet&amp;amp;lt;AuthMembership&amp;gt; AuthMemberships { get; }&lt;br /&gt;
    DbSet&amp;amp;lt;AuthOrganizationAudit&amp;gt; AuthOrganizationAudit { get; }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Opt-in organizations (8.0.0): &amp;lt;code&amp;gt;AddMindAtticOrganizations&amp;amp;lt;TContext&amp;gt;(config, configure?)&amp;lt;/code&amp;gt; registers &amp;lt;code&amp;gt;IOrganizationService&amp;lt;/code&amp;gt; (create organization, add / set role / remove / restore member, &amp;lt;code&amp;gt;MembershipsOfAsync&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MembersAsync&amp;lt;/code&amp;gt;) and &amp;lt;code&amp;gt;OrganizationClaimsAugmentor&amp;lt;/code&amp;gt; (one membership claim per active membership, &amp;lt;code&amp;gt;{organizationId:N}&amp;amp;#124;{role}&amp;lt;/code&amp;gt;, plus &amp;lt;code&amp;gt;ma:omfa&amp;lt;/code&amp;gt; when a held role requires MFA). Invitations (9.0.0): &amp;lt;code&amp;gt;IInvitationService&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;InviteAsync&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;InviteBulkCsvAsync&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ResendAsync&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;RevokeAsync&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ListAsync&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PreviewAsync&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AcceptAsync&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AcceptExistingAsync&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;AuthInvitationOptions&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;IAuthEmailSender.SendInvitationAsync&amp;lt;/code&amp;gt;, component &amp;lt;code&amp;gt;MaAcceptInvitation&amp;lt;/code&amp;gt;, endpoints &amp;lt;code&amp;gt;/_ma-auth/invite/accept&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/accept-existing&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;DbSet&amp;amp;lt;AuthInvitation&amp;gt; AuthInvitations&amp;lt;/code&amp;gt; joins &amp;lt;code&amp;gt;IOrganizationDataContext&amp;lt;/code&amp;gt;. Options: &amp;lt;code&amp;gt;AuthOrganizationOptions&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;OwnerRole&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Roles&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MfaRequiredRoles&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MembershipClaimType&amp;lt;/code&amp;gt;). Details: [[MindAttic.Authentication/ORGANIZATIONS|ORGANIZATIONS.md]].&lt;br /&gt;
&lt;br /&gt;
== 7. Services — &amp;lt;code&amp;gt;MindAttic.Authentication.Services&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;public enum LoginStatus { Success, MfaRequired, Failed }&lt;br /&gt;
public sealed record LoginResult(LoginStatus Status, Guid? UserId = null, IReadOnlyList&amp;amp;lt;Claim&amp;gt;? Claims = null);&lt;br /&gt;
public interface IAuthenticationService {&lt;br /&gt;
    Task&amp;amp;lt;LoginResult&amp;gt; LoginAsync(string userName, string password, string sourceIp, string userAgent, CancellationToken ct = default);&lt;br /&gt;
    Task&amp;amp;lt;LoginResult&amp;gt; ConfirmMfaAsync(Guid userId, string code, bool isRecoveryCode, string sourceIp, string userAgent, CancellationToken ct = default);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public readonly record struct ThrottleDecision(bool Allowed, TimeSpan RetryAfter);&lt;br /&gt;
public interface IAccountLockoutService {&lt;br /&gt;
    Task&amp;amp;lt;ThrottleDecision&amp;gt; CheckAsync(ThrottleScope scope, string rawKey, CancellationToken ct = default);&lt;br /&gt;
    Task RecordFailureAsync(ThrottleScope scope, string rawKey, CancellationToken ct = default);&lt;br /&gt;
    Task ResetAsync(ThrottleScope scope, string rawKey, CancellationToken ct = default);&lt;br /&gt;
}&lt;br /&gt;
public sealed class AccountLockoutService { public static TimeSpan BackoffFor(int consecutiveFailures); }&lt;br /&gt;
&lt;br /&gt;
public sealed record AuthAuditEntry(AuthEventType EventType, AuthOutcome Outcome, AuthReasonCode Reason, Guid? UserId=null,&lt;br /&gt;
    string? UserNameAttempted=null, string? AccountKeyRaw=null, string? SourceIpRaw=null, string? UserAgent=null, bool CaptchaPresented=false);&lt;br /&gt;
public interface IAuthAuditWriter { Task WriteAsync(AuthAuditEntry entry, CancellationToken ct = default); }&lt;br /&gt;
&lt;br /&gt;
public readonly record struct PasswordPolicyResult(bool Ok, string? Reason);&lt;br /&gt;
public interface IPasswordPolicy { Task&amp;amp;lt;PasswordPolicyResult&amp;gt; ValidateAsync(string password, Guid? userId = null, CancellationToken ct = default); }&lt;br /&gt;
&lt;br /&gt;
public interface ITotpService {&lt;br /&gt;
    byte[] GenerateSecret(); string ToBase32(byte[] secret);&lt;br /&gt;
    string BuildOtpAuthUri(byte[] secret, string accountName);&lt;br /&gt;
    long? Validate(byte[] secret, string code, long lastStepUsed);&lt;br /&gt;
    IReadOnlyList&amp;amp;lt;string&amp;gt; GenerateRecoveryCodes();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public interface IUserStore {&lt;br /&gt;
    Task&amp;amp;lt;AuthUser?&amp;gt; FindByUserNameAsync(string userName, CancellationToken ct = default);&lt;br /&gt;
    Task&amp;amp;lt;AuthUser?&amp;gt; FindByIdAsync(Guid id, CancellationToken ct = default);&lt;br /&gt;
    Task&amp;amp;lt;AuthUserMfa?&amp;gt; FindMfaAsync(Guid userId, CancellationToken ct = default);&lt;br /&gt;
    Task&amp;amp;lt;bool&amp;gt; AnyUsersAsync(CancellationToken ct = default);&lt;br /&gt;
    Task SaveChangesAsync(CancellationToken ct = default);&lt;br /&gt;
    void ApplyRehash(AuthUser user, string phc, string pepperKeyId);&lt;br /&gt;
    void RecordLogin(AuthUser user, DateTime utcNow);&lt;br /&gt;
    static string Normalize(string userName);   // NFKC + trim + upper&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public readonly record struct EnrollmentBeginResult(string SecretBase32, string OtpAuthUri);&lt;br /&gt;
public readonly record struct EnrollmentConfirmResult(bool Ok, IReadOnlyList&amp;amp;lt;string&amp;gt;? RecoveryCodes, string? Error);&lt;br /&gt;
public interface IMfaEnrollmentService {&lt;br /&gt;
    Task&amp;amp;lt;EnrollmentBeginResult&amp;gt; BeginAsync(Guid userId, CancellationToken ct = default);&lt;br /&gt;
    Task&amp;amp;lt;EnrollmentConfirmResult&amp;gt; ConfirmAsync(Guid userId, string code, string currentPassword, CancellationToken ct = default);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public readonly record struct PasswordChangeResult(bool Ok, string? Error);&lt;br /&gt;
public interface IPasswordChangeService { Task&amp;amp;lt;PasswordChangeResult&amp;gt; ChangeAsync(Guid userId, string currentPassword, string newPassword, CancellationToken ct = default); }&lt;br /&gt;
&lt;br /&gt;
public sealed class AuthBootstrapper { Task SeedAdminAsync(string adminUserName = &amp;quot;admin&amp;quot;, CancellationToken ct = default); }&lt;br /&gt;
&lt;br /&gt;
// Auth email. AddMindAtticAuthentication picks SmtpAuthEmailSender when AuthEmailSettings load, else LoggingAuthEmailSender.&lt;br /&gt;
public interface IAuthEmailSender {&lt;br /&gt;
    Task SendPasswordResetAsync(string toEmail, string resetLink, CancellationToken ct = default);&lt;br /&gt;
    Task SendSecurityAlertAsync(string toEmail, string subject, string body, CancellationToken ct = default);&lt;br /&gt;
}&lt;br /&gt;
public sealed class LoggingAuthEmailSender : IAuthEmailSender;                    // log-only fallback&lt;br /&gt;
public sealed record AuthEmailSettings(string SmtpHost, int SmtpPort, string Username, string Password, string From) {&lt;br /&gt;
    public const string SectionPath = &amp;quot;MindAttic:Vault:Notifications:email&amp;quot;;&lt;br /&gt;
    public static AuthEmailSettings? Load(IConfiguration configuration, out IReadOnlyList&amp;amp;lt;string&amp;gt; problems);&lt;br /&gt;
}&lt;br /&gt;
public sealed record AuthEmailStatus(AuthEmailSettings? Settings, IReadOnlyList&amp;amp;lt;string&amp;gt; Problems);&lt;br /&gt;
public interface IAuthMailTransport { Task SendAsync(MimeMessage message, CancellationToken ct); }   // test seam&lt;br /&gt;
public sealed class MailKitAuthMailTransport(AuthEmailSettings settings) : IAuthMailTransport;     // 465 = TLS, else STARTTLS&lt;br /&gt;
public sealed class SmtpAuthEmailSender : BackgroundService, IAuthEmailSender {   // queued; 3 attempts; never throws to caller&lt;br /&gt;
    public const int QueueCapacity = 256; public const int MaxAttempts = 3;&lt;br /&gt;
    public TimeSpan RetryDelay { get; init; }&lt;br /&gt;
}&lt;br /&gt;
public sealed class AuthEmailStartup : IHostedService;   // starts the SMTP queue; warns when mail will not be delivered&lt;br /&gt;
&lt;br /&gt;
// Security alerts. Registered by AddMindAtticAuthEmail; the account services take it as an optional last&lt;br /&gt;
// constructor parameter (IAuthSecurityAlerts? alerts = null) and call it after the change is saved.&lt;br /&gt;
public enum SecurityAlertKind { PasswordChanged, PasswordReset, PasswordResetByAdmin, MfaEnabled, RecoveryCodeUsed,&lt;br /&gt;
    AccountLocked, NewDeviceSignIn, EmailChanged, AccountDeactivated }&lt;br /&gt;
public interface IAuthSecurityAlerts {&lt;br /&gt;
    Task NotifyAsync(AuthUser user, SecurityAlertKind kind, string? userAgent = null, string? toEmail = null, CancellationToken ct = default);&lt;br /&gt;
}&lt;br /&gt;
public sealed class AuthSecurityAlerts(IAuthEmailSender email, TimeProvider clock, ILogger&amp;amp;lt;AuthSecurityAlerts&amp;gt; logger) : IAuthSecurityAlerts;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 8. Web wiring — &amp;lt;code&amp;gt;MindAttic.Authentication.Web&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;public static IServiceCollection AddMindAtticAuthentication&amp;amp;lt;TContext&amp;gt;(&lt;br /&gt;
    this IServiceCollection services, IConfiguration config, Action&amp;amp;lt;MindAtticAuthOptions&amp;gt; configure)&lt;br /&gt;
    where TContext : DbContext, IAuthDataContext;&lt;br /&gt;
public static IServiceCollection AddMindAtticAuthEmail(this IServiceCollection services, IConfiguration config, string appName);  // called by the above; TryAdd throughout&lt;br /&gt;
&lt;br /&gt;
public static IApplicationBuilder UseMindAtticAuthentication(this IApplicationBuilder app);  // authn→authz→scoped CSP&lt;br /&gt;
public static IEndpointRouteBuilder MapMindAtticAuthEndpoints(this IEndpointRouteBuilder endpoints);&lt;br /&gt;
//   POST /_ma-auth/login · /mfa-challenge · /logout · /change-password (RequireAuthorization)&lt;br /&gt;
//        /reset/request (→ /login?reset=sent) · /reset/confirm (→ /login?reset=ok, or back to ResetPath?error=1&amp;amp;token=…)&lt;br /&gt;
&lt;br /&gt;
public sealed class MaRevalidatingAuthenticationStateProvider : RevalidatingServerAuthenticationStateProvider;&lt;br /&gt;
public static class MindAtticAuthAppExtensions { public const string CspNonceItem = &amp;quot;ma-csp-nonce&amp;quot;; }&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 9. Components — &amp;lt;code&amp;gt;MindAttic.Authentication.Components&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Component&lt;br /&gt;
! Render&lt;br /&gt;
! Parameters&lt;br /&gt;
! Posts to&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MaLogin&amp;lt;/code&amp;gt;&lt;br /&gt;
| static SSR form&lt;br /&gt;
| &amp;lt;code&amp;gt;ReturnUrl&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Error&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;/_ma-auth/login&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MaMfaChallenge&amp;lt;/code&amp;gt;&lt;br /&gt;
| static SSR form&lt;br /&gt;
| &amp;lt;code&amp;gt;ReturnUrl&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Error&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;/_ma-auth/mfa-challenge&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MaChangePassword&amp;lt;/code&amp;gt;&lt;br /&gt;
| static SSR form&lt;br /&gt;
| &amp;lt;code&amp;gt;Error&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;/_ma-auth/change-password&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MaLogout&amp;lt;/code&amp;gt;&lt;br /&gt;
| static SSR form&lt;br /&gt;
| &amp;lt;code&amp;gt;Text&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;/_ma-auth/logout&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MaMfaSetup&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;strong&amp;gt;interactive&amp;lt;/strong&amp;gt;&lt;br /&gt;
| — (reads auth state)&lt;br /&gt;
| calls &amp;lt;code&amp;gt;IMfaEnrollmentService&amp;lt;/code&amp;gt; directly; shows recovery codes once&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
CSS hooks: &amp;lt;code&amp;gt;.ma-auth&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;.ma-auth-field&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;.ma-auth-error&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;.ma-auth-submit&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;.ma-recovery-codes&amp;lt;/code&amp;gt;, etc. No component ever calls &amp;lt;code&amp;gt;SignInAsync&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== 10. Internal helpers (public but not part of the stable contract) ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Internal.AuthKeys&amp;lt;/code&amp;gt; (key canonicalization/hashing), &amp;lt;code&amp;gt;Internal.UrlSafety&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;IsLocalUrl&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;Internal.TimingFloor&amp;lt;/code&amp;gt;. Treat as implementation detail; not covered by the major-version stability promise.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;md2wiki-crumb&amp;quot;&amp;gt;Part of [[MindAttic.Authentication]].&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;md2wiki-source&amp;quot;&amp;gt;From [https://github.com/mindattic/MindAttic.Authentication/blob/main/docs/API.md MindAttic.Authentication/docs/API.md] via MindAttic.Docs; synced automatically, so edit the repo, not this page.&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:MindAttic.Authentication]]&lt;/div&gt;</summary>
		<author><name>Docs Sync</name></author>
	</entry>
</feed>