<?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%2FORGANIZATIONS</id>
	<title>MindAttic.Authentication/ORGANIZATIONS - 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%2FORGANIZATIONS"/>
	<link rel="alternate" type="text/html" href="https://mindattic.com/wiki/docs/index.php?title=MindAttic.Authentication/ORGANIZATIONS&amp;action=history"/>
	<updated>2026-12-06T19:55:30Z</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/ORGANIZATIONS&amp;diff=544&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/ORGANIZATIONS&amp;diff=544&amp;oldid=prev"/>
		<updated>2026-11-29T20:25:22Z</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;= Organizations and memberships (opt-in) =&lt;br /&gt;
&lt;br /&gt;
Added in 8.0.0 (M.AUTH-T34). Multi-tenant apps give users &amp;lt;strong&amp;gt;memberships&amp;lt;/strong&amp;gt; in &amp;lt;strong&amp;gt;organizations&amp;lt;/strong&amp;gt;, each with an app-defined role string. The feature is opt-in: an app that does not call &amp;lt;code&amp;gt;AddMindAtticOrganizations&amp;lt;/code&amp;gt; is unchanged (no tables, no services, no claims).&lt;br /&gt;
&lt;br /&gt;
== Wiring ==&lt;br /&gt;
&lt;br /&gt;
# Your &amp;lt;code&amp;gt;DbContext&amp;lt;/code&amp;gt; implements &amp;lt;code&amp;gt;IOrganizationDataContext&amp;lt;/code&amp;gt; (it already implements &amp;lt;code&amp;gt;IAuthDataContext&amp;lt;/code&amp;gt;):&amp;lt;br&amp;gt;&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;public DbSet&amp;amp;lt;AuthOrganization&amp;gt; AuthOrganizations =&amp;gt; Set&amp;amp;lt;AuthOrganization&amp;gt;(); public DbSet&amp;amp;lt;AuthMembership&amp;gt; AuthMemberships =&amp;gt; Set&amp;amp;lt;AuthMembership&amp;gt;(); public DbSet&amp;amp;lt;AuthOrganizationAudit&amp;gt; AuthOrganizationAudit =&amp;gt; Set&amp;amp;lt;AuthOrganizationAudit&amp;gt;();&amp;lt;/pre&amp;gt;&lt;br /&gt;
# In &amp;lt;code&amp;gt;OnModelCreating&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;b.ApplyMindAtticAuthConfiguration(organizations: true);&amp;lt;/code&amp;gt; (or call &amp;lt;code&amp;gt;ApplyMindAtticOrganizationConfiguration()&amp;lt;/code&amp;gt; yourself), then add a migration. Tables (schema &amp;lt;code&amp;gt;auth&amp;lt;/code&amp;gt;): &amp;lt;code&amp;gt;AuthOrganizations&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;AuthMemberships&amp;lt;/code&amp;gt; (unique on organization + user; FK to the organization and, cascading, to &amp;lt;code&amp;gt;AuthUsers&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;AuthOrganizationAudit&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;AuthModel.OrganizationModelFingerprint&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;&amp;quot;auth-org-v1&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
# In &amp;lt;code&amp;gt;Program.cs&amp;lt;/code&amp;gt;, after &amp;lt;code&amp;gt;AddMindAtticAuthentication&amp;lt;/code&amp;gt;:&amp;lt;br&amp;gt;&amp;lt;pre class=&amp;quot;md-code lang-csharp&amp;quot;&amp;gt;builder.Services.AddMindAtticOrganizations&amp;amp;lt;MyDbContext&amp;gt;(builder.Configuration, o =&amp;gt; {     o.OwnerRole = &amp;quot;Owner&amp;quot;;     o.Roles = [&amp;quot;Owner&amp;quot;, &amp;quot;Admin&amp;quot;, &amp;quot;Instructor&amp;quot;, &amp;quot;Student&amp;quot;];     o.MfaRequiredRoles = [&amp;quot;Owner&amp;quot;, &amp;quot;Admin&amp;quot;, &amp;quot;Instructor&amp;quot;];     o.MembershipClaimType = &amp;quot;myapp:org&amp;quot;;   // optional; default &amp;quot;ma:org&amp;quot; });&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;code&amp;gt;IOrganizationService&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
The caller&amp;#039;s own authorization decides who may manage an organization; the service enforces invariants. Pass &amp;lt;code&amp;gt;actingRole&amp;lt;/code&amp;gt; (the caller&amp;#039;s role in the organization) when an organization member is acting, and &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; for platform staff and system code.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;CreateAsync(name, createdBy?, ownerUserId?)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Unique slug; optional first owner.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AddMemberAsync&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;SetRoleAsync&amp;lt;/code&amp;gt;&lt;br /&gt;
| Add, restore, or change role. Only an owner grants the owner role or changes an owner&amp;#039;s role. A role change signs the user out everywhere.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;RemoveMemberAsync&amp;lt;/code&amp;gt; / &amp;lt;code&amp;gt;RestoreMemberAsync&amp;lt;/code&amp;gt;&lt;br /&gt;
| Deactivates or restores; the last active owner cannot be removed. Removal signs the user out everywhere.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;SetOrganizationActiveAsync&amp;lt;/code&amp;gt;&lt;br /&gt;
| Deactivating ends every member&amp;#039;s sessions.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MembershipsOfAsync(userId)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Active memberships of active organizations.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MembersAsync(organizationId)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Memberships with user name and email.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Every change writes an &amp;lt;code&amp;gt;AuthOrganizationAudit&amp;lt;/code&amp;gt; row (action such as &amp;lt;code&amp;gt;member.role&amp;lt;/code&amp;gt;, actor, subject, short detail) in the same save as the change. No tokens, passwords or full emails are recorded.&lt;br /&gt;
&lt;br /&gt;
== Claims ==&lt;br /&gt;
&lt;br /&gt;
At sign-in the library adds one claim per active membership of an active organization, type &amp;lt;code&amp;gt;AuthOrganizationOptions.MembershipClaimType&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;ma:org&amp;lt;/code&amp;gt;), value &amp;lt;code&amp;gt;{organizationId:N}&amp;amp;#124;{role}&amp;lt;/code&amp;gt;. Claims are baked into the cookie once, so a membership change rotates the user&amp;#039;s &amp;lt;code&amp;gt;SecurityStamp&amp;lt;/code&amp;gt;; the existing revalidation then signs the old session out and the next sign-in carries the current memberships. Choosing which organization is &amp;quot;active&amp;quot; for a request is the host&amp;#039;s concern (Gadfly uses a cookie).&lt;br /&gt;
&lt;br /&gt;
== Per-role MFA ==&lt;br /&gt;
&lt;br /&gt;
Roles in &amp;lt;code&amp;gt;MfaRequiredRoles&amp;lt;/code&amp;gt; require MFA. Granting one to a user without MFA sets &amp;lt;code&amp;gt;MustEnrollMfa&amp;lt;/code&amp;gt;; and if any held role requires MFA, the sign-in carries &amp;lt;code&amp;gt;ma:omfa=1&amp;lt;/code&amp;gt;, so a session without &amp;lt;code&amp;gt;amr=mfa&amp;lt;/code&amp;gt; is redirected to &amp;lt;code&amp;gt;/account/mfa/setup&amp;lt;/code&amp;gt; by the library&amp;#039;s forced-step middleware, independent of &amp;lt;code&amp;gt;MfaOptions.RequireForAdmin&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Email invitations (M.AUTH-T35, 9.0.0) ==&lt;br /&gt;
&lt;br /&gt;
An organization admin invites people by email; the invitee sets a password through the library&amp;#039;s own page, the way a password reset works. The same &amp;lt;code&amp;gt;AddMindAtticOrganizations&amp;lt;/code&amp;gt; call registers it, and &amp;lt;code&amp;gt;AuthInvitations&amp;lt;/code&amp;gt; joins the opt-in model (&amp;lt;code&amp;gt;ApplyMindAtticOrganizationConfiguration&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;OrganizationModelFingerprint&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;&amp;quot;auth-org-v2&amp;quot;&amp;lt;/code&amp;gt;, so add a migration).&lt;br /&gt;
&lt;br /&gt;
=== Use ===&lt;br /&gt;
&lt;br /&gt;
# Your accept page renders &amp;lt;code&amp;gt;&amp;amp;lt;MaAcceptInvitation Token=&amp;quot;@token&amp;quot; Error=&amp;quot;@error&amp;quot; /&amp;gt;&amp;lt;/code&amp;gt; (default path &amp;lt;code&amp;gt;/account/accept-invite&amp;lt;/code&amp;gt;, configurable as &amp;lt;code&amp;gt;Invitations:AcceptPath&amp;lt;/code&amp;gt;; keep it under &amp;lt;code&amp;gt;/account&amp;lt;/code&amp;gt; so the library&amp;#039;s CSP nonce and forced-step exclusions apply). &amp;lt;code&amp;gt;?token=&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;?error=1&amp;lt;/code&amp;gt; are the query parameters.&lt;br /&gt;
# Set an absolute &amp;lt;code&amp;gt;Organizations:Invitations:PublicBaseUrl&amp;lt;/code&amp;gt; (falls back to &amp;lt;code&amp;gt;Reset:PublicBaseUrl&amp;lt;/code&amp;gt;). Links are never derived from the request host; with no absolute base URL invitations are refused.&lt;br /&gt;
# Call &amp;lt;code&amp;gt;IInvitationService&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;InviteAsync(org, email, role, invitedBy, actingRole)&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;InviteBulkCsvAsync&amp;lt;/code&amp;gt; (rows of &amp;lt;code&amp;gt;email[,role]&amp;lt;/code&amp;gt;, optional header, blank and &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt; lines skipped, &amp;lt;code&amp;gt;MaxBulkRows&amp;lt;/code&amp;gt; default 200), &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;. Delivery goes through &amp;lt;code&amp;gt;IAuthEmailSender.SendInvitationAsync&amp;lt;/code&amp;gt; (default implemented on top of &amp;lt;code&amp;gt;SendSecurityAlertAsync&amp;lt;/code&amp;gt;, so an existing host sender keeps compiling; the SMTP and logging senders override it, and the logging sender prints the link in development).&lt;br /&gt;
&lt;br /&gt;
=== Security properties ===&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strong&amp;gt;Token&amp;lt;/strong&amp;gt;: 256-bit CSPRNG, base64url in the link, stored only as HMAC-SHA256 under the existing &amp;lt;code&amp;gt;reset-token-key&amp;lt;/code&amp;gt; Vault secret with an &amp;lt;code&amp;gt;invite:&amp;lt;/code&amp;gt; domain prefix (no new secret). Single-use: acceptance claims the row with one conditional &amp;lt;code&amp;gt;UPDATE ... WHERE ConsumedUtc IS NULL&amp;lt;/code&amp;gt; (rows-affected check), so concurrent redemptions yield one winner. Expiry (&amp;lt;code&amp;gt;TtlHours&amp;lt;/code&amp;gt;, default 72) runs from each send; resending issues a fresh token and the old link stops working.&lt;br /&gt;
* &amp;lt;strong&amp;gt;Anti-enumeration&amp;lt;/strong&amp;gt;: creating or re-sending an invitation gives the inviter the same outcome whether or not the address already has an account. On the accept side every failure (unknown, used, revoked, expired, wrong account, policy-rejected username) returns one generic message and the endpoint applies the uniform timing floor.&lt;br /&gt;
* &amp;lt;strong&amp;gt;Caps&amp;lt;/strong&amp;gt;: per invitation &amp;lt;code&amp;gt;MaxSendsPerInvitation&amp;lt;/code&amp;gt; (5) and &amp;lt;code&amp;gt;MinResendIntervalSeconds&amp;lt;/code&amp;gt; (60); per organization &amp;lt;code&amp;gt;MaxInvitationsPerOrganizationPerHour&amp;lt;/code&amp;gt; (500); bulk &amp;lt;code&amp;gt;MaxBulkRows&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;strong&amp;gt;No auto-login&amp;lt;/strong&amp;gt;: like reset, the invitee signs in fresh. The new account is created with the chosen password and &amp;lt;code&amp;gt;EmailVerified&amp;lt;/code&amp;gt;; if the role requires MFA (&amp;lt;code&amp;gt;MfaRequiredRoles&amp;lt;/code&amp;gt;) &amp;lt;code&amp;gt;MustEnrollMfa&amp;lt;/code&amp;gt; is set, so the first sign-in is routed to MFA setup.&lt;br /&gt;
* &amp;lt;strong&amp;gt;Existing accounts&amp;lt;/strong&amp;gt;: an address that already has an account is never given a second one or a password. The page asks the holder to sign in; &amp;lt;code&amp;gt;AcceptExistingAsync&amp;lt;/code&amp;gt; (endpoint &amp;lt;code&amp;gt;/_ma-auth/invite/accept-existing&amp;lt;/code&amp;gt;, requires sign-in) accepts only for the account whose email matches the invitation, adds the membership, rotates the stamp, and signs the session out so the new membership is on the next cookie.&lt;br /&gt;
* &amp;lt;strong&amp;gt;Audit&amp;lt;/strong&amp;gt;: &amp;lt;code&amp;gt;AuthOrganizationAudit&amp;lt;/code&amp;gt; rows (&amp;lt;code&amp;gt;invite.create&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;invite.resend&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;invite.revoke&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;invite.accept&amp;lt;/code&amp;gt;) hold a masked address and the role; &amp;lt;code&amp;gt;AuthAuditLog&amp;lt;/code&amp;gt; gets &amp;lt;code&amp;gt;AuthEventType.Invitation&amp;lt;/code&amp;gt; success and failure rows with IP and user agent.&lt;br /&gt;
&lt;br /&gt;
=== Endpoints ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;POST /_ma-auth/invite/accept&amp;lt;/code&amp;gt; (token, optional userName, newPassword) redirects to &amp;lt;code&amp;gt;/login?invite=ok&amp;lt;/code&amp;gt;, or back to the accept page with &amp;lt;code&amp;gt;?error=1&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;POST /_ma-auth/invite/accept-existing&amp;lt;/code&amp;gt; (token) requires authorization. Both validate antiforgery.&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/ORGANIZATIONS.md MindAttic.Authentication/docs/ORGANIZATIONS.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>