Status: Accepted (in force). Reconstructed.

Context

PaidHR is multi-tenant; every request must be scoped to exactly one organisation + company. The scope has to travel with the request. Two obvious options: pass org/company ids as request parameters, or carry them in the auth token. Both risk leaking or letting a client choose its own tenant scope.

Decision

Carry the tenant scope inside the JWT, and encrypt the organisationid / companyid claim values. On each request, CustomContextAccessorService.GetCredentials(token) reads the claims, Decrypt(value, encryptionKey)s the ids, and populates a per-request ContextAccessorModel. Clients never pass org/company ids — they're derived from the token alone. The same encryptionKey signs the token (HmacSha256) and encrypts the sensitive claims.

Consequences

Good:

Bad / costs:

The context gate

Org/company claims are only read when the context claim is Owned or Acquired. Under TwoFactor*, PasswordResetRequired, or ReadOnly, tenant claims are deliberately not populated — a half-authenticated session must not act inside a tenant.

Alternatives

Related