Skip to content
Directory & LifecycleMarkdown

Bring users from another system

Move your users and groups from the system you use today into the realm, passwords included, and switch over without anyone resetting anything.

Available, with limitsAPI

You’re moving from another directory to the realm, and you want the switch to be invisible: the same sign-in names, the same groups, the same passwords. In this guide you load users inactive from your export, link their groups, check the load, and turn everyone on at once on the day you switch.

Before you start: you hold RealmOwner in the realm. You have an export of your users (sign-in name, profile, groups and, ideally, bcrypt password hashes), and a script that can send requests with a realm administrator’s session in $CVYUH_SESSION (see Call the API). If you keep attributes the shipped user doesn’t have, add them first: see Add your own attribute to users.

  1. For each user in the export, create them inactive, with their old password hash:

    Terminal window
    curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/user?id=ben" \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "uid": "ben", "firstName": "Ben", "lastName": "Okafor", "email": "ben@example.com",
    "passwordHash": "$2b$12$Ez6…", "status": "inactive" }'

    A hash starting $2a$, $2b$ or $2y$ is stored as it is, so the password still works. Leave out passwordHash for a user whose old hash is in another scheme. They can’t set one themselves (there’s no self-service password reset yet), so before the switch, set a first password for each and give it to them.

    Each answers 201. Write down the ones refused, with the reasons the realm gives (400 lists every failed rule).

  2. Create each group:

    Terminal window
    curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/group?id=finance" \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "displayName": "Finance" }'
  3. Link each member:

    Terminal window
    curl https://foobar.cvyuh.com/api/v0/am/objects/v1/group/finance/relationships/member \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -H "If-Match: *" \
    -d '{ "targetId": "ben" }'
  4. Fix the refused users in your export and run the load again. Users already created are refused as existing (409), not changed, so a second run only adds the missing users. Links are different: linking a user who’s already a member makes a second link, so on a second run link only the members a group’s list doesn’t have yet.

Count what arrived, and compare it with your export:

Terminal window
curl -G https://foobar.cvyuh.com/api/v0/am/objects/v1/user \
-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
--data-urlencode 'pageSize=1' \
--data-urlencode 'filter={"filter":{"field":"status","op":"=","value":"inactive"}}'

totalCount is the number of users loaded. For a group, list its members on /objects/v1/group/finance/relationships/member.

On the day, set each loaded user active:

Terminal window
curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/user/ben \
-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
-H "Content-Type: application/json" \
-d '{ "status": "active" }'

They sign in with the sign-in name and password they had.

Until the switch, the loaded users can’t sign in, so nothing is lost by starting again: delete them with DELETE on /objects/v1/user/{id}, and the groups the same way.