Audience: PMs, QA, Support, Implementation. What this answers: what the identity layer is, in product terms — how a person logs in, how "which company am I in" works, and how access is decided.

Written from code. Engineering detail lives in technical.md. Screens live in configuration.md and how-to.md.


1. Why this layer exists

PaidHR is multi-tenant: one platform serves many companies, and the same person can belong to several of them (a payroll consultant, an employee who is also an HR admin, a group with sub-companies). This subsystem is the shared foundation that keeps those worlds separate and safe. It does three jobs, on every request:

  1. Authentication — prove you are who you say (password, 2FA, or SSO).
  2. Tenancy — decide which organisation and company you are acting in right now.
  3. Authorization — decide what you may see and do there.

If any of the three is wrong, everything downstream is wrong — a Payroll Admin at Company A must never see Company B's payroll. That guarantee is enforced here, once, so no other module has to.


2. Signing in

There are three doors:

Door Who How
Password login Most users Username + password → Authenticate.
SSO / OAuth Companies using Google or Microsoft Google/Microsoft sign-in → SsoAuthenticate / OAuthAuthenticate.
Control login Internal PaidHR staff Separate Control/Authenticate door into the control panel.

A login attempt does not always end in "you're in." It can return one of several outcomes: