Customer Identity · public betaBuild your first Test integration.Create a Test project
NamoID
All posts
NamoID Blog

Multi-Tenant Authentication for SaaS: Users and Roles

Design multi-tenant SaaS authentication with organization membership, invitations, roles, tenant-bound sessions, and cross-tenant isolation.

Multi-tenant authentication answers who the user is. It does not answer which customer organization the user is acting in or what they may do there.

That distinction causes a common SaaS failure: the application verifies a valid session, accepts an organization ID from the URL, and loads data without proving that the user belongs to that organization. The user is authenticated, but the request crosses a tenant boundary.

A safe design makes organization membership and active-tenant context explicit at every authorization decision.

Separate users, organizations, and memberships

Model these as different entities:

User
  id
  primary identity
  account status
 
Organization
  id
  name
  status
 
Membership
  user_id
  organization_id
  role
  status

A user may belong to several organizations. An organization has several users. The membership carries the relationship-specific role and lifecycle.

Do not store one global role = admin on the user if the user can be an administrator in one organization and a viewer in another.

Bind every request to an active organization

The application needs an active organization for organization-scoped operations. That context may come from a route, subdomain, explicit selector, or session-bound choice—but it must be checked against an active membership.

Use the same decision everywhere:

authenticated user
  + requested organization
  + active membership
  + required permission
  + resource belongs to organization
  = allow or deny

Never trust organization_id merely because it came from a signed-in browser. A user can edit URLs, request bodies, GraphQL variables, and client-side state.

Scope database queries, not only route guards

A route-level membership check is useful but insufficient. Data access should include the organization boundary in the query.

Instead of:

SELECT * FROM projects WHERE id = :project_id;

use a tenant-scoped query:

SELECT * FROM projects
WHERE id = :project_id
  AND organization_id = :organization_id;

Apply the same rule to updates and deletes. Prefer a “not found” response when revealing that a resource exists in another tenant would leak information.

Background jobs, exports, webhooks, caches, object storage, search indexes, and analytics pipelines need the same boundary. Cross-tenant bugs often appear outside the main HTTP request path.

Invitations are security credentials

An invitation grants a path into an organization. Treat its token like a recovery link:

  • generate it randomly;
  • bind it to the intended organization and role;
  • expire it;
  • make it single-use;
  • invalidate it when revoked or replaced; and
  • record who created and accepted it.

Decide whether an invitation is bound to a specific verified email address. If it is, acceptance by a different account should fail or require an explicit administrator decision—not silently transfer the invitation.

Do not let inviters grant roles above their own authority. An organization member who can invite viewers should not be able to edit the request and invite an owner.

Role changes must affect active access

If a user is removed from an organization, their existing session may remain authenticated. Authorization must consult current membership state or receive a reliable revocation signal.

Strategies include:

  • short-lived authorization claims plus current-state checks for sensitive actions;
  • a membership version embedded in the session and compared server-side;
  • targeted session revocation after role changes; or
  • continuous security-event propagation in larger federated systems.

Do not place long-lived organization roles in a token and assume they remain true until the token expires. The JWT validation guide explains signature and claim checks, but a valid signature cannot make stale authorization data current.

Define owner and administrator recovery

Organizations need governance for:

  • the last owner trying to leave;
  • an owner losing account access;
  • employee departure;
  • domain or company ownership disputes;
  • transferring ownership; and
  • suspending a compromised administrator.

Require at least one accountable owner and encourage more than one recovery-capable administrator for business accounts. High-impact ownership transfers should require recent authentication, clear notifications, and an audit trail.

The secure account-recovery guide covers the user side. Organization recovery adds a business-authority question: even if support verifies a person, are they authorized to control the tenant?

Keep tenant information out of unsafe caches

Cache keys must include every dimension that changes the result. A key such as project:{id} may be unsafe if project identifiers are only unique inside an organization. Use an organization-qualified key and verify the stored object’s tenant before returning it.

The same applies to:

  • server-rendered page caches;
  • CDN responses;
  • report downloads;
  • job deduplication keys;
  • rate-limit buckets; and
  • local application state when switching organizations.

When the active organization changes, clear or refetch organization-scoped data. A polished tenant switcher can still leak the previous organization’s cached records.

Audit tenant-bound actions

An audit event should answer:

  • who acted;
  • in which organization;
  • with which role or authority;
  • what resource was affected;
  • what changed;
  • when it happened; and
  • which request or session produced it.

Record membership invitations, acceptance, role changes, removals, ownership transfers, authentication-factor changes, and sensitive exports. Avoid putting secrets, tokens, or full sensitive payloads into the event.

The DPDP audit-trail guide covers privacy and operational considerations.

Test the boundary directly

For every organization-scoped endpoint, test:

  1. a member with the required permission;
  2. a member without the permission;
  3. an authenticated non-member;
  4. a suspended or removed member;
  5. the same resource ID under another organization;
  6. a stale session after a role change; and
  7. a background job with a mismatched tenant context.

Include negative tests for list, detail, update, delete, export, webhook, and search operations. A secure detail endpoint does not compensate for an export job that ignores the tenant filter.

Distinguish your SaaS organizations from your identity-provider tenant

An identity provider may isolate each customer in its own control-plane tenant while the customer’s application separately models its end-user organizations. Those boundaries solve different problems.

NamoID currently uses tenant, project, and environment boundaries to isolate customer identity configuration. Product teams should not interpret that as an automatic end-user organization model inside their SaaS application. Model and authorize application organizations explicitly until a supported organization feature is part of the product contract.

For the broader architecture decision, read build versus buy authentication in India and explore NamoID Customer Identity.

Picking the identity provider underneath this model is a separate decision — see the Indian startup auth decision guide.