Canonical documentation for the Identity / Tenancy / Authorization subsystem — the multi-tenant, per-permission layer that answers three questions on every request:

  1. Who are you? — authentication (login, JWT, SSO, 2FA).
  2. Which company are you acting in? — tenancy resolution (Organisation → Company → TenantDb).
  3. What are you allowed to do? — authorization (26 admin tiers, custom roles, 199/230 per-permission grants, route guards).

Every other module (Payroll, People, Requests, Leaves, Payments, Performance) sits on top of this layer. It is the designated home for the role-tier + per-permission model — People's RFD-004 hands that ownership here.

Source of truth: written from the actual code — IdentityService.cs (3,642 lines), MembershipService.cs (2,641), AccountService.cs, AdminRolesService.cs, CustomContextAccessorService, IdentityModel.cs / AuthenticationModels.cs, the two DbContexts, and the frontend auth store + guards + roles UI. Unconfirmed frontend items are marked ⚠️ VERIFY.

Start with the surface-map.md — the complete inventory and coverage checklist.


The documents

Doc Audience What it answers Status
surface-map.md Everyone Complete inventory (auth, tenancy, roles, permissions) + coverage ✅ Done 2026-07-20
business.md PMs, QA, Support What it is — identity, the 26 admin tiers, custom roles, the permission model ✅ Done 2026-07-20
technical.md Engineers, DBAs How it's built — auth flow, JWT claims, two-DB tenancy, permission enforcement ✅ Done 2026-07-20
configuration.md Admins, Implementation Grant an admin, build a custom role, enable 2FA — field-by-field ✅ Done 2026-07-20
glossary.md Everyone Data dictionary — claims, contexts, tiers, permission naming ✅ Done 2026-07-20
api-reference.md FE + integration engineers The auth/identity/roles endpoint surface ✅ Done 2026-07-20
user-journey.md PMs, UX, Support Journeys — first login, 2FA setup, granting access, profile switch ✅ Done 2026-07-20
how-to.md Admins, Support Task guides — add admin, custom role, reset 2FA, transfer Primary Admin ✅ Done 2026-07-20
knowledge-base.md End users FAQ — login, 2FA, "why can't I see X?", roles ✅ Done 2026-07-20
runbook.md On-call / Ops Locked-out admins, 2FA resets, token/session issues, primary-admin recovery ✅ Done 2026-07-20
onboarding.md New engineers Ramp into IdentityService • the auth/tenancy area ✅ Done 2026-07-20
rfds/ Engineers Design decisions (encrypted claims, tier+permission split, non-contiguous IDs, admin bypass) ✅ Done 2026-07-20

Legend: ✅ done/verified · 🟡 in progress · ⚪ planned · ⚠️ VERIFY (needs live-product confirmation)


The one-paragraph model

A login (ApplicationUser) lives once in the platform-wide MembershipDb and is keyed to one Organisation. An Organisation contains one or more Companies, whose HR/operational data lives in a per-tenant TenantDb. On login, IdentityService issues a JWT whose claims carry the username, roles, permissions, and an encrypted organisation/company id, stamped with a sign-in context (Owned / Acquired / ReadOnly / a 2FA or reset gate). On every subsequent request, CustomContextAccessorService decrypts those claims into the per-request ContextAccessorModel, and TenantDbFactory resolves the right tenant DB. Authorization is two-layered: a coarse admin tier (one of ~26, e.g. Payroll Admin) and a fine per-permission grant (one of ~230 can_* aliases). Primary and Secondary Admins bypass all permission checks; everyone else is gated by RequireRoutePermit → usePermissions.


Cross-references