Skip to main content

Provision users from an identity provider

Let Okta, Entra ID or another provider create, change and remove users and groups in your organization with SCIM.

RecipeReadyView source
Works with
Plain HTTP
Standards
SCIM 2.0

What it shows​

  1. You switch SCIM provisioning on and give the identity provider an address and a token.
  2. The provider creates a person and a group. It searches first, so a second sync creates nothing new.
  3. A SCIM group is a role of your organization. The members of the group hold the role.
  4. The person leaves the company, and the provider sets active to false. LumoAuth blocks sign-in and ends the sessions and tokens of the person.
  5. The person comes back, and the provider sets active to true again.

The script plays the identity provider with curl. It sends the same requests as Okta or Microsoft Entra ID, so you can test the address and the token before you connect the real provider.

Before you start​

  • curl and jq.
  • The provisioning token. Create it in the portal, or run the setup script below.
    1. Open Settings, Integrations, then the tab SCIM provisioning.
    2. On the card Inbound SCIM, click Set up.
    3. Under Bearer token, click Generate bearer token. Copy the token: it is shown once.
    4. Under Provisioning, switch Enable SCIM provisioning on and click Save changes.
  • The setup script does the same through the Admin API. Its API key needs the scope admin:settings:write. Check that your plan includes the Admin API in the plans matrix.
VariableValue
LUMOAUTH_URLThe address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region.
LUMOAUTH_ORG_IDYour organization, for example acme-corp.
LUMOAUTH_API_KEYFor the setup script only: an API key with the scope admin:settings:write.
SCIM_TOKENThe provisioning token of the organization. The setup script prints it, or you generate it in the portal.
USER_NAMEOptional. The userName of the test person. The default is maya.chen@northwind.example.com.
GROUP_NAMEOptional. The name of the test group. The default is Support.

The setup script switches SCIM provisioning on and sets a new provisioning token. Run it only if you did not generate the token in the portal: each run replaces the token.

node b2b/scim-from-an-identity-provider/setup.mjs
setup.mjs
// Switches SCIM provisioning on and sets a new provisioning token. The token
// is what you give to the identity provider. Run it again to replace the token.
//
// node b2b/scim-from-an-identity-provider/setup.mjs
//
// The API key needs the scope admin:settings:write.
import { randomBytes } from 'node:crypto';
import { api, call, printEnv } from '../../_lib/admin.mjs';

// LumoAuth stores only a hash of the token, so this is the one time to read it.
const token = randomBytes(32).toString('base64url');
await call('PATCH', '/admin/settings/scim', { inbound: { enabled: true, bearer_token: token } });

console.log('SCIM provisioning is on. Give the identity provider this address and the token:');
console.log(` ${api}/scim2.0`);
printEnv({ SCIM_TOKEN: token });

The address for the identity provider is https://app.lumoauth.dev/orgs/<your organization>/api/v1/scim2.0. The Endpoint card of the Inbound SCIM page shows it with a Copy button.

Code​

Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization.

b2b/scim-from-an-identity-provider/http/provision.sh
#!/bin/sh
# Play the identity provider: create a user and a group through SCIM, then
# deactivate the user, with curl and jq.
#
# sh b2b/scim-from-an-identity-provider/http/provision.sh
set -eu

SCIM="$LUMOAUTH_URL/orgs/$LUMOAUTH_ORG_ID/api/v1/scim2.0"
USER_NAME="${USER_NAME:-maya.chen@northwind.example.com}"
GROUP_NAME="${GROUP_NAME:-Support}"

scim() {
curl --silent --show-error --globoff --request "$1" "$SCIM$2" \
--header "Authorization: Bearer $SCIM_TOKEN" \
--header "Content-Type: application/scim+json" \
--header "Accept: application/scim+json" \
${3:+--data "$3"}
}

# The discovery documents need no token. An identity provider reads them first.
curl --silent --show-error "$SCIM/ServiceProviderConfig" \
| jq -r '"discovery: patch \(.patch.supported), filter \(.filter.supported), bulk up to \(.bulk.maxOperations) operations"'

