KatInterview

Unified Login Across Independently Hosted Domains Using OIDC

System DesignModel answer
MediumModel answerSystem Designauthenticationoauthoidc

Last updated

Design a shared identity layer that lets users sign in once and move freely between two separate domains, then scale the same pattern to many sites and delegated API access.

Two products live on entirely separate domains: atlas.app.io and compass.app.io. Neither is a subdomain of the other, so they cannot share a browser cookie. A user who logs into one should be able to navigate to the other without being asked to enter their password again. Your job is to design the system that makes that happen.

Walk through the mechanics from first principles: what shared component enables the seamless transition, how the browser flow actually works, and what each site ends up holding at the end. Be specific enough that an engineer could implement it.

Then generalize: the company will eventually operate dozens of sites on the same pattern, and some of those sites need to call third-party APIs (a project tracker, a data warehouse, a messaging platform) on behalf of the signed-in user. Describe how to extend the design to cover both cases, and be precise about the difference between a user being recognized by a third-party tool and the application being permitted to call that tool's API.

Constraints

  • atlas.app.io and compass.app.io are distinct registrable domains. Cookies set on one are not readable by the other.
  • Each site can redirect the browser to another domain and can handle a callback from that domain on the server side.
  • "No repeated login" means no second password prompt as long as the shared identity session is still alive. It does not require any direct communication between the two sites.
  • You may not rely on cross-site iframes reading another site's cookies; that approach is blocked by modern browsers.
  • compass.app.io has its own existing user database. Account migration or linking must be addressed.

What to cover

Part 1 — The two-site flow

Walk through a user's first login on atlas.app.io and their later visit to compass.app.io. Include:

  • Why a shared identity provider (IdP) solves the cross-domain problem
  • The full authorization-code exchange: redirects, state/PKCE binding, token validation, and how each site forms its own local session
  • What happens when the IdP's own session has already expired by the time the user reaches the second site

Part 2 — Many sites and delegated API access

  • How the two-site pattern scales to an arbitrary number of sites without changing its shape
  • How the application decides whether a given user is allowed to access a given third-party tool, and who can revoke that
  • The difference between federating a user's identity into a third-party tool versus obtaining an OAuth access token to call that tool's API — and why an ID token is the wrong credential for the second case

Hints

Hint 1

The two sites don't need to communicate with each other at all. Think about what a shared identity provider already knows by the time the second site redirects to it — and what that means for the user experience.

Hint 2

Trace the authorization-code flow all the way through: what the browser carries, what stays server-to-server, what each party validates, and what credential the site actually uses as its ongoing session. The IdP tokens and the local session are two separate things.

Hint 3

When it comes to third-party tools, ask whether the user is the subject of the action or whether the application is acting autonomously. That distinction maps directly onto which OAuth flow and which token type belongs in each scenario.