Migrating Users With Password Hashes and MFA Secrets Into an Auth0 Database Connection
Last Updated:
Overview
A full migration requires combining a standard user export from the source Auth0 tenant with the Pretty Good Privacy (PGP) encrypted password hash and multi-factor authentication (MFA) secret files provided by Auth0 Support. Administrators migrate users to an Auth0 database connection with their existing password hashes and time-based one-time password (TOTP) MFA secrets by requesting PGP-encrypted exports through an Auth0 support case, decrypting them, merging them with the user export, and importing the result in chunks with the Management API.
Applies To
- Auth0
- Auth0 Paid Tenants
- Auth0 Database Connections
- Source Users Exported From an Auth0 Tenant
- Bulk User Import (Management API)
- Custom Password Hashes (
custom_password_hash) - MFA TOTP Secrets (
mfa_factors) - PGP-Encrypted Exports Provided by Auth0 Support
Solution
How do administrators migrate users with password hashes and MFA secrets into an Auth0 database connection?
Administrators generate a PGP key pair, request the encrypted exports through a support case, decrypt them, merge them with the user export into the bulk import schema, split the result into files under 500 KB, and import each file with the Management API.
How do administrators generate the PGP key pair and export the public key?
Generate an RSA 4096-bit key with the tenant administrator's email address, then export the public key by key ID.
- Install a PGP tool. Examples of these tools include GnuPG (gpg). These are examples only, and the administrator should use a tool that best fits their organizational guidelines for these types of tools.
- Run the key generation command and enter the required values.
- Key type: 1 (RSA and RSA). Do not accept the default ECC option, because Auth0 does not support ECC or EdDSA keys.
- Key size: 4096
- Validity: at least 7 days from today.
- Name and email: the exact email address registered to the tenant administrator account. Aliases or different capitalization can cause validation to fail.
- Passphrase: a strong, randomly generated passphrase. Store the passphrase and private key on an offline device.
- List the keys and copy the 16-character key ID shown under the pub line.
- Export the public key in ASCII-armored format.
gpg --armor --export <YOUR_KEY_ID> > public_key.asc
- Strip third-party signatures if the file is larger than 35,000 characters.
gpg --armor --export --export-options export-minimal <YOUR_KEY_ID> > public_key.asc
NOTE: Never share the private key or passphrase with anyone, including Auth0 Support.
The Exports Are Requested and Attached to a Support Case
Submit the request from the same tenant administrator account that generated the key, provide the required authorization forms, and download the encrypted file from the secure link.
- Open a support case requesting a password hash export and an MFA secrets export.
- Enter the tenant name in the case and paste the full ASCII-armored public key block from
public_key.asc, from-----BEGIN PGP PUBLIC KEY BLOCK-----to-----END PGP PUBLIC KEY BLOCK-----. - Wait for Auth0 to review eligibility. Not all requests qualify, and Auth0 does not provide estimated completion times. Note any deadlines in the case.
- Provide the following in the case if the request is approved:
- Written authorization for the export.
- Confirmation from at least one other tenant administrator. This is skipped if there is only one administrator.
- The signed Hashed Password and MFA Secret Export Acknowledgment form, signed by a CISO, CSO, or executive-level representative (VP or above). Auth0 does not accept typed names.
- Download the encrypted file from the secure link emailed to the administrator. The link works only for the administrator who opened the case, who must still hold the tenant administrator role. It expires after 3 days.
How do administrators decrypt, merge, and import the exports?
Decrypt each file on a secure local machine, prepare the basic user export, merge the files into a single payload using a script, split the array into smaller files, and submit each file to the Management API.
- Decrypt each file on a secure local machine.
gpg --output decrypted_hashes.json --decrypt <ENCRYPTED_HASHES_FILE>.pgp gpg --output decrypted_mfa.json --decrypt <ENCRYPTED_MFA_FILE>.pgp
- Prepare the basic user export from the source tenant. Auth0 user exports are in NDJSON format, so convert them to a JSON array. Examples of tools that can be used include jq. These are examples only, and the administrator should use a tool that best fits their organizational guidelines for these types of tools. To keep the same user IDs, remove the
auth0|prefix from each<user_id>. Bulk import adds the prefix automatically, so IDs would otherwise becomeauth0|auth0|<user_id>. - Write a script to merge the three files into one payload. Examples of scripting languages include Node.js or Python. These are examples only, and the administrator should use a tool that best fits their organizational guidelines for these types of tools.
- Load the decrypted password hashes and MFA secrets into dictionaries keyed by
<user_id>oremail. - Loop through the users file and look up each user in both dictionaries.
- Add the hash or secret to the user object as
custom_password_hashandmfa_factorswhere a hash or secret exists.
- Load the decrypted password hashes and MFA secrets into dictionaries keyed by
- Verify the merged file matches the following format.
NOTE: The algorithm value must exactly match the algorithm used to hash the exported passwords.[ { "email": "user@example.com", "email_verified": true, "name": "Jane Doe", "custom_password_hash": { "algorithm": "bcrypt", "hash": { "value": "$2b$10$<YOUR_EXTRACTED_BCRYPT_HASH>" } }, "mfa_factors": [ { "totp": { "secret": "<YOUR_EXTRACTED_BASE32_SECRET>" } } ] } ] - Split the final array into smaller JSON files, such as
users-chunk-1.jsonandusers-chunk-2.json. The Management API rejects bulk import files over 500 KB. - Submit each file over TLS with a POST request to
/api/v2/jobs/users-imports, usingmultipart/form-datawith these fields:users: the chunked.jsonfile.connection_id: the ID of the target database connection (for example,con_1234567890).upsert:true. This updates users that already exist in the connection instead of failing with a conflict error.curl -L 'https://<YOUR_DOMAIN>.auth0.com/api/v2/jobs/users-imports' \ -H 'Authorization: Bearer <YOUR_MGMT_API_TOKEN>' \ -F 'users=@/path/to/users-chunk-1.json' \ -F 'connection_id=con_1234567890' \ -F 'upsert=true'
- Check each job with a GET request to
/api/v2/jobs/{id}, using thejob_idreturned by the import request. Review thefailed_recordsarray and correct any formatting problems, such as invalid base32 secrets. A failed MFA import returns the error codeMFA_FACTORS_FAILEDwith the message "Unable to import factors". It is safe to retry the import for failed users with upsert enabled.
- Permanently delete all plaintext JSON files, the original PGP files, and any temporary script output from the local machine when the migration is complete.