Connect one app to many business customers
Serve every business customer from one SaaS app, each signing in to their own realm, with the app trusting each realm's issuer and telling their tokens apart.
APIOpenID Connect Core 1.0, OpenID Connect Discovery 1.0
You sell one app, https://app.example.com, to many businesses. Each business customer has a realm of its own
beneath your customer realm (see A realm per business customer), so their
users, administrators and sign-in settings are theirs. This guide is for the developer who connects the one app to
all of those realms, here acme at foobar-acme.cvyuh.com and globex at foobar-globex.cvyuh.com. It answers
four questions: where the app sends each user, where the app is registered, which issuers and keys it trusts, and how
it tells one business customer’s tokens from another’s.
Before you start:
- each business customer has its realm, with its host name;
- you hold
RealmOwnerin your customer realm, which reaches every realm beneath it, with your session in$CVYUH_SESSION(see Call the API); or each business customer’s own administrator does their realm’s step; - the app uses an OpenID Connect library that can hold more than one provider.
The four answers
Section titled “The four answers”| Question | Answer |
|---|---|
| Where does the app send a user? | To their business customer’s realm host. The app decides which, from its own records: the realm doesn’t find a business customer from an email address |
| Where is the app registered? | In each business customer’s realm. A client belongs to one realm, and a realm knows no client of another |
| Which issuer and keys does it trust? | Each realm’s own: for acme, issuer https://foobar-acme.cvyuh.com/oauth2, with keys at that issuer’s jwks_uri |
| How does it tell them apart? | By the token’s iss. Key every user by iss and sub together |
Connect the app
Section titled “Connect the app”-
Keep a map from your tenants to realm hosts. In your app, each business customer you serve has a realm host:
acmeisfoobar-acme.cvyuh.com. Choose the tenant the way your app already does, by a subdomain such asacme.app.example.com, a tenant picker, or the domain of the email address the user types, and look up its host. -
Register the app in each realm. On each realm’s own host, create the same client. The client ID can be the same in every realm; give each its own secret:
Terminal window curl "https://foobar-acme.cvyuh.com/api/v0/am/objects/v1/oauth2Client?id=example-app" \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-d '{"status": "active","clientName": "Example App","tokenEndpointAuthMethod": "client_secret_basic","clientSecret": "<a secret for acme>","grantTypes": ["authorization_code", "refresh_token"],"redirectUris": ["https://app.example.com/callback"],"scopes": ["openid", "profile", "email"],"defaultScopes": ["openid"],"allowedResources": ["https://app.example.com/api"],"defaultAudience": "https://app.example.com/api"}'The realm answers
201. Repeat onfoobar-globex.cvyuh.comwith globex’s secret. Do it as part of setting up each new business customer. -
Add each realm as a provider in the app. Point the library at each realm’s discovery document,
https://foobar-acme.cvyuh.com/oauth2/.well-known/openid-configuration. It reads the issuer,https://foobar-acme.cvyuh.com/oauth2, the endpoints, and thejwks_uriwhose keys sign that realm’s tokens. Store the client secret for that realm beside it. -
Send each user to their realm. When a user of acme chooses Sign in, the app sends them to acme’s authorization endpoint, from acme’s discovery document, with a PKCE challenge and a
statethat records acme. The user signs in with acme’s settings, and sees acme’s consent page. -
Check the answer against the realm you chose. On the callback, find the provider from
state, exchange the code at that realm’s token endpoint, and check the ID token with that realm’s keys. Itsissmust be the issuer you sent the user to. Anything else is refused.
Check it worked
Section titled “Check it worked”Sign in as a user of acme and decode the ID token: iss is https://foobar-acme.cvyuh.com/oauth2. Sign in as a user
of globex: iss is https://foobar-globex.cvyuh.com/oauth2, and the two users’ records in your app are apart, even if
their sub values ever matched.
What to know
Section titled “What to know”- Each realm signs with its own keys. Read them from each realm’s
jwks_uri, and refresh them as your library does; see Signing keys. - Sessions and consent are per realm. A user signed in to acme isn’t signed in to globex, and consent given in one realm means nothing in another.
- One person in two business customers has two accounts, one in each realm.
- Your API checks the same way. An API that serves every business customer accepts each realm’s issuer and keys,
and keys its data by
iss.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
invalid_client at one business customer only | The app isn’t registered in that realm, or its secret there is different | Register it in that realm, and use that realm’s secret |
| The ID token’s issuer doesn’t match | The app checked it against another realm’s issuer | Find the provider from state, not from the token |
| A signature doesn’t verify | The app used another realm’s keys | Use the keys from the issuer’s own jwks_uri |
redirect_uri refused at one business customer | That realm’s client lists other return addresses | List the same redirectUris in every realm |
Undo it
Section titled “Undo it”To stop the app for one business customer, deactivate its client in their realm:
curl -X PATCH https://foobar-acme.cvyuh.com/api/v0/am/objects/v1/oauth2Client/example-app \ -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \ -H "Content-Type: application/json" \ -d '{ "status": "inactive" }'Then remove that realm from the app’s providers.
Related
Section titled “Related”- A realm per business customer: make and hand over each realm.
- Discovery: what each realm’s discovery document holds.
- Get started with Customer Identity: one app and one realm, end to end.