Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Enterprise sign-in for a multi-tenant SaaS

When one service hosts many customer organizations, each with its own identity provider, sign-in is where their separation is first tested. This lesson follows the photo service as Lantern Studio and Cedar Inc. bring their own providers: routing each person to the right one, giving every organization its own connection, provisioning and administrators, carrying the organization in tokens, and the shortcuts that let one customer reach another.

One service, many organizations

The photo service started with people like Ava, who sign up on their own. Then businesses asked for accounts their whole staff could share. Lantern Studio, the design agency, was first: its designers wanted shared albums, its office manager wanted to control who joined, and its IT contractor wanted everyone to sign in with Lantern's own identity provider at idp.lantern.example rather than with another password. Cedar Inc. followed, with a SAML identity provider at login.cedar.example and a thousand employees.

That makes the photo service a multi-tenant SaaS: one running service that hosts many customer organizations, each of which the service calls a tenant or an organization. Every organization gets its own users, settings and data inside the same application, and expects none of it to be visible to any other. Sign-in is where that expectation is tested first, because one sign-in page now has to serve Ava, Lantern's designers and Cedar's employees, each through a different provider.

Partners and guests from other organizations showed one organization admitting a guest from another. Here the relationship is reversed and multiplied: the photo service accepts sign-ins from every customer organization's provider, and must keep each one's people inside that organization.

Finding the right provider

A sign-in page with one button per customer stops working at the third customer, and it tells every visitor who the customers are. The photo service asks for the email address first instead, and decides from it where to send the person. This is identifier-first sign-in, and the decision it makes is called home realm discovery: finding the realm, the organization and provider, that the person belongs to.

Identifier-first sign-in: the email domain picks the organization, and the organization's connection picks the provider.

The lookup is only as trustworthy as the domain list behind it. Before the photo service routes lantern.example to Lantern, Lantern must prove it controls that domain, usually by publishing a value the photo service gives it in a DNS record. Without that check, any customer could claim cedar.example and catch Cedar's employees at the sign-in page. Domains that many unrelated people share, such as mail.example, are never routed to an organization at all.

An email domain is a hint about where to sign in, not evidence of who someone is. Some people work for two customers, some organizations use several domains, and a contractor's address may sit on their own company's domain. So the page lets people choose a different organization, remembers the choice on that device, and accepts an organization named in the link the customer gave its staff, such as a sign-in address with ?organization=lantern. Whatever the route, the account a sign-in reaches is decided by the provider's answer and the organization's connection, never by the address someone typed.

A connection per organization

Each organization's provider is configured as its own connection, a federation agreement between the photo service and one provider, owned by one organization. Lantern's is OpenID Connect; Cedar's is SAML:

Two organizations' connections at the photo service
SettingLantern StudioCedar Inc.
ProtocolOpenID ConnectSAML 2.0
Trusted issuerhttps://idp.lantern.exampleEntity ID https://login.cedar.example/saml
Keys fromLantern's discovery document and JWKSCedar's metadata and signing certificate
Account keyIssuer and subEntity ID and persistent NameID
Verified domainslantern.examplecedar.example, cedar-labs.example
New peopleCreated at first sign-inOnly if Cedar's SCIM feed created them first

The connection, not the person, decides which organization a sign-in belongs to. An ID token from idp.lantern.example can only ever produce an account in Lantern's organization, whatever email address it states. That is what keeps a customer's administrator, who controls their own provider and can make it say anything, from minting accounts in another customer's space.

Accounts are keyed by the issuer and subject, exactly as Connecting a sign-in to an account required, and scoped to the organization. If the same designer also has a personal photo service account under the same email address, the two stay separate unless she links them deliberately.

Provisioning per organization

Lantern is small, so it lets accounts appear at each designer's first sign-in, the just-in-time provisioning described in Getting accounts into applications. The connection creates the account in Lantern's organization with the name and email from the token, and Lantern's office manager can see it appear. Others join by invitation: the office manager types a freelancer's address, the photo service emails a single-use link, and the freelancer's account is created when they accept, inside Lantern and nowhere else.

