SCIM directory sync
How your customer’s directory pushes users and groups into the realm of an account, and the routes it uses.
RealmSSO accepts SCIM 2.0 pushes of users and groups from your customer's directory. Group sync and delete-time deprovisioning are off by default. Live now.
What SCIM does here
A SCIM push writes a directory row for each user and each group. A directory row lives in the RealmSSO database. With auto-provision on, a user push also creates or updates the user in the realm of the account. A realm is the separate sign-in space of one account. RealmSSO can refuse a push for an existing user: see SCIM and SSO together.
SCIM belongs to the account. One bearer token identifies one account, and no route path holds an account id. Your customer's directory calls RealmSSO. RealmSSO does not call the directory.
The token
Your customer chooses the SCIM bearer token. It must have at least 32 characters. RealmSSO stores only the SHA-256 hash of the token. An account has one token. A new token replaces the old one at once. There is no overlap.
The IT admin turns SCIM on and sets the token in the Admin Portal. A save can also pair SCIM with a connection. See SCIM and SSO together. The portal can generate a token in the browser.
The switches
Live now · API only. Four settings decide what a push does. The pairing of SCIM with a connection also decides what a push for an existing user does. See SCIM and SSO together.
| Switch | API field | Default | Effect |
|---|---|---|---|
| Auto-provision | autoProvision | On | A user push creates or updates the user in the realm, unless RealmSSO refuses the push. |
| Auto-deprovision | autoDeprovision | Off | DELETE /Users/:id disables the user in the realm. |
| Group sync | groupSync | Off | A group push creates, renames and deletes the group in the realm, and syncs its members. |
| Attribute mapping | attributeMapping | Empty | Stores the SCIM attributes that the mapping names in the directory row of the user, and nowhere else. It does not add them to the user in the realm. See Attribute mapping below. |
Only PUT /api/v1/admin-portal/connections/:id/scim sets auto-deprovision, group sync and attribute mapping. The route needs an Admin Portal session, which starts from an invite link. The :id in the path is ignored, because SCIM settings belong to the account. The same route also takes enabled, endpoint, bearerToken, autoProvision and pairedConnectionId. See SCIM and SSO together.
Attribute mapping
An attribute mapping has one entry for each value that RealmSSO keeps. In attributeMapping, each key is a target name and each value is a SCIM attribute. A SCIM attribute is one of these:
- A core attribute, such as
title. - A sub-attribute of a single-valued attribute, such as
name.givenName. - An extension attribute with its schema URN, such as
urn:ietf:params:scim:schemas:extension:enterprise:2.0:User:department.
A POST, PUT or PATCH that carries the SCIM attribute stores its value under the target name. RealmSSO does this with auto-provision on or off. The value stays in the directory row of the user. RealmSSO does not add it to the user in the realm.
RealmSSO checks a mapping when the IT admin saves it with PUT /api/v1/admin-portal/connections/:id/scim. RealmSSO refuses a mapping that breaks a rule in the table. It answers 400 with the code VALIDATION_ERROR. It saves nothing from the request. The message field holds the sentence in the table.
| Rule | Message |
|---|---|
| The mapping has more than 100 entries. | An attribute mapping can have at most 100 entries. Remove the ones you do not need. |
| The mapping has a target that RealmSSO manages. The check ignores case, spaces and invisible characters. | An attribute mapping cannot target an attribute RealmSSO manages: username, email, firstName, lastName, enabled, emailVerified, any realmsso_ attribute, or the agent and offline-access attributes. Choose another target name. |
| The mapping reads the SCIM password, or a part of it. The check ignores case and the schema URN. | An attribute mapping cannot read the password: RealmSSO does not store passwords. Choose another SCIM attribute. |
A mapping that the IT admin saved before these rules keeps working. RealmSSO skips an entry with a target that it manages. It also skips an entry that reads the password. It applies the other entries.
Provisioning and deprovisioning
| Request | Directory row | User in the realm, with auto-provision on (default) |
|---|---|---|
POST /Users | Written, unless RealmSSO refuses the push. | Created, or adopted when a user with that userName or email exists. The user has no password. RealmSSO marks the email as verified. A push can be refused: see SCIM and SSO together. |
PUT or PATCH with active: false | Marked inactive. | Disabled. RealmSSO then asks the sign-in service to end the sessions of the user. |
PUT or PATCH that changes userName | Updated. | Renamed. The user keeps its id. See Renames. |
DELETE /Users/:id | Removed. | Disabled, and the sessions are ended, only when auto-deprovision is on. The default is off. Otherwise the user stays as it is. |
With auto-provision off, POST, PUT and PATCH write the directory row only. They change nothing in the realm. A deactivation with active: false follows auto-provision, not auto-deprovision. So a deactivation works in a default account.
RealmSSO disables the user first. Then it asks the sign-in service to end the sessions. If that second step fails, the user stays disabled and RealmSSO writes a warning to its log. A replace with no path and { "active": false } as its value also deactivates the user.
Renames
Live now · API only. A rename is a change of the userName of a user. A PATCH or a PUT can make one, and can change the email in the same request. With auto-provision on, which is the default, the user in the realm gets the new userName and email. The user keeps the same user id. With auto-provision off, a rename changes the directory row only.
A PUT renames the user first and then writes the other fields. If a later write fails, the realm keeps the new username and the directory row keeps the old userName. After you fix the cause, send the PUT again.
| Case | RealmSSO answers, with auto-provision on |
|---|---|
| A rename that works. | 200, with the new userName. |
A PATCH that renames a user and sets active to false. | 200. RealmSSO renames the user, disables it, and then asks the sign-in service to end the sessions of the user. |
| A new userName that another user has as a userName, in any letter case, or as an email. | 409 with scimType uniqueness. The directory row keeps its old userName. |
| A new userName or email that the realm refuses. | 400 with scimType invalidValue. The directory row keeps its old userName. |
What your application should key on
A rename does not change the id of the user in the realm. The sub claim of an OIDC token holds that id, so key your records on sub. The preferred_username claim holds the username. The email claim holds the email. After a rename or an email change, the next token carries the new values. An application that keys on a changed value sees a new user.
A SAML product grant sends the product a NameID. The persistent NameID, which is the default, does not change at a rename or an email change. The email NameID is the email of the user, so it changes when the email changes. See the Products API.
Who can change a username or email
Live now · Automatic. RealmSSO locks the username and the email of every user in the realm of an account. With the lock on, a user cannot change either one. A SCIM push can change both, with auto-provision on.
| Where | What happens |
|---|---|
| The account page of the realm | The page does not save a changed username or email. A user can still change their own first and last name there. A later SCIM push can replace the names. |
| The sign-in page that asks a user for a missing first or last name | The user can fill in the names only. The page has no username or email field, or shows them as read-only. If a changed value is sent anyway, the page refuses it. A page that shows the field then says “This field is read only.” |
| The first sign-in of a user whose identity provider sends no email | With an OIDC connection, the user signs in with no email. The page does not ask the user for one. |
| A change made only at the identity provider | With an OIDC connection, the username and email of the user in the realm do not change. |
| A SCIM push | Changes both, with auto-provision on. See Renames. |
| The dashboard, the Admin Portal and the API | No screen and no route changes the username or the email of a user, apart from the SCIM routes. |
SCIM and SSO together
Only a first sign-in through the connection that SCIM is paired with links a person to the user SCIM created. The person then keeps one user. The table assumes that auto-provision is on. It also assumes a match. The directory and the identity provider send the same email or userName. In the second column, SCIM does not yet manage that person's user.
| SCIM is paired with | A push for a person who already signed in through SSO | The first SSO sign-in of a person that SCIM created |
|---|---|---|
| No connection. | RealmSSO refuses the push with 409. | No link. The person sees “Account already exists”. |
| The connection that the person signs in through. | RealmSSO adopts the user that the person has. | The sign-in links to the user that SCIM created. |
| Another connection of the account. | RealmSSO refuses the push with 409. | No link. The person sees “Account already exists”. |
At the first sign-in through the paired connection, RealmSSO looks for a user in the realm. It matches the email or the userName that the identity provider sends. It links the person to a user that SCIM marked for that connection. RealmSSO denies a person that matches a user without that mark.
With a pairing, SCIM marks each user that it creates or adopts. A save that pairs SCIM also marks the users that SCIM already manages. It skips a user that the adoption rules below refuse.
If no user matches, RealmSSO creates a user for the person. SCIM does not manage that user. If SCIM also created a user for the person, the person has two users. A deactivation from SCIM acts only on the user that SCIM manages. Linking works only while SCIM is on.
Pairing
The SCIM settings of an account pair with one connection. Only a save of the SCIM settings makes the pairing. Adding or editing a connection pairs nothing, and neither does a restart. A provisioned connection has an identity provider in the sign-in service. A connection without one does not count. A save that sends no pairedConnectionId gives these results:
| State of SCIM | Result |
|---|---|
| Paired. | The pairing stays. |
| Never paired, and the account has one provisioned connection. | RealmSSO pairs SCIM with that connection. |
| Never paired, and the account has no provisioned connection. | SCIM stays unpaired. |
| Never paired, the account has two or more provisioned connections, and the save leaves SCIM on. | RealmSSO refuses the save with 400. It saves nothing. |
| Never paired, the account has two or more provisioned connections, and the save leaves SCIM off. | RealmSSO saves the settings. SCIM stays unpaired. |
| Paired before, and the paired connection was deleted. | SCIM stays unpaired. |
A save that sends pairedConnectionId pairs SCIM with that connection. The connection must belong to the account, or RealmSSO refuses the save with 400. On an existing SCIM configuration, a save that sends only pairedConnectionId changes nothing else. A SCIM configuration that an IT admin saved before pairing existed has no pairing. SCIM links nobody until a save pairs it. The route and GET /api/v1/admin-portal/scim return pairedConnectionId, which is null when SCIM is unpaired.
The save in the Admin Portal
The IT admin makes the pairing with Save on the SCIM page of the Admin Portal. The portal enables Save only after a change on the page. The change can be a switch or a new token. A new token replaces the old token at once. The portal does not send pairedConnectionId. To pair SCIM with a specific connection, send pairedConnectionId through the route.
If RealmSSO saves the settings but cannot apply the linking, the route answers 502 with the code SIGN_IN_LINKING_FAILED. Save again to retry the linking.
With two or more provisioned connections, and SCIM never paired, RealmSSO refuses any save that leaves SCIM on, a new token included, and it saves nothing from the request. The route answers 400 with the code VALIDATION_ERROR and this message: This account has more than one connection. Choose the one your directory's people sign in through: send pairedConnectionId. After the paired connection is deleted, send pairedConnectionId through the route to pair SCIM again.
A push that meets an existing user
With auto-provision on, a POST or a PUT looks for an existing user in the realm before it creates one. A PATCH does the same when its directory row has no user in the realm yet. An example is a row that RealmSSO wrote while auto-provision was off. RealmSSO matches the userName first, then the email, and it ignores case.
If RealmSSO finds a user that it may adopt, it adopts that user and creates no duplicate. To adopt, RealmSSO sets the userName, the email, the names and the enabled state of the user from the directory. A name or an email that the directory leaves out stays as it is. With a pairing, RealmSSO also marks the user for the paired connection.
RealmSSO adopts a user only if all of these are true:
- The user has no sign-in through a connection other than the paired one. With no pairing, every connection is another one.
- If RealmSSO found the user by email, the paired connection already linked that user.
- No other directory row of the account manages the user.
A refusal answers 409 in the SCIM error format, with scimType uniqueness. The detail field holds this text: The userName or email belongs to a sign-in this directory does not manage. A refused push records an event with the status error and writes no directory row. The adoption rules never block a push for the user that the same directory row already manages. So people that SCIM manages keep syncing.
Groups
A group push always writes a directory row. With group sync off, that is all. With group sync on, RealmSSO also creates, renames and deletes the group in the realm and syncs its members. Group sync is off by default and works when you switch it on.
Events
A SCIM write records an event, on success and on error. A write refused before it starts records none. That covers a bad token, a write refused with 403, an unknown id and a body that fails validation. A push that RealmSSO refuses with 409 has started, so it records an event.
The event types are scim.provisioned, scim.updated, scim.deprovisioned, scim.group_provisioned, scim.group_updated and scim.group_deprovisioned. A read records no event. RealmSSO keeps events for 90 days by default. Read them with GET /api/v1/observability/events and the eventType filter.
Base URL and format
The SCIM base is /api/scim/v2 on the API origin. Your customer registers the full URL in their IdP. RealmSSO reads a request body sent as application/scim+json or application/json. Responses come back as application/json.
API=https://api.realmsso.com
curl -G -H "Authorization: Bearer <scim-token>" \
--data-urlencode 'filter=userName eq "ada@customer.example"' \
"$API/api/scim/v2/Users"Give your customer the URL on the API origin.
SCIM serves /Users, /Groups, /ServiceProviderConfig and /Schemas. A path that SCIM does not serve gets the web server's own 404, not a SCIM error. A resource id is the id of the RealmSSO directory row. A route that takes an :id also accepts the externalId.
Authentication
Every /Users and /Groups request must carry Authorization: Bearer <token>. The two discovery routes need no credential, because a connector reads them before it has a token. RealmSSO hashes the token and looks for an enabled SCIM configuration with that hash. A missing header, or a hash with no match, gets 401 in the SCIM error format.
Users
/api/scim/v2/UsersReturns a ListResponse with totalResults, startIndex, itemsPerPage and Resources. The query parameters are filter, startIndex and count. The default count is 100. RealmSSO caps count at 200.
Only this route filters. It reads two forms: userName eq "<value>" and email eq "<value>". It ignores any other filter and returns every user. GET /Groups ignores filter.
/api/scim/v2/UsersThe body holds userName (required), name, emails, active (default true), externalId and groups. The response is 201. A second POST with the same userName updates the same user and also answers 201. A POST can also answer 409. See SCIM and SSO together.
/api/scim/v2/Users/:id/api/scim/v2/Users/:idReplaces the user. A PUT can also answer 409. See SCIM and SSO together. A PUT that changes the userName renames the user: see Renames.
/api/scim/v2/Users/:idTakes Operations, a list of { op, path, value }. The op is add, remove or replace, in any letter case. RealmSSO acts on the paths userName, name, name.givenName, name.familyName, externalId and active. It also acts on one email, through email, emails, emails[type eq "work"].value or emails[primary eq true].value. It accepts an email of another type, other core User attributes such as title or phoneNumbers, and extension attributes. It stores those only when an attribute mapping reads them, and only in the directory row.
Any other path that no attribute mapping reads answers 400 with scimType invalidPath. One refused operation refuses the whole request, and RealmSSO writes nothing. An operation with no path applies its value key by key, by the same rules. A remove with no path answers 400 with scimType noTarget.
A PATCH can answer 409 when its directory row has no user in the realm yet. A PATCH that changes the userName renames the user: see Renames.
/api/scim/v2/Users/:idRemoves the directory row and answers 204. See the provisioning table above.
Groups
/api/scim/v2/GroupsReturns a ListResponse with the members of each group.
/api/scim/v2/GroupsThe body holds displayName (required), members and externalId. The response is 201.
/api/scim/v2/Groups/:id/api/scim/v2/Groups/:idReplaces the name and the members of the group.
/api/scim/v2/Groups/:idRenames the group with displayName and sets externalId. Adds and removes members with path: "members". A remove can also name one member with the path members[value eq "<id>"]. The op is accepted in any letter case, and an operation with no path applies its value key by key. Any other path answers 400 with scimType invalidPath, except id in an add or a replace. There, the group's own id changes nothing, and another value answers 400 with scimType invalidValue.
/api/scim/v2/Groups/:idRemoves the directory row and answers 204.
Discovery
/api/scim/v2/ServiceProviderConfigNeeds no credential. It reports that patch and filter are supported, with maxResults 200. It reports that bulk, changePassword, sort and etag are not supported. The only authentication scheme is an OAuth bearer token. The response is a ListResponse with one resource.
/api/scim/v2/SchemasNeeds no credential. Returns the User and Group schema definitions.
Errors
SCIM answers 400, 401, 403, 404, 409, 413, 415, 429, 500 and 503 in the SCIM error format. A body that fails validation answers 400 with scimType invalidSyntax. If a list has too many entries, the scimType is invalidValue instead. A userName or an email that the realm refuses also answers 400 with scimType invalidValue. See the API overview.
{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:Error"],
"status": "404",
"detail": "User <id> not found"
}| Status | detail | When |
|---|---|---|
| 400 | The directory refused a value in this request. Check userName, emails and name. | The realm refuses a userName or an email in a POST, PUT or PATCH, with auto-provision on. An example is a userName with spaces around it in a POST. See Who can change a username or email. |
| 401 | Missing or invalid Authorization header, or Invalid SCIM token | No bearer token, or no enabled SCIM configuration matches it. |
| 404 | User <id> not found, or Group <id> not found | No directory row for the id in this account. |
| 409 | The userName or email belongs to a sign-in this directory does not manage. | A push meets a user that RealmSSO may not adopt. See SCIM and SSO together. |
| 409 | The userName, email or group name is already in use in this directory. | A userName, email or group name is already taken, in the directory or in the realm. A rename gets it too: see Renames. |
Related pages