Appearance
Authentication Designs
These questions reuse the building blocks explained in depth in the identity module. Each answer here is the design: the components, how they connect, and the decisions an interviewer wants to hear, with links to the detail.
35. How would you design a secure login system?
The short answer
An auth service owns credentials and sessions. Passwords are hashed with Argon2id; passkeys and MFA are supported, with phishing-resistant options for admins. Login is protected by rate limits per account and IP, breached-password checks, bot challenges after failures, and identical errors for unknown users. On success it creates a server-side session in Redis with a new ID, sent as a __Host-, HttpOnly, Secure, SameSite=Lax cookie, with idle and absolute timeouts. It provides secure password reset, email verification, a devices and sessions page, audit logs and alerts on suspicious logins.
| Decision | Detail |
|---|---|
| Password storage | Argon2id, OWASP parameters (bcrypt versus Argon2) |
| Brute force | Per-account and per-IP limits, growing delays, no permanent lockout (lockout) |
| MFA and passkeys | Passkeys preferred; TOTP; SMS only as fallback (passkeys) |
| Session | Server-side, cookie only holds the ID (securing cookie login) |
| Recovery | Single-use hashed reset tokens; revoke all sessions after reset (password reset) |
36. How would you design a JWT-based authentication system?
The short answer
An auth server issues a short-lived access token, a JWT of 5 to 15 minutes signed with an asymmetric key such as ES256, containing iss, sub, aud, exp, scopes and a kid, plus an opaque, rotating refresh token stored hashed on the server. It publishes public keys at a JWKS endpoint. APIs verify tokens locally, checking algorithm, signature, issuer, audience and expiry. Refresh happens only at the token endpoint, with rotation and reuse detection. Revocation uses refresh-token deletion plus a small deny list or per-user "valid after" time. Browser apps keep tokens server-side behind a session cookie.
| Part | Design |
|---|---|
| Access token | JWT, 10 minutes, aud per API (JWT claims) |
| Signing | Private key in a KMS; public keys in JWKS; rotate by kid (HS256 versus RS256) |
| Verification | Fixed allowed algorithms, issuer and audience (signing and verifying) |
| Refresh | Opaque, hashed, rotated, family revoked on reuse (rotation) |
| Revocation | Short expiry plus deny list or valid-after (revoking JWTs) |
| Browser storage | Back end for front end; no tokens in localStorage (token storage) |
37. How would you design OAuth-based login?
The short answer
Use OpenID Connect, not plain OAuth, so you get a verifiable ID token. The web app is a confidential client using the authorization code flow with PKCE, state and nonce, through a certified client library. The callback exchanges the code server-side, verifies the ID token, links the external identity to a local user by issuer plus subject, and starts the app's own session. Support several providers through one identity table, link accounts only on verified emails, and handle denial, expired state and provider outages gracefully.
The end-to-end flow, the checks and the code are in OIDC login flow and implementing OAuth login.
The data model that supports several providers:
| Table | Columns |
|---|---|
users | id, email, email_verified, name |
identities | user_id, issuer, subject, email_at_link_time, created_at; unique on (issuer, subject) |
sessions | In Redis: session_id → user_id, auth_method, auth_time |
38. How would you design Google login?
The short answer
Register an OAuth client in Google Cloud with exact redirect URIs. On "Sign in with Google", redirect to Google's authorize endpoint with scope=openid email profile, state, nonce and PKCE. In the callback, exchange the code, verify the ID token's signature against Google's JWKS, iss of https://accounts.google.com, aud equal to your client ID, exp and nonce. Find or create the user by Google's sub, trusting email only if email_verified is true, then create your own session. Keep Google's tokens only if you need Google APIs.
The whole flow, with a diagram, is in how Google login works. The design decision worth saying: "Google proves who the user is once; after that, our own session controls access, so revoking our session logs them out of our app regardless of their Google session."
39. How would you design enterprise SSO for multiple applications?
The short answer
Put one identity provider, such as Entra ID, Okta or Keycloak, at the centre. Each application registers as a client, using OIDC for new apps and SAML for those that only support it. Users sign in once at the IdP, with MFA and Conditional Access, and each app receives a signed token or assertion and creates its own short session. Groups and app roles flow as claims; SCIM provisions and deprovisions accounts in each app; back-channel logout and short app sessions limit how long access outlives a disabled account. Central audit logs record every sign-in.
The flow across apps is drawn in how SSO works.
| Decision | Choice |
|---|---|
| Protocol per app | OIDC by default; SAML where required (SAML versus OIDC) |
| Session lengths | IdP: a working day. Apps: 30 to 60 minute idle timeout (SSO cookies) |
| Access per app | Assignment at the IdP, by group |
| Joiners and leavers | SCIM provisioning (SCIM) |
| Logout | Back-channel logout plus short app sessions (single logout) |
40. How would you design SAML-based login?
The short answer
Your app is the service provider. Each customer's IdP connection stores its entity ID, SSO URL and signing certificates, ideally from a metadata URL. Use SP-initiated login: find the tenant from the email domain, send an AuthnRequest, remember its ID, and receive the response at the ACS URL. Validate with a maintained library: signature over the assertion, issuer, audience, destination, time window, InResponseTo, and one-time use of the assertion ID. Map a stable NameID to the user, groups to roles, create a session, and monitor certificate expiry per customer.
The full design, data model and security points are in designing SAML login, and validation in validating assertions.
41. How would you design multi-tenant SaaS authentication and tenant isolation?
The short answer
Every user belongs to one or more tenants, and every request runs in one tenant context, taken from the session or token, never from a client-chosen header. Authentication is per tenant: password and passkeys for small customers, SSO through SAML or OIDC for enterprises, chosen by verified email domain, with an optional "SSO required" setting. Tokens and sessions carry tenant_id. Authorization checks roles within that tenant. Data isolation is enforced in layers: a data-access layer that always filters by tenant, database row-level security, tenant-prefixed cache and storage keys, and separate databases for customers that need them.
Details: tenant isolation, SAML for many tenants and supporting SAML and OIDC.
42. How would you design a secure refresh-token system?
The short answer
Refresh tokens are opaque random values, stored hashed with user, client, device, family ID, an idle expiry and an absolute expiry. Every use rotates the token; reusing an old one revokes the whole family and alerts the user. They are sent only to the token endpoint, in an HttpOnly cookie scoped to the refresh path for browsers or the OS keychain on mobile, and can be bound to the device with DPoP. They are revoked on logout, password change and admin action, and listed to the user as active sessions.
The table design, the rotation code and the checklist are in designing a refresh-token system and rotation with reuse detection.
43. How would you design token revocation at scale?
The short answer
Make revocation mostly unnecessary with short access tokens, 5 to 15 minutes, and revoke the refresh token in the database. For immediate cut-off, keep a tiny deny list of revoked token IDs with entries that expire when the token would have, plus a per-user "valid after" timestamp for "log out everywhere". Distribute both by pushing revocation events to every service, which keeps them in memory, with Redis as the shared fallback. Keep introspection for the few highest-risk APIs, and rotate the signing key for a key compromise.
The diagram and the numbers are in revocation at scale.
44. How would you design authentication for microservices?
The short answer
Authenticate users once at the edge: the API gateway or a BFF validates the user's token or session. Inside, every call carries two identities: the calling service, proven by mTLS from a service mesh or a client-credentials token with an audience, and the end user, carried as a signed token, ideally exchanged for a narrower, audience-specific token per hop. Each service verifies both itself and makes its own authorization decision; nothing is trusted because it comes from inside the network, and plain headers such as X-User-Id are never accepted as identity.
The two-question picture is in how services authenticate each other; token exchange is in token exchange; the end-to-end architecture is in securing microservices.
45. How would you design API Gateway authentication?
The short answer
The gateway is the first, coarse check. It terminates TLS, validates the incoming credential, a JWT by signature, issuer, audience and expiry against cached JWKS, or an API key by hashed lookup, or a session through the BFF, and rejects bad requests with 401 before they reach services. It applies rate limits and quotas per client, strips any client-sent identity headers, and forwards a verified identity to services, as the original token or a newly minted internal token. Fine-grained authorization stays in the services; the gateway never becomes the only line of defence.
| Gateway does | Service still does |
|---|---|
| Verify token signature, issuer, audience, expiry | Verify the token again, or the internal token |
| Check required scope for the route | Check this user may act on this record |
| Rate limits per API key or user | Business rules |
Remove client-sent X-User-* headers | Never trust identity from headers |
| Log every request with a trace ID | Audit sensitive actions |
Gateway responsibilities in general: API gateways.
46. How would you design a centralized IAM platform similar to Entra ID or Okta?
The short answer
The core is a multi-tenant directory of tenants, users, groups, applications and credentials, and a token service implementing OIDC, OAuth 2.0 and SAML. Around it: an authentication service supporting passwords, passkeys and MFA; a policy engine for conditional access, evaluating user, device, location and risk at each sign-in; sessions with SSO cookies; federation to external IdPs; provisioning with SCIM; an admin and self-service portal; and audit logs. It must be extremely available, multi-region, with signing keys in HSMs, strict tenant isolation, and rate limiting against credential attacks.
| Requirement | Design |
|---|---|
| Availability | Multi-region active-active for token issuing; the directory replicated, with writes in a home region per tenant |
| Latency | Signing keys cached as handles; JWKS on a CDN; tokens verified locally by apps |
| Isolation | Tenant ID on every record and key; per-tenant rate limits so one tenant cannot starve others |
| Security | HSM-backed signing keys, rotated; admin actions need phishing-resistant MFA; full audit |
| Attacks | Credential stuffing defences, consent-phishing review, anomaly detection |
| Extensibility | Custom claims, hooks, and per-tenant branding |
47. How would you implement enterprise identity federation?
The short answer
Federation lets users from a partner's or customer's own IdP access your systems with their home accounts. Establish trust by exchanging metadata, entity IDs, endpoints and signing certificates, for SAML, or issuer and JWKS for OIDC. Configure claims mapping: which attribute is the stable user ID, which become email, name and groups, and how groups map to your roles. Choose provisioning: just-in-time at first login or SCIM. Restrict which domains each trusted IdP may assert, monitor certificate expiry, and log federated sign-ins separately so you can audit partner access.
| Step | Detail |
|---|---|
| Trust | Exchange metadata; pin issuer and certificates per partner (federation) |
| Identity key | Partner's persistent NameID or sub, never only email |
| Claims | Map and transform attributes per partner (claims transformation) |
| Accounts | Just-in-time or SCIM (JIT) |
| Guardrails | A partner's IdP may only assert users in its own verified domains |
| Operations | Certificate expiry alerts, a test login per partner, audit of partner sign-ins |