Aller au contenu

Migrate from Auth0 to Firebase

Ce contenu n’est pas encore disponible dans votre langue.

This guide covers moving users from Auth0 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 Auth0 and the import guide for Firebase cover each side in full, including a rehearsal with synthetic users.

Auth0 to Firebase
PasswordsNot in the export. With a hash file from Auth0 support merged in (bcrypt in the guide’s example), users keep their password; otherwise they reset it.
Second factorsNot exported: users enroll again on Firebase.
User IDsThe Auth0 user_id becomes the Firebase uid, up to 128 characters.

The Auth0 export leaves behind:

  • Password hashes (Auth0 never returns them through its API)
  • MFA enrollments
  • Linked identities: a social or enterprise user keeps its user_id, email and profile, but the link to the identity provider isn’t carried over
  • Roles, permissions, organizations and memberships
  • Timestamps
  • iamigrate installed (see Installation).
  • A paid Auth0 plan (Auth0 doesn’t offer user export jobs on the Free plan).
  • A Machine-to-Machine application authorized for the Management API, with the read:users scope. If waiting for the export job fails with a 403, also grant create:users, which Auth0 requires to read a job’s status.
  • 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 AUTH0_DOMAIN=your-tenant.us.auth0.com
export AUTH0_CLIENT_ID=... # the Machine-to-Machine application's Client ID
export AUTH0_CLIENT_SECRET=... # and its Client Secret
iamigrate export --source auth0 --out ./export/

Every user of the tenant is exported, whatever the connection: database, social, passwordless and enterprise users. Pass --connection-id to export one connection, and --limit to try the export on a sample first.

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.

By default, users arrive in Firebase without a password, because Auth0 never returns hashes through its API. They need to set a new one. Send them a password reset email, for example with the Admin SDK’s generatePasswordResetLink.

Social and enterprise users never had an Auth0 password. The prefix of their source_id (google-oauth2|…, windowslive|…) tells them apart from database users, whose IDs start with auth0|, so you only need to reach the latter.

To keep passwords, ask Auth0 support for a password hash export and merge the hashes into the CMF file, as the Auth0 export guide describes. That needs a paid plan and Auth0’s approval, so ask early. The export guide’s example is a bcrypt hash, which Firebase accepts. Check the algorithm in your own file: validate names every one Firebase can’t take.

  • An email or a phone number is required. Firebase can’t create a user with neither, and reports TRANSLATION_ERROR. Auth0 users who sign in with a phone number or a username only (passwordless SMS users, for example) have no email.
  • 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. app_metadata and user_metadata are exported whole. 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.
  • Names and picture. profile.name (else given_name and family_name) becomes displayName, and profile.picture becomes photoURL.

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.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 small fixture, 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.cmf.jsonl.gz | head -n 100 | gzip > export/canary.cmf.jsonl.gz
gunzip -c export/users.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.cmf.jsonl.gz --mapping ./export/mapping.yaml

If you merged in a hash file from Auth0 support, a user showing up doesn’t prove its hash was translated correctly. Before the export, create a few test users in Auth0 with passwords you know, 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. Users you didn’t get a hash for have no password to prove: check that a test user can set a new one on Firebase and sign in.

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 Auth0, re-export, and import the final file.
  • Reconnect what the export doesn’t carry: the social and enterprise identity providers users were linked to, and roles and organizations. Then point every application at Firebase.
  • Tell users what to expect. Their passwords keep working if you merged in Auth0’s hashes. Otherwise they 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.