# An identity provider searches before it creates, so a second run finds the
# user of the first run. %20 is a space and %22 is a quotation mark.
USER_ID=$(scim GET "/Users?filter=userName%20eq%20%22$USER_NAME%22" | jq -r '.Resources[0].id // empty')
if [ -z "$USER_ID" ]; then
USER_ID=$(scim POST /Users "{
\"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],
\"userName\": \"$USER_NAME\",
\"externalId\": \"00u-maya\",
\"name\": {\"givenName\": \"Maya\", \"familyName\": \"Chen\"},
\"displayName\": \"Maya Chen\",
\"emails\": [{\"value\": \"$USER_NAME\", \"primary\": true}],
\"active\": true
}" | jq -r .id)
fi
echo "user: $USER_NAME ($USER_ID)"

# A SCIM group is a role of the organization. A member of the group holds the role.
GROUP_ID=$(scim GET "/Groups?filter=displayName%20eq%20%22$GROUP_NAME%22" | jq -r '.Resources[0].id // empty')
if [ -z "$GROUP_ID" ]; then
GROUP_ID=$(scim POST /Groups "{
\"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:Group\"],
\"displayName\": \"$GROUP_NAME\"
}" | jq -r .id)
fi
scim PATCH "/Groups/$GROUP_ID" "{
\"schemas\": [\"urn:ietf:params:scim:api:messages:2.0:PatchOp\"],
\"Operations\": [{\"op\": \"add\", \"path\": \"members\", \"value\": [{\"value\": \"$USER_ID\"}]}]
}" > /dev/null
scim GET "/Groups/$GROUP_ID" | jq -r '"group: \(.displayName) (\(.id)), members: \([.members[]?.display] | join(", "))"'
scim GET "/Users/$USER_ID" | jq -r '"roles of \(.userName): \([.roles[]?.value] | join(", "))"'

# The person leaves the company. The identity provider sets `active` to false:
# LumoAuth blocks sign-in and ends the sessions and tokens of the person.
active() {
scim PATCH "/Users/$USER_ID" "{
\"schemas\": [\"urn:ietf:params:scim:api:messages:2.0:PatchOp\"],
\"Operations\": [{\"op\": \"replace\", \"path\": \"active\", \"value\": $1}]
}" | jq -r '"\(.userName): active \(.active)"'
}
active false

# The person comes back. SCIM lifts the block, because SCIM set it.
active true
sh b2b/scim-from-an-identity-provider/http/provision.sh

Check the result​

Output
discovery: patch true, filter true, bulk up to 100 operations
user: maya.chen@northwind.example.com (01a21fda-9c94-77ad-a007-0147c8193f9d)
group: Support (92), members: Maya Chen
roles of maya.chen@northwind.example.com: support
maya.chen@northwind.example.com: active false
maya.chen@northwind.example.com: active true
  • Run the script again: the lines are the same. The search finds the person and the group of the first run.
  • A person who was signed in before the run is signed out. An access token of that session gets 401 from the UserInfo endpoint, and its refresh token gets invalid_grant. The hosted pages ask for a new sign-in.
  • To try that, the test person needs a way to sign in. The provider can send a password in the password attribute, or the person signs in with single sign-on.
  • The Audit logs page lists each write as a scim.* event, for example scim.user.patch, with the actor type scim.

To connect Okta or Microsoft Entra ID, paste the address and the token into the provisioning settings of the provider. The SCIM guide has the steps for each one.

Limits​

  • A group can never give a role that makes its members administrators. Such a request gets 403. Give administrator roles in the portal.
  • roles is read-only on a user. A role comes only from the members of a group.
  • A block that an administrator set in LumoAuth stays. active: true from the provider lifts only a block that SCIM set.
  • What DELETE /Users/{id} does depends on the Deprovisioning action of the Inbound SCIM page. The default is a soft delete, which an administrator can undo.
  • Attributes that are not in the user schema, such as title or department, are not stored.
  • /Bulk takes up to 100 operations in one request, and an organization can send 10 such requests in an hour.