Neither route hears about people who leave. Cedar needs that, so it provisions over SCIM, as SCIM requests and responses showed. Each organization gets its own SCIM endpoint and its own token, which can reach only that organization's users and groups:

http
PATCH /scim/v2/organizations/org_c3d9/Users/u_51a7 HTTP/1.1
Host: api.photos.example
Authorization: Bearer (Cedar's SCIM token)
Content-Type: application/scim+json

{"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
 "Operations": [{"op": "replace", "path": "active", "value": false}]}

The photo service checks that the token belongs to org_c3d9 and that user u_51a7 is in it, before anything else. A token for Lantern that names Cedar's organization in the path is refused, and so is a valid Cedar token that names a user from another organization. Deactivating an account also ends its sessions and tokens, which is the part of leaving that only provisioning delivers.

Administrators inside an organization

Each customer wants to run its own corner: add people, remove them, decide who may manage shared albums. The photo service gives every organization its own administrator roles, as Roles, assignments, and scope described for roles that apply to one part of a system. Lantern's office manager holds Organization admin with the scope org_7a12, Lantern's organization. Every management request she makes is checked against that scope on the server, so a request that names a Cedar user is refused however it was built.

The photo service's own staff need access too, for support. That access comes from the photo service's own roles, granted to its own employees, and it is recorded in the customer's audit history as support access, so Lantern can see when someone outside Lantern looked at its organization. A customer's administrator, in turn, has no role in the photo service's own administration. The two kinds of authority never imply each other.

The organization in the token

Once a designer is signed in, every API request has to be answered for the right organization. The photo service puts the organization in the access tokens it issues:

json
{
  "iss": "https://auth.photos.example",
  "sub": "u_8812",
  "aud": "https://api.photos.example",
  "org_id": "org_7a12",
  "scope": "albums.read albums.write",
  "exp": 1793702400
}

org_id is a value the photo service chose from the connection the person signed in through. It is never copied from anything the person or their provider supplied, such as a claim in Lantern's ID token or a parameter in the request. The API uses it to limit every query: a request for album 91 from this token is answered only if album 91 belongs to org_7a12, and otherwise gets the same 404 as an album that does not exist. Someone who belongs to two organizations signs in to one at a time and receives a token for that one.

Isolation pitfalls

Most failures in multi-tenant sign-in come from a shortcut that treats something shared as if it belonged to one organization:

Shortcuts that break isolation
ShortcutWhat goes wrongWhat to do instead
Matching accounts by email across organizationsA provider that states [email protected] reaches Cedar's accountKey accounts by connection, issuer and subject
Routing by unverified domainsA customer claims another company's domain and receives its sign-insVerify domain ownership before routing
Taking the organization from a claim or parameterA crafted request or provider claim moves a user into another organizationDerive the organization from the connection
Global object IDs without an organization checkChanging /albums/91 to /albums/92 reads another customer's albumScope every lookup by the token's organization
Caches keyed by user or object aloneOne organization's answer is served to anotherInclude the organization in every cache key
Support tools with direct database accessStaff see every organization at once, unrecordedSupport access through the same checks, recorded per organization

Each row is the same rule seen from a different place: the organization is fixed when someone signs in, by the photo service, from a connection it trusts, and everything after that inherits it.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

Lantern's identity provider sends an ID token whose email claim is [email protected]. Cedar Inc. is also a customer, with its own connection. Where should the photo service put this sign-in? 1 of 3

Choose one answer.

A new customer asks the photo service to send everyone who types an address at cedar.example to its own identity provider. What should the photo service require first? 2 of 3

Choose one answer.

A Lantern designer's token carries org_id org_7a12. She changes a request from /albums/91 to /albums/92, an album that belongs to Cedar. How should the API answer? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity