What you'll learn: By the end of this lesson you will be able to explain what changes when each customer brings its own identity provider, send a user to the right provider, state which checks the server makes on an OpenID Connect or SAML response and why the browser must not make them, key identities by issuer and subject, end sessions when a person leaves, ask for a fresh sign-in before a sensitive action, design an audit trail the UI feeds but does not own, and apply data-minimisation ideas to what a screen shows and stores. This is engineering education, not legal advice.
Think of a company that rents desks in several client buildings. Each front desk checks a badge issued by that client, not by you. You must know which client's desk to send a visitor to, trust only that client's badges on that floor, and stop honouring a badge the moment the client withdraws it. Enterprise single sign-on is that arrangement.
The running example is a support console sold to companies (the enterprise side of the seller dashboard from Multi-Tenant UI Architecture). Customers "Acme" and "Bravo" each use their own identity provider, want an audit trail of admin actions, and ask security questionnaires about sessions and personal data. All names, lifetimes and numbers are illustrative.
The core idea
- Each tenant is its own trust relationship. Acme's provider may speak OpenID Connect and Bravo's SAML. A token or assertion is believed only for the tenant whose provider issued it.
- The server verifies; the UI routes and reacts. The browser carries messages between the app and the provider. It cannot be trusted to judge them.
- Audit and compliance are properties of the whole system. The UI contributes context, limits what it shows and stores, and gives admins readable views. It never holds the only record.
Sending a user to the right provider
The user types an email or picks a company. The app maps that to a tenant and the tenant to its provider configuration: protocol, issuer, client id, sign-in URL. A common design is discovery by email domain; the mapping is data you own and the user's input is only a lookup key.
SAML distinguishes two starts. In SP-initiated sign-in the user reaches the service provider first and is sent to the identity provider; the OASIS technical overview calls it the most common scenario. In IdP-initiated sign-in the provider sends an assertion with no prior request from the app. OWASP's SAML cheat sheet says an unsolicited response is inherently less secure by design, because the service provider cannot create a pre-login session to guard against login CSRF; if you support it, allow-list any URL-based RelayState and detect replay.
Figure 1. Enterprise sign-in, per tenant
How to read this: the console looks up which provider belongs to the tenant and redirects. The provider's answer comes back through the browser but is verified only by the server in the warning box, which also writes the audit event.
What the server checks, and why not the browser
Take OpenID Connect first. OpenID Connect Core says the issuer in the ID token must exactly match the provider's issuer identifier, that the token must be rejected if it does not list the client as an audience, that the current time must be before exp, and that the nonce must match the one sent. The subject claim sub is, in the spec's words, a locally unique and never reassigned identifier within the issuer. In a multi-tenant app that has two consequences.
- Expected issuer and audience are per tenant. A token that is perfectly valid from Bravo's provider must be rejected on Acme's sign-in.
- Identify a person by issuer and subject together. Two providers may both issue
sub: "u-42"for different people.
Illustration 1: the minimal example, per-tenant claim checks
The signature is assumed already verified; this model shows only the tenant-specific checks. Run in Node 26.13.1:
const tenants = {
t_acme: { issuer: "https://login.acme.example", clientId: "app-acme" },
t_bravo: { issuer: "https://idp.bravo.example", clientId: "app-bravo" },
};
function checkClaims(tenantId, claims, nowSec) {
const t = tenants[tenantId];
if (!t) return "reject: unknown tenant";
if (claims.iss !== t.issuer) return "reject: issuer is not this tenant's provider";
const aud = Array.isArray(claims.aud) ? claims.aud : [claims.aud];
if (!aud.includes(t.clientId)) return "reject: audience";
if (!(nowSec < claims.exp)) return "reject: expired";
return `accept: identity key ${claims.iss}|${claims.sub}`;
}
const now = 1000;
const good = { iss: "https://login.acme.example", sub: "u-42", aud: "app-acme", exp: 1300 };
console.log("1", checkClaims("t_acme", good, now));
console.log("2", checkClaims("t_bravo", good, now));
console.log("3", checkClaims("t_acme", { ...good, exp: 900 }, now));
console.log("4", checkClaims("t_acme", { ...good, iss: "https://idp.bravo.example" }, now));
console.log("5", checkClaims("t_bravo", { iss: "https://idp.bravo.example", sub: "u-42", aud: ["x", "app-bravo"], exp: 1300 }, now));
Output, from running it in Node 26.13.1:
1 accept: identity key https://login.acme.example|u-42
2 reject: issuer is not this tenant's provider
3 reject: expired
4 reject: issuer is not this tenant's provider
5 accept: identity key https://idp.bravo.example|u-42
Rows 1 and 5 share a sub but are two identities, because the key includes the issuer. Rows 2 and 4 are the cross-tenant mix-ups. The model omits the signature, nonce and key handling, which a maintained library does on the server (OAuth, OIDC and PKCE in Single-Page Apps covers the flow).
For SAML, OWASP's cheat sheet lists the service provider's checks: the Audience must match the provider's entity id, InResponseTo must match the request, NotBefore and NotOnOrAfter must hold, the Destination must match the expected consumer URL, and signing keys should come from your configuration rather than from the document. The browser carries the base64 response to the server through the POST binding; the UI has no business parsing it.
Provisioning and sign-out: when people leave
An enterprise customer expects that disabling someone in their directory ends that person's access. Two mechanisms matter.
- Provisioning. SCIM (RFC 7644) is an HTTP protocol for provisioning identity data across domains, with
/Usersendpoints for create, read, replace, patch and delete. A SCIM delete need not remove the record permanently, but later operations must return 404. Decide what a deprovisioned user means in your product: sessions ended, content reassigned, audit entries kept. - Sessions. Signing out of your app does not end the provider's session (JWTs, SSO and the Session Lifecycle walks through the clocks). RP-initiated logout redirects the user to the provider's logout endpoint. OpenID Back-Channel Logout lets the provider call a registered endpoint on the app with a signed logout token carrying
suborsid, so the app clears those sessions without the browser; the spec also says the app should revoke refresh tokens issued withoutoffline_accessfor that session.
Tenants usually want to set session policy themselves. NIST SP 800-63B shows the shape of one: at assurance level AAL2 it says reauthentication SHOULD occur within 24 hours overall and after no more than 1 hour of inactivity. That document is about US federal digital identity, not a rule for your customers. Make idle and absolute timeouts tenant settings within bounds you choose, enforced by the server.
Figure 2. Ending a session when the provider ends it
How to read this: the notification travels server to server, so it works while the user's tab is closed or idle. The UI only learns on its next request, so it must handle a 401 anywhere by clearing client state and showing sign-in.
Step-up: asking again before a sensitive action
Some actions deserve a fresh proof: exporting all users, changing the identity provider, deleting a tenant. OpenID Connect Core gives the vocabulary. prompt=login asks the provider to reauthenticate the user; max_age is the allowable elapsed time since the user was last actively authenticated, and when it is used the ID token must carry auth_time. The spec notes max_age=0 is equivalent to prompt=login. The acr claim and acr_values request let you ask for a particular authentication context; what values mean is agreed with each provider.
Illustration 2: the realistic example, a step-up decision
The server decides; the UI only redirects when told to. A pure model of the decision, run in Node 26.13.1:
function stepUp(claims, nowSec, maxAgeSec) {
if (typeof claims.auth_time !== "number") return "deny: no auth_time, ask again with max_age";
const age = nowSec - claims.auth_time;
return age <= maxAgeSec ? `allow: authenticated ${age}s ago` : `deny: authenticated ${age}s ago, limit ${maxAgeSec}s, redirect with prompt=login`;
}
console.log(stepUp({ auth_time: 9990 }, 10000, 300));
console.log(stepUp({ auth_time: 9000 }, 10000, 300));
console.log(stepUp({}, 10000, 300));
Output, from running it in Node 26.13.1:
allow: authenticated 10s ago
deny: authenticated 1000s ago, limit 300s, redirect with prompt=login
deny: no auth_time, ask again with max_age
The 300-second limit is an illustrative policy. A missing auth_time is a denial, not a pass. The UI's part is the redirect and then returning the user to what they were doing; the decision stays on the server.
Figure 3. Step-up decision
and recent enough?"} B -->|"yes"| C["Perform action"] B -->|"no"| D["Answer: step-up required"] D --> E["UI redirects with prompt=login"] E --> A C --> F["Audit: allowed"] D --> G["Audit: denied, step-up"]
How to read this: the loop at the top is the UI sending the user to the provider and retrying the same request. Both outcomes leave an audit event.
Audit: the UI feeds it, the server owns it
OWASP's Logging Cheat Sheet says each event should record when, where, who and what. It lists authentication successes and failures, authorization failures and user administration actions among the events to log. It also lists data to exclude, including access tokens, passwords, keys and session identifiers (which may be hashed for tracking), and recommends tamper detection for stored logs. Audit Logging is the server-side treatment.
For the front end that means:
- The record is made on the server, where the action is authorized and performed. A client-side "log this" call can be skipped, forged or blocked. OWASP notes time cannot always be synchronised on user-controlled devices, so the server assigns the timestamp.
- The UI adds context: a correlation id and the action name (Logging, Tracing and Correlation IDs), never tokens or copies of customer records.
- Reading the trail is a feature. Admins need filters (actor, action, date), stable pagination, export and readable descriptions. Viewing or exporting is itself audited, and the view shows only its own tenant's events.
An illustrative event has the fields at, tenant, actor, action, target, outcome and reqId; it is a design sketch, not a standard, and denials such as denied:step-up belong in it.
Compliance in the UI: privacy by what you show and keep
A front end cannot make a product compliant; people, processes and lawyers do that. It can avoid creating problems. GDPR Article 5 states principles an engineer can translate into screens: personal data should be limited to what is necessary (data minimisation), kept identifiable no longer than necessary (storage limitation), processed securely, and the controller must be able to demonstrate compliance. Article 25 asks for data protection by design and by default. This lesson does not say which laws apply to you or what they require of your product.
Translated into UI decisions:
- Show the least that does the job. A support list needs a name and ticket id, not the address; reveal sensitive fields on demand and audit the reveal.
- Keep the least on the device. Do not persist customer records in
localStorageor offline caches longer than the task needs; clear them at sign-out. - Do not put personal data in URLs, analytics events or error reports, which travel to systems with other retention rules.
- Make the evidence easy to produce, such as accessibility reports (Accessibility and Compliance).
Trade-offs
| Choice | Gain | Cost |
|---|---|---|
| OIDC and SAML both | Any customer's provider works | Two protocols to verify and test |
| IdP-initiated sign-in | Launch from the customer's portal | Weaker login CSRF protection |
| Back-channel logout | Ends sessions without the browser | Endpoint and session index per app |
| Step-up before sensitive actions | Fresh proof for risky actions | Extra redirects; provider must return auth_time |
| Rich audit viewer in the UI | Admins self-serve | Another surface that must be tenant-scoped and audited |
Build it
This lesson has no lab (lab type none). The three Node snippets above are small models that were run, with their output shown unedited. They omit signatures, keys and the SAML XML handling. Nothing here was tested against a real identity provider, so provider-specific behaviour (claims returned, logout support, acr values) must be checked in each tenant's setup.
In practice: onboarding a SAML-only customer
This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.
The situation
Acme signs in with OpenID Connect. Bravo requires SAML, an 8-hour maximum session, an exportable audit trail and deprovisioning. Today the console has one hard-coded provider, signs out locally, and logs admin actions client-side.
Starting architecture
Figure 4. One provider, local sign-out, client-side logging
How to read this: the warning boxes are the gaps: audit lives where it can be skipped, the server cannot tell tenants' providers apart, and sign-out ends nothing at the provider.
Options considered
| Option | What it fixes | What it costs | Risk |
|---|---|---|---|
| Build SAML into the console | Full control | XML signature code to own | Subtle verification bugs |
| A maintained library or identity service | Verified protocol handling | A dependency | Provider quirks need per-tenant testing |
| Tell Bravo to use OIDC | Nothing to build | Lost deal | The next customer asks again |
The decision
| Field | Decision record |
|---|---|
| Context | Tenants bring different providers and policies; audit and deprovisioning are requirements. |
| Decision | Per-tenant provider config; a maintained SAML and OIDC library on the server; identities keyed by tenant, issuer and subject; app-started sign-in only; back-channel logout for OIDC tenants; tenant-set session limits within server bounds; server-written audit events; step-up for exports and provider changes. |
| Consequences, good | One sign-in flow per tenant, audit that cannot be skipped by the client, sessions that end with the directory. |
| Consequences, bad | Per-tenant setup work and testing, an audit viewer to build and secure. |
| Revisit when | A tenant needs IdP-initiated launch, or a provider cannot send the claims step-up needs. |
Rollout and verification
- Onboard Bravo in staging and walk through sign-in, sign-out, a disabled user and an expired session.
- Run the cross-tenant probe: a valid response from Bravo's provider sent to Acme's sign-in must be rejected.
- Check what the browser holds after sign-out.
- Review events for a sample session: none contains a token.
The 2 a.m. failure
Bravo reports that an employee dismissed last week still opens the console. The console's own session cookie has an idle limit that the employee's regular use kept renewing, there is no absolute limit, and the logout notification from the provider was never registered for SAML tenants.
First three checks: (1) look up the sessions for that issuer and subject; (2) check how the tenant's deprovisioning reaches the app (SCIM call, logout notification, nothing); (3) compare the session's age with the tenant's absolute limit. Mitigation: end the sessions by hand and enforce the absolute limit. Follow-up: wire provisioning or logout to session clearing, and add a test that disables a user and expects a 401 within a stated time.
The other side of this topic
The back end holds the machinery: OAuth 2.0 and OpenID Connect, RBAC, ABAC and ReBAC, Audit Logging and Compliance and Privacy (GDPR). The UI routes, reacts, shows less and stores less.
Architect's notes
- Make the tenant's provider data, not code. A new customer should be a config record plus tests.
- Handle 401 in one place, clearing client state.
Common mistakes
- One expected issuer for all tenants, so any customer's provider is accepted anywhere.
- Using
subor email as a global identity key. - Verifying tokens or assertions in the browser.
- Sign-out that ends only the app's session.
- Client-written audit events as the only record, or tokens and personal data inside them.
Key takeaways
- Each tenant is its own trust relationship: its own provider, issuer, audience and policy.
- The server verifies; the UI routes and reacts to outcomes such as 401.
- Identity is issuer plus subject, within a tenant.
- Provisioning and logout carry a customer's decision to remove someone into your sessions.
- Step-up uses
max_age,auth_timeandprompt=login, decided on the server. - Audit is written on the server; the UI adds context and a good viewer.
- Data minimisation shapes screens and client storage. This is not legal advice.
Practice exercises
Exercise 1: Starter (30 min). Add rows to checkClaims for a right issuer with a wrong audience, and for a missing sub; state what each returns.
Exercise 2: Intermediate (2 hours). Design the tenant provider config record and list which edits require step-up.
Exercise 3: Advanced (half day). Draw the lifecycle of a departing employee at a SAML tenant, from directory change to client storage, and mark every point where a failure would leave access in place.
Related reading
In this course:
- JWTs, SSO and the Session Lifecycle: the clocks behind sign-out and refresh.
- OAuth, OIDC and PKCE in Single-Page Apps: the browser side of the login flow.
- Authentication vs Authorization in the UI: who you are versus what you may do.
- RBAC and ABAC on the UI: permission-aware screens.
- Multi-Tenant UI Architecture: resolving and isolating the tenant.
Official documentation
- OpenID Connect Core 1.0: ID token claims and validation,
prompt,max_age,auth_time. - OpenID Connect Back-Channel Logout 1.0: logout tokens and what the app does with them.
- OpenID Connect RP-Initiated Logout 1.0: asking the provider to end its session.
- SAML V2.0 Technical Overview (OASIS): roles, SSO flows, assertions.
- OWASP: SAML Security Cheat Sheet: the service provider's checks.
- RFC 7644: SCIM Protocol: provisioning users across domains.
- OWASP: Logging Cheat Sheet: audit event attributes and data to exclude.
- GDPR Article 5 and Article 25: principles and data protection by design (an unofficial text; check the official journal for legal use).