Status: Accepted (in force). Reconstructed.
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.
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.
Good:
accessor.companyId / accessor.organisationId.Bad / costs:
0 — code must treat companyId == 0 as "no/invalid tenant," which overlaps with the "not yet elevated" case (see gate below).encryptionKey won't decrypt elsewhere. Never move tokens across environments.encryptionKey invalidates every live token (forced logout).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.