From WorkOS
For: an operator and a developer who move an app from WorkOS to authtempo.
What it does: you save the users, the identities, the organizations, and the members of WorkOS as four files, and import them into core’s tables. Then you change the app’s WorkOS calls to @authtempo/client.
Before you start
Section titled “Before you start”- An API with authtempo, the magic link, and the password reset. Do a getting started tutorial first.
curlandjqin the shell. authtempo import reads the files that they write.- A WorkOS secret key in the shell as
WORKOS_API_KEY. The command never reads it. @authtempo/cliin the app’s workspace. authtempo import is a command of it.
Export
Section titled “Export”- Save the script below as
workos-export.shin a folder that only you can read. - Run it with
bash workos-export.sh. Do not paste it into a shell:set -ecloses that shell at the first error. - The script stops at the first failed call.
curlprints the HTTP error, such as 401 for a wrong key. - A failed run writes no new file and keeps the old files. Run the script again.
- A complete run writes
users.json,identities.json,memberships.json, andorganizations.json.
set -euo pipefailumask 077api=https://api.workos.com# Every file goes to a temporary folder first. Only a complete run moves the four files here.t=$(mktemp -d)trap 'rm -rf "$t"' EXITpage() { curl -sSf -H "Authorization: Bearer $WORKOS_API_KEY" "$api$1"; }list() { after=""; : > "$t/$2.ndjson" while :; do p=$(page "$1${after:+&after=$after}") printf '%s\n' "$p" | jq -c '.data' >> "$t/$2.ndjson" after=$(printf '%s' "$p" | jq -r '.list_metadata.after // empty') [ -z "$after" ] && break done jq -s 'add // []' "$t/$2.ndjson" > "$t/$2.json"}# A user that WorkOS deleted after the user list answers 404: write [] and a note.identities() { code=$(curl -sS -o "$t/identity" -w '%{http_code}' -H "Authorization: Bearer $WORKOS_API_KEY" "$api/user_management/users/$1/identities") case "$code" in 200) cat "$t/identity" ;; 404) echo "note: user $1 is deleted in WorkOS; it has no identities in the export" >&2; printf '[]' ;; *) echo "error: the identities of user $1 answered HTTP $code" >&2; return 1 ;; esac}list "/user_management/users?limit=100&order=asc" userslist "/organizations?limit=100&order=asc" organizations: > "$t/memberships.ndjson"for o in $(jq -r '.[].id' "$t/organizations.json"); do list "/user_management/organization_memberships?organization_id=$o&statuses=active,inactive,pending&limit=100" "m-$o" cat "$t/m-$o.json" >> "$t/memberships.ndjson"donejq -s 'add // []' "$t/memberships.ndjson" > "$t/memberships.json"for u in $(jq -r '.[].id' "$t/users.json"); do i=$(identities "$u") printf '{"%s":%s}\n' "$u" "$i"done | jq -s 'add // {}' > "$t/identities.json"mv "$t/users.json" "$t/organizations.json" "$t/memberships.json" "$t/identities.json" .bash workos-export.shCarry the passwords
Section titled “Carry the passwords”WorkOS exports no password hash, so no password moves. Each user signs in by a magic link, or sets a new password by a reset. The API below turns on both, and the organizations feature.
// The API after the move of the guide "From WorkOS".import { createAuth, createPbkdf2PasswordHash, type MailPort, type StorageAdapter,} from "@authtempo/core";
/** * WorkOS exports no password hash (owner decision 1 of 2026-10-14). A moved * user signs in by a magic link, or sets a password by a reset. */export function createWorkosAuth(deps: { storage: StorageAdapter; mail: MailPort; secret: string;}) { return createAuth({ baseURL: "https://api.example.com", trustedOrigins: [], secret: deps.secret, storage: deps.storage, mail: deps.mail, magicLink: { // The default link, written out: it opens the confirm page of the API. linkBuilder: (token) => `https://api.example.com/auth/magic-link/verify?token=${encodeURIComponent(token)}`, }, password: { // No hash moves, so no legacy seam: every password is a new PBKDF2 hash. hash: createPbkdf2PasswordHash(), }, // The organizations and the members of the WorkOS export. organizations: {}, });}Dry run
Section titled “Dry run”- Run the import as a dry run, and read the report.
- Read each skipped record and each
droppeditem. A WorkOS export has no hash, so thehashes:line countsnoneonly.
The @authtempo packages are on npm. Add the CLI to your app with pnpm add -D @authtempo/cli, and run each command as pnpm exec authtempo ….
authtempo import workos --users users.json --identities identities.json --memberships memberships.json --organizations organizations.json --target postgres --url-env DATABASE_URL --dry-runRun the real import on a copy of the database only. The one real import into the real database runs at step 9 of The cutover, after the old sign-ins stop. If it runs earlier, a password, an address, or a delete that changes in the old system after it is lost. One real import tells why.
- Make the copy. On Postgres, create an empty database, set
COPY_URLto its URL, and load the real one into it withpg_dump --no-owner "$DATABASE_URL" | psql "$COPY_URL". - On D1, load the real database into the empty local copy of the import Worker with
wrangler d1 export <database> --remote --output copy.sqlandwrangler d1 execute <database> --local --file copy.sql. - Run both in the folder of the import Worker. Delete its
.wrangler/statefirst, or the load stops on a table that exists. - Run the same command without
--dry-run, with--url-env COPY_URL. On D1, run the import Worker without"remote": true, so it writes the local copy.
authtempo import workos --users users.json --identities identities.json --memberships memberships.json --organizations organizations.json --target postgres --url-env COPY_URLVerify
Section titled “Verify”- Run
authtempo import verifywith the same files on the copy. It exits 0 only when the copy holds the whole export. - Run
authtempo check <base url>against the API. - Sign in once with a known user by a magic link, and once by each social provider of the export. Do it at step 13 of The cutover: before that step, the real database holds no user.
- Drop the copy, and on D1 delete
copy.sql, whenimport verifyexits 0. The copy holds every user of the export. - Delete the four files after the cutover.
authtempo import verify workos --users users.json --identities identities.json --memberships memberships.json --organizations organizations.json --target postgres --url-env COPY_URLauthtempo check https://api.example.comThe test below imports the fixture export, signs a user in by a magic link, and sets a password by a reset.
import { importUsers, readSource } from "@authtempo/import";import { FIXTURE_EXPORTS } from "@authtempo/import/testing";import { describe, expect, it } from "vitest";import { call, harness, linkIn, sessionCookieOf } from "../support/harness.ts";import { createWorkosAuth } from "./workos.ts";
// The fixture export of the WorkOS reader: Wren, verified, admin of Okafor Labs, and Theo.const f = FIXTURE_EXPORTS.workos;const WREN = "wren@example.com";
describe("move users from WorkOS", () => { it("imports a WorkOS export with no password, and signs the user in by a magic link", async () => { const h = harness(); const report = await importUsers(h.storage, await readSource(f.bundle), { formats: [] }); expect({ passwords: report.created.password, organizations: report.created.organization, }).toEqual({ passwords: 0, organizations: 1 });
const auth = createWorkosAuth(h); const request = await call(auth, "POST", "/auth/magic-link/request", { email: WREN }); expect(request.status).toBe(200); const token = linkIn(h, WREN).searchParams.get("token") ?? ""; const verify = await call(auth, "POST", "/auth/magic-link/verify", { token }); expect(verify.status).toBe(200); const cookie = sessionCookieOf(verify);
const session = await call(auth, "GET", "/auth/session", undefined, { cookie }); expect(session.status).toBe(200); const { user } = (await session.json()) as { user: { email: string } }; expect(user.email).toBe(WREN); // The first admin of a WorkOS organization becomes its owner. const orgs = await call(auth, "GET", "/auth/organizations", undefined, { cookie }); const { organizations } = (await orgs.json()) as { organizations: { organization: { name: string }; role: string }[]; }; expect(organizations.map((o) => [o.organization.name, o.role])).toEqual([ ["Okafor Labs", "owner"], ]); });
it("lets an imported user set a password by a reset", async () => { const h = harness(); await importUsers(h.storage, await readSource(f.bundle), { formats: [] }); const auth = createWorkosAuth(h); const password = "a new password for wren";
const request = await call(auth, "POST", "/auth/password/reset/request", { email: WREN }); expect(request.status).toBe(200); const token = linkIn(h, WREN).searchParams.get("token") ?? ""; const reset = await call(auth, "POST", "/auth/password/reset", { token, password }); expect(reset.status).toBe(200); const signIn = await call(auth, "POST", "/auth/password/sign-in", { email: WREN, password }); expect(signIn.status).toBe(200); });});Change the calls
Section titled “Change the calls”- Change each auth call of the app with the table of The calls.
Cut over
Section titled “Cut over”- Do the steps of The cutover.
- Delete
WORKOS_API_KEYfrom the shell, and revoke the key in the WorkOS dashboard after the cutover.
The calls
Section titled “The calls”WorkOS sends the person to its AuthKit page. authtempo has no page for a web app: the app shows its own sign-in form.
| WorkOS | authtempo |
|---|---|
getSignInUrl(), getSignUpUrl() |
The app’s own form, with client.magicLink.request or client.password.signIn. |
userManagement.authenticateWithPassword({ email, password }) |
client.password.signIn({ email, password }) |
userManagement.sendMagicAuthCode({ email }) |
client.magicLink.request({ email }) |
userManagement.getAuthorizationUrl({ provider: "GoogleOAuth" }) |
Send the browser to /auth/social/google/start?next=/ on the API. |
userManagement.sendPasswordResetEmail({ email }) |
client.password.requestReset({ email }) |
userManagement.resetPassword({ token, newPassword }) |
client.password.reset({ token, password }), with the token of the reset link |
signOut() |
client.signOut() |
withAuth(), getUser() |
client.session() |
userManagement.listOrganizationMemberships({ userId }) |
client.organizations.list() |
| The check of a WorkOS access token on the server | auth.session(request), or a check of the session JWT against /auth/jwks |
How it behaves
Section titled “How it behaves”- WorkOS exports no password hash. No password moves.
idis the source id.email,email_verified,name,profile_picture_url, andcreated_atmove. Withoutname,first_nameandlast_namejoin with one space.- A user imports verified only when
email_verifiedis the JSON valuetrue. - An
OAuthidentity mapsGoogleOAuthto Google,AppleOAuthto Apple, andGitHubOAuthto GitHub, withidp_idas the subject. LinkedInOAuthis listed asidentity:linkedin_legacy. Every other provider and every other type is dropped and listed.- Only an
activemembership imports. The roleadminbecomes admin,memberbecomes member, and the first admin becomes owner. - The membership of a user with an unverified address is skipped as
user_unverified. The user imports, and the command exits 0. - An organization with no active admin gives
no_owner, and the command exits 1. - The script reads the
active,inactive, andpendingmemberships. Eachinactiveorpendingmembership is listed on its user asmember:<status>. - A WorkOS SSO user and a directory user are not read. Directory sync is a later plan.
- A user that WorkOS deletes after the user list call still imports. Its identities call answers 404, and the script writes no identity and prints a note.
- A membership of a user that the user list lacks is not read.
If it fails
Section titled “If it fails”- The command stops at start with “the WorkOS memberships input needs the organizations input”: give both files, or neither.
- The command stops at start with “input is not an array”: a file holds a page object. Run the script again, which saves the
dataarray. - The command exits 1: read the report for
no_owner,duplicate_row, orno_source_id. The exit status lists each. invalid_credentials: no password moved. The user signs in by a magic link, or sets a new password.invalid_token: a magic link or a reset link that expired or was used. Send it again.