<?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%2FINTEGRATION</id>
	<title>MindAttic.Authentication/INTEGRATION - 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%2FINTEGRATION"/>
	<link rel="alternate" type="text/html" href="https://mindattic.com/wiki/docs/index.php?title=MindAttic.Authentication/INTEGRATION&amp;action=history"/>
	<updated>2026-12-06T08:02:07Z</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/INTEGRATION&amp;diff=543&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/INTEGRATION&amp;diff=543&amp;oldid=prev"/>
		<updated>2026-11-29T20:25:21Z</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;= Integrating MindAttic.Authentication into an app =&lt;br /&gt;
&lt;br /&gt;
A consuming app keeps its own &amp;lt;code&amp;gt;DbContext&amp;lt;/code&amp;gt;, connection string, and deployment. It gains hardened auth by (1) referencing the package, (2) implementing &amp;lt;code&amp;gt;IAuthDataContext&amp;lt;/code&amp;gt; on its &amp;lt;code&amp;gt;DbContext&amp;lt;/code&amp;gt;, (3) wiring DI + middleware + endpoints, (4) adding login/MFA/account pages, and (5) provisioning Vault secrets.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Every consuming app (today MindAttic.Ideas, IdiotProof, Prose and Tutor) is a &amp;lt;strong&amp;gt;separate trust boundary&amp;lt;/strong&amp;gt; — each picks a unique &amp;lt;code&amp;gt;AppName&amp;lt;/code&amp;gt;, so a cookie from one app can never authenticate to another.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== 1. Reference the package ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;nuget.config&amp;lt;/code&amp;gt; must include the local feed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-xml&amp;quot;&amp;gt;&amp;amp;lt;add key=&amp;quot;LocalNuGet&amp;quot; value=&amp;quot;C:\LocalNuGet&amp;quot; /&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-xml&amp;quot;&amp;gt;&amp;amp;lt;PackageReference Include=&amp;quot;MindAttic.Authentication&amp;quot; Version=&amp;quot;6.0.0&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;amp;lt;PackageReference Include=&amp;quot;MindAttic.Vault&amp;quot; Version=&amp;quot;5.0.0&amp;quot; /&amp;gt;   &amp;amp;lt;!-- only if the host fills config through Vault; the library itself does not depend on it --&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 2. Implement &amp;lt;code&amp;gt;IAuthDataContext&amp;lt;/code&amp;gt; on your DbContext ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;using MindAttic.Authentication.Data;&lt;br /&gt;
using MindAttic.Authentication.Entities;&lt;br /&gt;
&lt;br /&gt;
public sealed class AppDbContext(DbContextOptions&amp;amp;lt;AppDbContext&amp;gt; o) : DbContext(o), IAuthDataContext&lt;br /&gt;
{&lt;br /&gt;
    // ... your app&amp;#039;s DbSets ...&lt;br /&gt;
    public DbSet&amp;amp;lt;AuthUser&amp;gt; AuthUsers =&amp;gt; Set&amp;amp;lt;AuthUser&amp;gt;();&lt;br /&gt;
    public DbSet&amp;amp;lt;AuthUserMfa&amp;gt; AuthUserMfa =&amp;gt; Set&amp;amp;lt;AuthUserMfa&amp;gt;();&lt;br /&gt;
    public DbSet&amp;amp;lt;AuthRecoveryCode&amp;gt; AuthRecoveryCodes =&amp;gt; Set&amp;amp;lt;AuthRecoveryCode&amp;gt;();&lt;br /&gt;
    public DbSet&amp;amp;lt;AuthSession&amp;gt; AuthSessions =&amp;gt; Set&amp;amp;lt;AuthSession&amp;gt;();&lt;br /&gt;
    public DbSet&amp;amp;lt;AuthLoginThrottle&amp;gt; AuthLoginThrottles =&amp;gt; Set&amp;amp;lt;AuthLoginThrottle&amp;gt;();&lt;br /&gt;
    public DbSet&amp;amp;lt;AuthAuditLog&amp;gt; AuthAuditLog =&amp;gt; Set&amp;amp;lt;AuthAuditLog&amp;gt;();&lt;br /&gt;
    public DbSet&amp;amp;lt;AuthPasswordHistory&amp;gt; AuthPasswordHistory =&amp;gt; Set&amp;amp;lt;AuthPasswordHistory&amp;gt;();&lt;br /&gt;
    public DbSet&amp;amp;lt;AuthPasswordResetToken&amp;gt; AuthPasswordResetTokens =&amp;gt; Set&amp;amp;lt;AuthPasswordResetToken&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
    protected override void OnModelCreating(ModelBuilder b)&lt;br /&gt;
    {&lt;br /&gt;
        base.OnModelCreating(b);&lt;br /&gt;
        // ... your app&amp;#039;s config ...&lt;br /&gt;
        b.ApplyMindAtticAuthConfiguration();   // tables in the isolated `auth` schema&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then &amp;lt;code&amp;gt;dotnet ef migrations add AddMindAtticAuth&amp;lt;/code&amp;gt; and deploy the migration (the &amp;lt;code&amp;gt;auth&amp;lt;/code&amp;gt; schema is created alongside your existing tables; no FKs cross into app tables).&lt;br /&gt;
&lt;br /&gt;
== 3. Wire DI + middleware + endpoints (&amp;lt;code&amp;gt;Program.cs&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;builder.Configuration.AddMindAtticVaultFiles().AddEnvironmentVariables();&lt;br /&gt;
builder.Services.AddMindAtticVault(builder.Configuration);&lt;br /&gt;
&lt;br /&gt;
builder.Services.AddDbContextFactory&amp;amp;lt;AppDbContext&amp;gt;(o =&amp;gt; o.UseSqlServer(conn));   // your existing setup&lt;br /&gt;
builder.Services.AddScoped&amp;amp;lt;AppDbContext&amp;gt;(sp =&amp;gt; sp.GetRequiredService&amp;amp;lt;IDbContextFactory&amp;amp;lt;AppDbContext&amp;gt;&amp;gt;().CreateDbContext());&lt;br /&gt;
&lt;br /&gt;
builder.Services.AddMindAtticAuthentication&amp;amp;lt;AppDbContext&amp;gt;(builder.Configuration, o =&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    o.AppName       = &amp;quot;Ideas&amp;quot;;                       // per-app trust boundary&lt;br /&gt;
    o.IsProduction  = !builder.Environment.IsDevelopment();&lt;br /&gt;
    o.ConfigureDataProtection = dp =&amp;gt;                // PROD only — fail-closed if omitted in prod&lt;br /&gt;
    {&lt;br /&gt;
        dp.PersistKeysToAzureBlobStorage(blobUri, cred)&lt;br /&gt;
          .ProtectKeysWithAzureKeyVault(kvKeyUri, cred);&lt;br /&gt;
    };&lt;br /&gt;
    // o.ConfigureAdditionalPolicies = ab =&amp;gt; ab.AddPolicy(&amp;quot;MyPolicy&amp;quot;, p =&amp;gt; ...);&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
builder.Services.AddRazorComponents().AddInteractiveServerComponents();&lt;br /&gt;
&lt;br /&gt;
var app = builder.Build();&lt;br /&gt;
&lt;br /&gt;
using (var scope = app.Services.CreateScope())&lt;br /&gt;
{&lt;br /&gt;
    var db = scope.ServiceProvider.GetRequiredService&amp;amp;lt;AppDbContext&amp;gt;();&lt;br /&gt;
    await db.Database.MigrateAsync();&lt;br /&gt;
    await scope.ServiceProvider.GetRequiredService&amp;amp;lt;AuthBootstrapper&amp;gt;().SeedAdminAsync();   // needs Vault bootstrap-token&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
app.UseForwardedHeaders();                 // configure KnownProxies/KnownNetworks (security-critical)&lt;br /&gt;
app.UseMindAtticAuthentication();          // authn → authz → scoped CSP nonce&lt;br /&gt;
app.UseAntiforgery();&lt;br /&gt;
app.MapMindAtticAuthEndpoints();           // /_ma-auth/*&lt;br /&gt;
app.MapRazorComponents&amp;amp;lt;App&amp;gt;().AddInteractiveServerRenderMode();&lt;br /&gt;
app.Run();&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 4. Add the pages ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code lang-razor&amp;quot;&amp;gt;@* /login *@&lt;br /&gt;
@page &amp;quot;/login&amp;quot;&lt;br /&gt;
@inject NavigationManager Nav&lt;br /&gt;
&amp;amp;lt;MaLogin ReturnUrl=&amp;quot;@_returnUrl&amp;quot; Error=&amp;quot;@_error&amp;quot; /&amp;gt;&lt;br /&gt;
@code {&lt;br /&gt;
    string? _returnUrl; bool _error;&lt;br /&gt;
    protected override void OnParametersSet() {&lt;br /&gt;
        var q = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(new Uri(Nav.Uri).Query);&lt;br /&gt;
        _returnUrl = q.TryGetValue(&amp;quot;returnUrl&amp;quot;, out var r) ? r.ToString() : null;&lt;br /&gt;
        _error = q.ContainsKey(&amp;quot;error&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add &amp;lt;code&amp;gt;/mfa&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;&amp;amp;lt;MaMfaChallenge/&amp;gt;&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;/account/change-password&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;&amp;amp;lt;MaChangePassword/&amp;gt;&amp;lt;/code&amp;gt;), and &amp;lt;code&amp;gt;/account/mfa/setup&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;&amp;amp;lt;MaMfaSetup/&amp;gt;&amp;lt;/code&amp;gt;, rendered &amp;lt;code&amp;gt;@rendermode InteractiveServer&amp;lt;/code&amp;gt;). For self-service reset, add an anonymous static page at &amp;lt;code&amp;gt;/forgot-password&amp;lt;/code&amp;gt; hosting &amp;lt;code&amp;gt;&amp;amp;lt;MaForgotPassword/&amp;gt;&amp;lt;/code&amp;gt; (link it from &amp;lt;code&amp;gt;/login&amp;lt;/code&amp;gt;) and one at the &amp;lt;code&amp;gt;ResetPath&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;/account/reset&amp;lt;/code&amp;gt;) hosting &amp;lt;code&amp;gt;&amp;amp;lt;MaResetPassword Token=&amp;quot;@Token&amp;quot; Error=&amp;quot;@(Error == 1)&amp;quot;/&amp;gt;&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;Token&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;Error&amp;lt;/code&amp;gt; bound by &amp;lt;code&amp;gt;[SupplyParameterFromQuery]&amp;lt;/code&amp;gt;; show &amp;lt;code&amp;gt;?reset=sent&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;?reset=ok&amp;lt;/code&amp;gt; on &amp;lt;code&amp;gt;/login&amp;lt;/code&amp;gt;; and set &amp;lt;code&amp;gt;MindAttic:Auth:Reset:PublicBaseUrl&amp;lt;/code&amp;gt; to the app&amp;#039;s public https origin. Protect admin pages with &amp;lt;code&amp;gt;@attribute [Authorize(Policy = MaPolicies.Admin)]&amp;lt;/code&amp;gt; (role &amp;lt;strong&amp;gt;+&amp;lt;/strong&amp;gt; MFA).&lt;br /&gt;
&lt;br /&gt;
== 5. Email channel ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;AddMindAtticAuthentication&amp;lt;/code&amp;gt; registers auth email for you; there is no code to write. It reads SMTP settings in the MindAttic.Vault &amp;lt;code&amp;gt;Notifications&amp;lt;/code&amp;gt; format (the same shape MindAttic.Psst uses):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;md-code&amp;quot;&amp;gt;MindAttic:Vault:Notifications:email:smtpHost / smtpPort / username / password / from&lt;br /&gt;
MindAttic:Auth:Reset:PublicBaseUrl      e.g. https&amp;amp;#58;//ideas.mindattic.com  (reset links must be absolute)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;Dev:&amp;lt;/strong&amp;gt; &amp;lt;code&amp;gt;%APPDATA%\MindAttic\Notifications\providers.json&amp;lt;/code&amp;gt; — include &amp;lt;code&amp;gt;&amp;quot;Notifications&amp;quot;&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;AddMindAtticVaultFiles&amp;lt;/code&amp;gt; bucket list if you pass one (it is in Vault&amp;#039;s default list).&lt;br /&gt;
* &amp;lt;strong&amp;gt;Prod:&amp;lt;/strong&amp;gt; app settings &amp;lt;code&amp;gt;MindAttic&amp;amp;#95;_Vault&amp;amp;#95;_Notifications&amp;amp;#95;_email&amp;amp;#95;_smtpHost&amp;lt;/code&amp;gt; (etc.), or Key Vault references.&lt;br /&gt;
&lt;br /&gt;
All five SMTP fields present ⇒ &amp;lt;code&amp;gt;SmtpAuthEmailSender&amp;lt;/code&amp;gt; (queued, MailKit, TLS required). Anything less ⇒ the log-only &amp;lt;code&amp;gt;LoggingAuthEmailSender&amp;lt;/code&amp;gt;, and a startup &amp;lt;strong&amp;gt;warning&amp;lt;/strong&amp;gt; says email will not be delivered and names any missing field. Register your own &amp;lt;code&amp;gt;IAuthEmailSender&amp;lt;/code&amp;gt; to override either. See [[MindAttic.Authentication/OPERATIONS#5. Email (password reset / security alerts)|&amp;lt;code&amp;gt;OPERATIONS.md&amp;lt;/code&amp;gt;]].&lt;br /&gt;
&lt;br /&gt;
== 6. Provision secrets ==&lt;br /&gt;
&lt;br /&gt;
Before first run, provision the Vault &amp;lt;code&amp;gt;Security&amp;lt;/code&amp;gt; bucket: &amp;lt;code&amp;gt;pepper.v1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;bootstrap-token&amp;lt;/code&amp;gt; (and prod &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;). See [[MindAttic.Authentication/OPERATIONS|&amp;lt;code&amp;gt;OPERATIONS.md&amp;lt;/code&amp;gt;]]. The hasher and bootstrap are &amp;lt;strong&amp;gt;fail-closed&amp;lt;/strong&amp;gt; — the app will not start without them.&lt;br /&gt;
&lt;br /&gt;
== 7. Migrating existing users ==&lt;br /&gt;
&lt;br /&gt;
Run a one-time data migration mapping your old user rows → &amp;lt;code&amp;gt;AuthUser&amp;lt;/code&amp;gt;, carrying the old hash with &amp;lt;code&amp;gt;LegacyHashScheme = &amp;quot;bcrypt&amp;quot;&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;&amp;quot;sha256&amp;quot;&amp;lt;/code&amp;gt;), so they upgrade to Argon2id+pepper on next login. Force a reset for any known-bad/hardcoded/dormant accounts. Map your old admin role onto &amp;lt;code&amp;gt;MaRoles.Admin&amp;lt;/code&amp;gt; (the one canonical admin role name; the library has no option to rename it).&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/INTEGRATION.md MindAttic.Authentication/docs/INTEGRATION.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>