kavachOS
Authentication

SCIM

Directory sync for enterprise identity providers.

SCIM 2.0 lets Okta, Azure AD, and Google Workspace automatically provision and deprovision users in your app. When an employee is onboarded in the directory, they get access. When they leave, access is removed.

Setup

Add the plugin

import { createKavach } from 'kavachos';
import { scim } from 'kavachos/auth';

const kavach = await createKavach({
  database: { provider: 'postgres', url: process.env.DATABASE_URL },
  plugins: [
    scim({
      bearerToken: process.env.SCIM_TOKEN,
    }),
  ],
});

Configure your identity provider

Point your IdP's SCIM provisioning settings at:

Base URL:  https://your-app.com/api/kavach/scim/v2
Auth:      Bearer token
Token:     <your SCIM_TOKEN>

The token must match SCIM_TOKEN exactly. Use a long random secret (32+ bytes).

User endpoints

The plugin exposes standard SCIM 2.0 user CRUD endpoints. Your IdP calls these automatically.

MethodPathDescription
GET/scim/v2/UsersList users (with optional filter)
GET/scim/v2/Users/:idGet a single user
POST/scim/v2/UsersProvision a new user
PUT/scim/v2/Users/:idReplace a user's attributes
PATCH/scim/v2/Users/:idUpdate specific attributes
DELETE/scim/v2/Users/:idDeprovision a user

Group endpoints

Groups are mapped to KavachOS organizations.

MethodPathDescription
GET/scim/v2/GroupsList groups
GET/scim/v2/Groups/:idGet a single group
POST/scim/v2/GroupsCreate a group / org
PUT/scim/v2/Groups/:idReplace group attributes
PATCH/scim/v2/Groups/:idUpdate group membership
DELETE/scim/v2/Groups/:idRemove a group

Filtering

All list endpoints support SCIM filter expressions. The most common one is userName:

GET /scim/v2/Users?filter=userName eq "john@example.com"

Supported filter operators: eq, ne, co (contains), sw (starts with).

Discovery endpoints

SCIM clients use these to learn what your server supports:

PathDescription
/scim/v2/ServiceProviderConfigSupported features and auth schemes
/scim/v2/SchemasUser and Group schema definitions
/scim/v2/ResourceTypesRegistered resource type metadata

Rotate SCIM_TOKEN immediately if it is exposed. All SCIM endpoints reject requests without a valid Authorization: Bearer <token> header.

On this page