Enterprise sign-in for a multi-tenant SaaS
When one service hosts many customer organizations, each with its own identity providerA service that authenticates users and tells other applications about the sign-in, so those applications never handle the users' passwords. In OpenID Connect it is called an OpenID 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, provisioningCreating accounts in applications, keeping their attributes and access current, and disabling them when people leave, without waiting for each person to sign in. SCIM is a standard way to send those changes. 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 SAMLThe Security Assertion Markup Language, a federation standard widely used for workplace single sign-on, in which the identity provider sends the application a signed assertion about the user. 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.
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 DNSThe Domain Name System, the internet's lookup service that turns a domain such as photos.example into the address of the computer serving it. Whoever controls a name's DNS records controls where that name points. 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 federationAn arrangement that lets systems accept identity information from another trusted system, so an application can rely on a sign-in performed by a separate identity provider. agreement between the photo service and one provider, owned by one organization. Lantern's is OpenID ConnectAn identity layer on top of OAuth 2.0 that lets an application sign people in with an account at another service. It adds the ID token, standard claims, and discovery to the OAuth exchange.; Cedar's is SAML:
| Setting | Lantern Studio | Cedar Inc. |
|---|---|---|
| Protocol | OpenID Connect | SAML 2.0 |
| Trusted issuer | https://idp.lantern.example | Entity ID https://login.cedar.example/saml |
| Keys from | Lantern's discovery document and JWKS | Cedar's metadata and signing certificate |
| Account key | Issuer and sub | Entity ID and persistent NameID |
| Verified domains | lantern.example | cedar.example, cedar-labs.example |
| New people | Created at first sign-in | Only if Cedar's SCIM feed created them first |
The connection, not the person, decides which organization a sign-in belongs to. An ID tokenIn OpenID Connect, a signed JWT from the provider, addressed to one client, saying which account authenticated, when, and in answer to which request. It reports a sign-in and is not used to call APIs. 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 issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts. 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 tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret., 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 SCIMThe System for Cross-domain Identity Management: a standard shape for users and groups and a standard set of HTTP requests for creating, changing, and disabling accounts in applications., 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:
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 APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests. request has to be answered for the right organization. The photo service puts the organization in the access tokens it issues:
{
"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:
| Shortcut | What goes wrong | What to do instead |
|---|---|---|
| Matching accounts by email across organizations | A provider that states [email protected] reaches Cedar's account | Key accounts by connection, issuer and subject |
| Routing by unverified domains | A customer claims another company's domain and receives its sign-ins | Verify domain ownership before routing |
| Taking the organization from a claim or parameter | A crafted request or provider claim moves a user into another organization | Derive the organization from the connection |
| Global object IDs without an organization check | Changing /albums/91 to /albums/92 reads another customer's album | Scope every lookup by the token's organization |
| Caches keyed by user or object alone | One organization's answer is served to another | Include the organization in every cache key |
| Support tools with direct database access | Staff see every organization at once, unrecorded | Support 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.
Try it in the Lab
- Route a customer's designer to their own provider and create their account thereTreat Lab Mail as a customer organization's identity provider, hide its button, route a designer to it by email domain, let the connection create her account, and read the tenant in her token.