feat(auth): close PMS-138 - subdomain-driven tenant hint on login + forgot-password + Google JIT #89
No reviewers
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
psa-systems/mokosh-server!89
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/pms-138-closeout"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds
tenant_id: Option<Uuid>to LoginRequest and ForgotPasswordRequest so the SPA can disambiguate multi-tenant deployments where the same email exists under several tenants. Omitted clients fall back to the default tenantUuid::from_u128(1), matchingdb::tenant::default_tenant_idand the OIDC_DEFAULT_TENANT_ID convention so legacy login behaviour converges with the Bunyip at+jwt path.Renames
find_user_by_emailandfind_user_by_email_optionaltofind_user_by_email_for_tenant[_optional], binding bothtenant_idandemailin WHERE. Theusers.UNIQUE(tenant_id, email)constraint guarantees at most one row, so the oldORDER BY created_at ASC LIMIT 1tiebreaker (which silently routed colliding-email logins to the oldest tenant) is gone.Scope expansion vs the stated AC list: the PR also fixes the sibling email-only lookups in
login_with_google(JIT-link) andrequest_password_reset(forgot-password). All three callers now thread the optional hint through the newSelf::resolve_tenant_for_login(hint)helper. Multi-tenant Google login remains a future story because the OAuth state cookie does not carry a tenant hint yet.The Bunyip-issued at+jwt OIDC validation path in
RequireAuth(JWKS fetch, audience check, EdDSA verify, claim mapping) is untouched: this PR only hardens the legacy HS256 paths so they match the OIDC path's tenant resolution.Tests:
login_with_tenant_hint_resolves_to_correct_tenant(two tenants with same email, the hint picks the right user)login_omitting_tenant_id_falls_back_to_default(backward compat for current single-tenant SPAs)login_wrong_tenant_hint_returns_401(wrong hint must not cross-authenticate)forgot_password_with_tenant_hint_targets_correct_user(reset token row scoped to the hinted tenant)Closes cross-cutting issue #8 in
dev-docs/codebase-state.mdfor the auth module.#PMS-138