Image for post
Image for post

Firebase: Importing users with the Admin SDK

Firebase Admin SDK is rolling out a new API for importing users into Firebase projects in bulk. This is useful for developers who wish to migrate users from various external user stores into Firebase. The bulk import capability has been present in the Firebase CLI for a while. But the CLI can only import users that are stored in JSON or CSV files. In contrast, the Admin SDK enables developers to implement their own tools and services that import users into Firebase projects from arbitrary sources.

The new API supports importing up to 1000 users per invocation. Listing 1 shows how to use this API in Python.

Listing 1: Importing users in bulk with the Firebase Admin SDK

The return value of the import_users() method indicates how many users were imported successfully, and how many were failed. It is also possible to inspect the causes behind failed imports. Listing 2 illustrates how.

Listing 2: Handling import results

The new API also facilitates importing users with passwords. In that case the ImportUserRecord must specify the password hash, and the configuration of the hashing algorithm should be passed to the import_users() method. Listing 3 shows an example where some users with SHA256 password hashes are being imported into Firebase.

Listing 3: Importing users with passwords

Admin SDK supports around a dozen password hashing algorithms including the modified variant of Scrypt that Firebase Auth uses by default. The new import users API is currently available in Node.js, Java and Python. The Go implementation is awaiting release, and chances are it will be available for use by the time you read this. Head over to the official documentation to get started, and as always feel encouraged to share your thoughts on how this feature can be improved further.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store