Add SSO to an existing SaaS one customer at a time
Acme and Beacon already use your Reports product. Acme wants SSO. Beacon wants to keep its current login. Your company also runs Ledger, which has its own user IDs and subscriptions. A report owned by Reports account 42 must still have the same owner after Acme enables SSO.
| Customer | Login | Reports | Ledger |
|---|---|---|---|
| Acme | Corporate OIDC or SAML | Existing account 42 can open its reports |
Requires a separate product assignment |
| Beacon | Existing application login | Existing accounts continue using their current sessions | Uses Ledger's own IDs and assignments |
Connect Acme's organization
Enable organizations and configure Acme's identity connection. Register each product backend as a separate service, for example reports and ledger. Give a backend auth:login for organizations where it starts SSO and authorization:check where it checks product access. Keep the operator credential on the provisioning backend. You can omit local_authentication when the applications keep password sign-in.
Store Acme's OE organization and connection IDs on its existing workspace. On your login page, look up the workspace and use those settings to start Acme's SSO flow. Leave Beacon on its existing login route.
The examples below use four server-side SDK clients. Load the corresponding raw keys from each backend's secret store.
import { EnterpriseClient } from "@open-enterprise/sdk";
const client = (apiKey: string) => new EnterpriseClient({ endpoint: oeEndpoint, apiKey });
const operator = client(accountOperatorKey);
const migrator = client(migrationOperatorKey);
const reports = client(reportsServiceKey);
const ledger = client(ledgerServiceKey);Preserve existing account IDs
Use an operator with accounts:manage to import Acme's existing people. In this example the deployment defines an analyst role with the action reports:open. Use the role that represents each person's current access in your product.
const imported = await operator.operator.importUsers({
mode: "identity_only",
users: [{
external_id: "42",
email: "ada@acme.example",
email_verified: true,
memberships: [{ organization_id: acmeOrgId, role: "analyst" }],
}],
});
const row = imported.results[0];
if (!row?.imported) throw new Error(row?.error?.message ?? "Missing import result");
const userId = row.imported.user_id;For a deployment-wide import, choose stable external IDs that are unique across the source system. When two products use overlapping IDs, map each product's IDs in its own namespace as described below.
From a reviewed Acme directory export, obtain the immutable subject for the person who owns account 42. Before allowing Acme's first SSO login, have an operator with identities:migrate plan and run the mapping.
const plan = await migrator.operator.migrations.plan({
organization_id: acmeOrgId,
connection_id: acmeConnection,
source: "Acme directory export approved in CHG-1042",
mappings: [{ user_id: userId, subject: "00u1a2b3c4" }],
});
// A planned item's detail describes an existing link, a proposed link or a conflict.
const completed = await migrator.operator.migrations.run(plan.id);
if (completed.status !== "completed") throw new Error("Review the recorded conflicts");Review the planned mapping before submitting the run. If another account already owns that subject, use the conflict report to correct the source mapping. For a rollback, restore the previous login policy and confirm the affected users can use another sign-in method. Migration and rollback runbook
Redeem the callback in Reports
Use the application's existing pending-login transaction to store the workspace, state and PKCE verifier. On callback, validate the state against that transaction. Redeem the code on the Reports backend.
const login = await reports.auth.exchangeProfile(code, pendingLogin.verifier);
if (login.organization_id !== pendingLogin.organizationId ||
login.membership?.status !== "active" || !login.user.external_id) {
throw new Error("Account unavailable in this workspace");
}
const decision = await reports.authorization.check({
organizationId: login.organization_id,
subjectId: login.user.id,
action: "reports:open",
});
if (!decision.allowed) throw new Error("Reports access required");
// These calls use the application's existing database and session implementation.
const account = await app.accounts.requireActive(login.organization_id, login.user.external_id);
await app.sessions.start(account.id, login.organization_id);Account 42 still owns its reports. Store the canonical login.user.id alongside it for later access checks. Ledger checks ledger:open on its own backend. Membership in Acme alone leaves Ledger closed. For application sessions that outlive sign-in, consume membership and deactivation events and close those sessions when access ends. Broker sessions
Reconcile an acquired product
If Ledger also calls a person 42, review that association using the Ledger service ID. The operator needs accounts:manage. The Ledger backend needs members:read in the appropriate organization to look up the resulting alias.
const batch = {
product_id: "ledger",
source: "Ledger customer export reviewed in CHG-1071",
mappings: [{ external_id: "42", user_id: ledgerUsersCanonicalId }],
};
const preview = await operator.operator.reviewUserAliases({ ...batch, mode: "preview" });
if (preview.results.every(row => row.status === "ready" || row.status === "already_linked")) {
const applied = await operator.operator.reviewUserAliases({ ...batch, mode: "apply" });
if (!applied.results.every(row => row.status === "linked" || row.status === "already_linked")) {
throw new Error("The mapping changed during review");
}
}
const resolved = await ledger.organizations.resolveUserAlias(beaconOrgId, "42");Each review accepts up to 500 mappings. An unknown canonical user or an alias already owned by a different user prevents the entire batch from applying. A conflict reports both the requested user_id and existing_user_id for review. Applying a reviewed alias records its product, source, operator and canonical user in the deployment operator's audit log. Resolution selects the product from the authenticated service and requires an active member of the requested organization. The application still checks its product assignment before opening business records.
On successful apply, Ledger can store each returned user_id on the corresponding legacy account. Its SSO callback can then look up its existing customer and account by organization and canonical user ID. When a legacy integration starts with a Ledger account ID instead, resolveUserAlias supplies the canonical ID for an access check.
The PostgreSQL-backed integration tests cover the two workspaces, overlapping product IDs, broker exchange, retained report ownership and independent product access. Integration tests (crates/enterprise-runtime/tests/support/product_identity.rs)