Skip to content

Migrate from Ory Kratos to Firebase

This guide covers moving users from Ory Kratos to Firebase: what carries over and what doesn’t, how their passwords and second factors are handled, and the commands to run. It sticks to what is specific to this pair. The export guide for Ory Kratos and the import guide for Firebase cover each side in full, including a rehearsal with synthetic users.

Ory Kratos to Firebase
PasswordsPartly kept: bcrypt hashes are imported. Argon2 users must reset their password.
Second factorsNot exported: users enroll again on Firebase.
User IDsThe Kratos identity UUID becomes the Firebase uid, up to 128 characters.

The Ory Kratos export leaves behind:

  • Every trait except email, username and phone: names and custom traits, so profile is empty
  • MFA (TOTP, recovery codes and WebAuthn)
  • Social sign-in links
  • Recovery addresses and timestamps
  • iamigrate installed (see Installation).
  • A self-hosted instance whose Admin API you can reach, usually on port 4434. iamigrate calls it without credentials, so Ory Network projects aren’t supported yet.
  • Firebase. A Firebase project with Authentication enabled and the Email/Password sign-in method turned on (use a disposable project for the rehearsal), plus a service account key or an OAuth2 access token. The import guide walks through it.
Terminal window
export KRATOS_ADMIN_URL=http://127.0.0.1:4434
iamigrate export --source kratos --out ./export/

Identities with no password hash are skipped and listed in manifest.json.

The export is a snapshot: users created, and passwords changed, after it aren’t in it, so plan a freeze or a final re-export before cutover. Check export/manifest.json for skipped_records, because the command exits with status 0 even when users are skipped, and for the per-algorithm counts.

Ory Kratos stores bcrypt and Argon2, and Firebase imports only bcrypt. A user whose hash can’t be translated isn’t created at all, so deal with the Argon2 users before the import.

Hash in the exportFirebase
bcryptImported as BCRYPT hashes.
Argon2Not supported. The user isn’t created: it fails validate and the import reports TRANSLATION_ERROR.

manifest.json shows how many users hold each algorithm. If any hold Argon2, drop their password, so they are created without one:

Terminal window
gunzip -c export/users.cmf.jsonl.gz \
| jq -c 'if .password.algorithm == "argon2" then .password = null else . end' \
| gzip > export/users.ready.cmf.jsonl.gz

Those users then need to set a new password. Send them a password reset email, for example with the Admin SDK’s generatePasswordResetLink.

Read the later steps from export/users.ready.cmf.jsonl.gz.

  • An email or a phone number is required. Firebase can’t create a user with neither, and reports TRANSLATION_ERROR. An identity that signs in with a username alone has neither.
  • Usernames are dropped. Firebase has no username sign-in, so users who signed in with a username need an email or phone number to sign in at all.
  • user_metadata is dropped. Firebase stores no free-form profile data. metadata_admin becomes app_metadata and metadata_public becomes user_metadata. Move what you need into app_metadata (it becomes custom claims, limited to 1000 serialized characters and no reserved claim names), or keep it in your own database.
  • No names. Kratos exports no profile, so Firebase users get no displayName.
  • Phone numbers. The phone trait carries over as the phone number. Firebase needs it in E.164 format, which validate checks.

Set the target in the scaffolded mapping, then check the export against what the target can import. validate makes no network calls:

Terminal window
iamigrate map --target firebase --mapping ./export/mapping.yaml
iamigrate validate --in ./export/users.ready.cmf.jsonl.gz \
--mapping ./export/mapping.yaml --target firebase

Fix every reported problem at the source, or in the CMF records, and run it again until it comes back clean. Review mapping.yaml too: custom metadata keys are flagged under manual_steps for you to place, rather than guessed at.

Do a rehearsal first. Follow the Firebase import guide with a fixture that holds the same hash algorithms as your users, against a disposable target, and sign in as a few of the users (see Generate test fixtures).

For the real run, point iamigrate at Firebase:

Terminal window
export FIREBASE_PROJECT_ID=acme-rehearsal
export GOOGLE_APPLICATION_CREDENTIALS=./service-account.json

Split off a small canary, import it, and check the result before you import the rest:

Terminal window
gunzip -c export/users.ready.cmf.jsonl.gz | head -n 100 | gzip > export/canary.cmf.jsonl.gz
gunzip -c export/users.ready.cmf.jsonl.gz | tail -n +101 | gzip > export/rest.cmf.jsonl.gz
iamigrate import firebase \
--in ./export/canary.cmf.jsonl.gz \
--mapping ./export/mapping.yaml \
--report ./export/canary-report.json

Sign in as a few canary users, then import the rest:

Terminal window
iamigrate import firebase \
--in ./export/rest.cmf.jsonl.gz \
--mapping ./export/mapping.yaml \
--report ./export/rest-report.json

The command exits with status 0 even when users fail. Always read the reports: each failed user is listed under failed with a code, and the follow-up lists (requires_password_reset, requires_reenrollment and so on) say who needs to hear from you. The import guide explains each code.

Reconcile the file with the live target. It reports users missing from it and drift in the fields it can read back:

Terminal window
iamigrate diff firebase --in ./export/users.ready.cmf.jsonl.gz --mapping ./export/mapping.yaml

A user showing up doesn’t prove its password hash was translated correctly. Before the export, create a few test users in Ory Kratos with passwords you know, one for each hash algorithm in manifest.json, and sign in as each of them on Firebase after the import: the Identity Toolkit accounts:signInWithPassword endpoint with the project’s Web API key, as the Firebase import guide shows.

Firebase keeps the source_id as the user’s uid, which Firebase limits to 128 characters. If your applications reference users by the old ID, keep that mapping.

  • Freeze changes in Ory Kratos, re-export, and import the final file.
  • Reconnect what the export doesn’t carry: social sign-in links, and whatever lived in traits other than email, username and phone. Then point every application at Firebase.
  • Tell users what to expect. Users whose hash was imported keep their password. The others need a reset. Second factors aren’t exported, so users enroll them again.
  • Clean up the rehearsal. Delete the rehearsal project, or delete its users from Authentication → Users.