SCIM Provisioning & Deprovisioning That Actually Removes Access
Here is a scenario I now test on every enterprise SSO integration. An employee leaves a customer company. Their IT team disables the account in the identity provider. The next morning, the ex-employee's laptop is still logged in to your SaaS app, because the session cookie is valid for 30 days and nobody told your app anything. Their personal API token, created months ago for a script, still…
When a user leaves a company, their identity provider (IdP) sends a deprovisioning request to your application. This request includes the user's unique identifier, such as a username or email address. Your application must respond to this request by blocking login, revoking any live sessions, disabling API tokens and pending invites, and logging the change—all within a single, transaction-safe step.
To accomplish this, your application must first authenticate the IdP per tenant. Each customer tenant is assigned a unique long random bearer token for SCIM, stored hashed and rotatable. A middleware function checks the bearer token in the request and ensures it corresponds to the correct tenant's users. If the token is invalid or not associated with a tenant, the application returns a 401 Unauthorized response.
Next, the application handles the PATCH /Users/{id} endpoint with active: false. This endpoint is sent by the IdP when deprovisioning a user. The application must normalize the different ways IdPs express deactivation, such as replace active with false or active: false. Once normalized, the application uses a transaction to update the user's status, kill all live sessions (database or Redis), and disable any API tokens and pending invites. Finally, the application logs the change to maintain a record of the deprovisioning event.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.