Every week, a company terminates an engineer or a sales rep with access to sensitive production data. As part of the offboarding checklist, the IT administrator logs into Okta or Microsoft Entra ID, finds the employee's profile, and clicks Deactivate. The IT admin closes their laptop, confident that the employee is locked out of the company’s entire SaaS stack. Twenty minutes later, that terminated employee opens their personal laptop, refreshes an open browser tab for your B2B SaaS application, and exports the entire customer database. Or worse, a Python script on their local machine continues pulling records via a Personal Access Token (PAT) for the next six months. Why did this happen? Because SAML and OIDC only govern the front door. Once a user is inside your application, your Identity Provider (IdP) is completely blind to what happens next. If you are building a B2B SaaS product, relying on SSO login checks alone means your enterprise customers have a massive, silent offboarding vulnerability. Here is a technical breakdown of the four architectural gaps that keep terminated users active and how to engineer the fixes. 1. The Stateless JWT Trap (Authentication is not the same as Session Management) How the problem gets built: When a user logs in via SAML 2.0 or OIDC, the IdP hands your Assertion Consumer Service (ACS) endpoint a signed payload saying: "As of 9:00:00 AM, Alice is an active employee." Once your backend validates that signature, the SAML transaction is finished. Your backend then issues its own application session—typically a stateless JSON Web Token (JWT) with a 24-hour expiration or an HTTP-only session cookie with a 7-day rolling TTL—so the user doesn't have to bounce back to Okta on every page load. Why it fails during offboarding: If Alice is terminated at 9:15 AM and removed from Okta, Okta does not notify your application in a standard SAML setup. Your API gateway continues to validate Alice's stateless JWT strictly by checking its cryptographic signature and its exp timestamp. Because the signature is still valid, Alice has uninterrupted access for the remaining 23 hours and 45 minutes. [09:00 AM] Alice logs in via Okta SAML ──> App issues 24h JWT + 30d Refresh Token [09:15 AM] IT Admin deactivates Alice in Okta (No webhook fires in basic SAML) [04:30 PM] Alice requests GET /api/v1/customers ──> API Gateway checks JWT signature (VALID) ──> 200 OK The Architectural Fix: Short-Lived Access Tokens + Stateful Refresh Revocation \ Never issue long-lived stateless JWTs for enterprise tenants. Split your session architecture into two tiers: Stateless Access Token (JWT): Set a strict TTL of 5 to 15 minutes. Stateful Refresh Token: Store a cryptographically random token in PostgreSQL (and cache its active status in Redis) tied to the user's user_id and tenant_id. When the 15-minute JWT expires, the browser must hit your /auth/refresh endpoint. This forces a stateful lookup where your backend can verify that tenant_memberships.status == 'ACTIVE' before minting a new 15-minute JWT. 2. Missing SCIM 2.0 Deprovisioning (Closing the IdP-to-App Loop) How the problem gets built: Many engineering teams build SAML/OIDC login + Just-In-Time (JIT) user creation and consider "Enterprise SSO" complete. They skip building a SCIM 2.0 (System for Cross-domain Identity Management) server because customers only ask about SAML during the initial trial. Why it fails during offboarding: JIT provisioning is a one-way street. It creates users when they log in, but it can never tell you when a user leaves. Without SCIM, your application only discovers a user was deactivated in Okta when their session finally expires and they try to log in again—which could be days or weeks later if you use rolling refresh tokens. The Architectural Fix: Wiring SCIM PATCHto a Kill-Switch WorkerWhen you implement a SCIM 2.0/Users/{id} endpoint, deactivating a user in Okta or Entra ID immediately triggers an outbound HTTP request to your backend: PATCH /scim/v2/Users/f47ac10b-58cc-4372-a567-0e02b2c3d479 HTTP/1.1 Host: api.yourproduct.com Authorization: Bearer Content-Type: application/scim+json { "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], "Operations": [ { "op": "replace", "value": { "active": false } } ] } Do not treat this PATCH request as a simple database update (UPDATE users SET active = false). It must execute an Atomic Revocation Cascade:def handle_scim_deactivation(tenant_id: str, user_id: str, db: Session, redis: Redis): with db.begin(): # 1. Mark membership inactive db.execute( """ UPDATE tenant_memberships SET status = 'DEPROVISIONED', updated_at = NOW() WHERE tenant_id = :t_id AND user_id = :u_id """, {"t_id": tenant_id, "u_id": user_id} ) # 2. Delete all active refresh tokens & web sessions db.execute( "DELETE FROM refresh_tokens WHERE tenant_id = :t_id AND user_id = :u_id", {"t_id": tenant_id, "u_id": user_id} ) # 3. Revoke user-scoped API keys, PATs, and OAuth grants! db.execute( """ UPDATE api_keys SET revoked_at = NOW(), revoke_reason = 'SCIM_DEPROVISIONED' WHERE tenant_id = :t_id AND created_by_user_id = :u_id AND revoked_at IS NULL """, {"t_id": tenant_id, "u_id": user_id} ) # 4. Push user_id to Redis revocation denylist (TTL = Max JWT lifetime, e.g., 900s) redis.setex(f"revoked_user:{tenant_id}:{user_id}", 900, "1") # 5. Force-disconnect active WebSockets / gRPC streams publish_ws_disconnect_event(tenant_id=tenant_id, user_id=user_id) By pushing revoked_user:{tenant_id}:{user_id} into Redis with a 15-minute TTL (matching your JWT lifetime), your API gateway can check a sub-millisecond Redis key on every request and kill the user's in-flight JWT within milliseconds of the IT admin clicking "Deactivate" in Okta.3. The "Orphaned Credential" Blindspot: PATs, Webhook Tokens, and CLI Sessions How the problem gets built: Even when teams remember to invalidate web browser sessions, they forget about secondary authentication channels created by the user while they were employed: Personal Access Tokens (PATs) used for CI/CD or local scripts. Long-lived OAuth tokens granted to third-party integrations (Slack bots, Zapier, IDE plugins). Active CLI tokens (~/.yourapp/credentials) and SSH certificates. Why it fails during offboarding: In many schemas, API keys are validated by a simple lookup on the api_keys table (SELECT tenant_id, scopes FROM api_keys WHERE key_hash = :hash). Notice what is missing in that query: it never joins against the users or tenant_memberships table to verify if the creator of the key is still employed. The Architectural Fix: Identity-Bound vs. Service-Account Credentials You must enforce a strict separation in your data model between Human-Bound Credentials and Machine Service Accounts: Credential Type Tied to What Happens When User is Removed from SSO? Personal Access Token (PAT) / CLI Token user_id + tenant_id Immediately Revoked. Any API call using this token must fail with 401 Unauthorized the moment the user's tenant_membership is deactivated. OAuth 2.0 User Grant user_id + tenant_id Immediately Revoked. Refresh tokens issued to third-party apps on behalf of this user are purged. Service Account / System API Key service_account_id + tenant_id Remains Active (With Audit Alert). Never let critical production CI/CD pipelines run on a human engineer's PAT. Provide dedicated Service Accounts owned by the Tenant, and fire a warning notification to workspace admins if the user who originally created the Service Account is deprovisioned so they can rotate the secret if needed. How the problem gets built: Before Acme Corp upgraded to your Enterprise tier and configured SAML SSO, five of their engineers signed up for your product using a standard email + password or "Sign in with Google." Later, Acme's IT admin configures Okta SAML in your portal. Why it fails during offboarding: When one of those original five engineers is fired and removed from Okta, they can no longer log in via the "Sign in with SSO" button. So they go back to your login page, click "Forgot Password" (or use their old cached password / linked Google account), and log right back into the workspace—completely bypassing the Okta SAML wall. The Architectural Fix: Strict Authentication Method Enforcement When a tenant sets enforce_sso = TRUE on their workspace: Block Non-SSO Auth Grants at the Token Minting Layer: Your authentication service must check tenant.enforce_sso before issuing a session token for any identity provider. Even if a user has a valid password_hash in your database, if they are accessing an SSO-enforced tenant, reject password and social OAuth logins with 403: SSO Required by Organization. Disable Password Reset Emails for Managed Domains: If a user requests a password reset for bob@acme-corp.com, and acme-corp.com is a verified domain with enforce_sso = TRUE, do not send a password reset link. Redirect them to their IdP instead. (Sending a password reset link only helps if they still have access to their corporate inbox, and creates confusion or race conditions during offboarding). The Offboarding Audit Checklist for Technical PMs & Architects If you want to test whether your application actually revokes access when a user is removed from SSO, run this 5-minute test in your staging environment today: The "Open Tab" Test: Log in as a test user via SAML, open a dashboard tab, and deactivate the user in your IdP. Wait 60 seconds and click a button that triggers a POST or GET API call in that open tab. Does it return 401 Unauthorized, or does it still load data? The PAT Test: Generate a Personal Access Token as that user, deactivate the user via SCIM, and run a curl command with that Bearer token. Does the API gateway reject it? The WebSocket Test: Open a live streaming view (WebSockets or Server-Sent Events) as the user, then deactivate them in the IdP. Does the server actively close the socket, or does data keep streaming until the browser tab is closed? The No-SCIM Fallback: What if a mid-market customer uses SAML SSO, doesn't configure SCIM, and removes a user in Okta? Because you won't receive a SCIM webhook, do you enforce a Maximum Absolute Session Lifetime (e.g., forcing a silent SAML AuthnRequest re-check every 12 or 24 hours) so deprovisioned users can't coast on a 30-day rolling refresh token?
The Illusion of the “Kill Switch”: Why Removing a User From SSO Doesn’t Always Revoke Access
Full Article
Original Source
Read the full article at Hackernoon →KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.