Skip to content

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.

  • An API with authtempo, the magic link, and the password reset. Do a getting started tutorial first.
  • curl and jq in 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/cli in the app’s workspace. authtempo import is a command of it.
  1. Save the script below as workos-export.sh in a folder that only you can read.
  2. Run it with bash workos-export.sh. Do not paste it into a shell: set -e closes that shell at the first error.
  3. The script stops at the first failed call. curl prints the HTTP error, such as 401 for a wrong key.
  4. A failed run writes no new file and keeps the old files. Run the script again.
  5. A complete run writes users.json, identities.json, memberships.json, and organizations.json.
workos-export.sh
set -euo pipefail
umask 077
api=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"' EXIT
page() { 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" users
list "/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"
done
jq -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" .
Terminal window
bash workos-export.sh

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 import
// 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: {},
});
}
  1. Run the import as a dry run, and read the report.
  2. Read each skipped record and each dropped item. A WorkOS export has no hash, so the hashes: line counts none only.

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 ….

Terminal window
authtempo import workos --users users.json --identities identities.json --memberships memberships.json --organizations organizations.json --target postgres --url-env DATABASE_URL --dry-run

Run 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.

  1. Make the copy. On Postgres, create an empty database, set COPY_URL to its URL, and load the real one into it with pg_dump --no-owner "$DATABASE_URL" | psql "$COPY_URL".
  2. On D1, load the real database into the empty local copy of the import Worker with wrangler d1 export <database> --remote --output copy.sql and wrangler d1 execute <database> --local --file copy.sql.
  3. Run both in the folder of the import Worker. Delete its .wrangler/state first, or the load stops on a table that exists.
  4. 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.
Terminal window
authtempo import workos --users users.json --identities identities.json --memberships memberships.json --organizations organizations.json --target postgres --url-env COPY_URL
  1. Run authtempo import verify with the same files on the copy. It exits 0 only when the copy holds the whole export.
  2. Run authtempo check <base url> against the API.
  3. 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.
  4. Drop the copy, and on D1 delete copy.sql, when import verify exits 0. The copy holds every user of the export.
  5. Delete the four files after the cutover.
Terminal window
authtempo import verify workos --users users.json --identities identities.json --memberships memberships.json --organizations organizations.json --target postgres --url-env COPY_URL
authtempo check https://api.example.com

The test below imports the fixture export, signs a user in by a magic link, and sets a password by a reset.

The test of this guide
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);
});
});
  1. Change each auth call of the app with the table of The calls.
  1. Do the steps of The cutover.
  2. Delete WORKOS_API_KEY from the shell, and revoke the key in the WorkOS dashboard after the cutover.

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
  • WorkOS exports no password hash. No password moves.
  • id is the source id. email, email_verified, name, profile_picture_url, and created_at move. Without name, first_name and last_name join with one space.
  • A user imports verified only when email_verified is the JSON value true.
  • An OAuth identity maps GoogleOAuth to Google, AppleOAuth to Apple, and GitHubOAuth to GitHub, with idp_id as the subject.
  • LinkedInOAuth is listed as identity:linkedin_legacy. Every other provider and every other type is dropped and listed.
  • Only an active membership imports. The role admin becomes admin, member becomes 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, and pending memberships. Each inactive or pending membership is listed on its user as member:<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.
  • 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 data array.
  • The command exits 1: read the report for no_owner, duplicate_row, or no_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.