[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-11。"],[[["\u003cp\u003eThis document guides users through the process of migrating users between different Identity Platform projects, including migrating users from a non-tenant project to a tenant, or between different tenants.\u003c/p\u003e\n"],["\u003cp\u003eBefore migrating users, you will require service account keys for both the source and target projects, ensuring they have at least the IAM Editor role to access the necessary data.\u003c/p\u003e\n"],["\u003cp\u003eUser migration involves downloading users using \u003ccode\u003eadmin.auth().listUsers\u003c/code\u003e and uploading them to the target project via \u003ccode\u003eadmin.auth().importUsers()\u003c/code\u003e, with a maximum of 1000 users handled at a time.\u003c/p\u003e\n"],["\u003cp\u003eMigrating users to or between tenants requires setting the tenant ID using \u003ccode\u003eadmin.auth().tenantManager().authForTenant()\u003c/code\u003e, and in cases of inter-tenant migration, deleting the old tenant ID from user data before importing.\u003c/p\u003e\n"],["\u003cp\u003eFor password users, you need to supply the hash configuration, which can be retrieved from the Identity Platform Users page in the Google Cloud console, to ensure secure password migration.\u003c/p\u003e\n"]]],[],null,["# Migrating users between projects and tenants\n============================================\n\nThis document explains how to migrate users from an existing Identity Platform\nproject to a different one. It also shows how to migrate users from a\nnon-tenant project to a tenant, or migrate users between tenants.\n\nBefore you begin\n----------------\n\n- [Install the Admin SDK](/identity-platform/docs/install-admin-sdk).\n\nConfiguring service account keys\n--------------------------------\n\nBefore you can migrate user accounts, you need service account keys for both\nthe source and target projects. The service accounts must be granted at least\nthe IAM Editor role (`roles/editor`) to access the users\nand their hashed passwords from the source project. See the\n[IAM documentation](/iam/docs) to learn more about creating\nservice accounts, granting permissions, and obtaining keys.\n\nAfter downloading the keys, use them to instantiate two `auth` instances. \n\n var admin = require('firebase-admin');\n\n var sourceApp = admin.initializeApp({\n credential: admin.credential.cert('source-project-service-account.json'),\n }, 'source-app');\n\n var targetApp = admin.initializeApp({\n credential: admin.credential.cert('target-project-service-account.json'),\n }, 'target-app');\n\n var authFrom = sourceApp.auth();\n var authTo = targetApp.auth();\n\nIf your access control policies don't allow the use of multiple service\naccounts in a single workload, you can still use the example code from this\ndocument, but you'll need to download all users from the source project to a\nstorage system first, then upload them to the target project in a separate\nworkload.\n\nMigrating users between projects\n--------------------------------\n\nTo migrate users, call the `admin.auth().listUsers` method, which returns a\na paginated list of users. You can then call `admin.auth().importUsers()` to\nupload them to the target project.\n\nA maximum of 1000 users can be downloaded or uploaded at a time.\n\nFor password users, you need to supply the hash config for password hashing.\nYou can retrieve the hash config by navigating to the\n[Identity Platform Users page](https://console.cloud.google.com/customer-identity/users) in the\nGoogle Cloud console, and then clicking **Import Users**.\n\nThe following example shows how to migrate users: \n\n function migrateUsers(userImportOptions, nextPageToken) {\n var pageToken;\n authFrom.listUsers(1000, nextPageToken)\n .then(function(listUsersResult) {\n var users = [];\n listUsersResult.users.forEach(function(user) {\n var modifiedUser = user.toJSON();\n // Convert to bytes.\n if (user.passwordHash) {\n modifiedUser.passwordHash = Buffer.from(user.passwordHash, 'base64');\n modifiedUser.passwordSalt = Buffer.from(user.passwordSalt, 'base64');\n }\n // Delete tenant ID if available. This will be set automatically.\n delete modifiedUser.tenantId;\n users.push(modifiedUser);\n });\n // Save next page token.\n pageToken = listUsersResult.pageToken;\n // Upload current chunk.\n return authTo.importUsers(users, userImportOptions);\n })\n .then(function(results) {\n results.errors.forEach(function(indexedError) {\n console.log('Error importing user ' + indexedError.index);\n });\n // Continue if there is another page.\n if (pageToken) {\n migrateUsers(userImportOptions, pageToken);\n }\n })\n .catch(function(error) {\n console.log('Error importing users:', error);\n });\n }\n var userImportOptions = {\n hash: {\n algorithm: 'SCRYPT',\n // The following parameters can be obtained from the \"Users\" page in the\n // Cloud console. The key must be a byte buffer.\n key: Buffer.from('base64-secret', 'base64'),\n saltSeparator: Buffer.from('base64SaltSeparator', 'base64'),\n rounds: 8,\n memoryCost: 14\n }\n };\n\n migrateUsers(userImportOptions);\n\nFor more information, see the\n[Admin SDK API reference](https://firebase.google.com/docs/auth/admin/import-users).\n\nMigrating users to a tenant\n---------------------------\n\nMigrating users from a non-tenant project to a tenant is almost exactly the same\nas migrating users between projects.\n\nAssuming the tenant belongs to a different project than the source\nIdentity Platform project, use the same code as before, but call\n`admin.auth().tenantManager().authForTenant()` on the target app instance and\nset the target tenant ID before calling `importUsers()`. \n\n var authTo = targetApp.auth().tenantManager().authForTenant('tenant');\n\nMigrating users between tenants\n-------------------------------\n\nMigrating users between tenants is very similar to migrating users between\nprojects, with two key differences:\n\n1. You'll need to delete the tenant ID from users of the old tenant before\n uploading them to the new tenant. Skipping this step will result in tenant\n ID mismatch errors.\n\n2. Call `admin.auth().tenantManager().authForTenant()` to set the tenant ID on\n the source and target tenants.\n\n // Migrate from tenant1 to tenant2 in same project.\n var authFrom = admin.auth().tenantManager().authForTenant('tenant1');\n var authTo = admin.auth().tenantManager().authForTenant('tenant2');\n\nThe rest of the code is the same."]]