Firebase Admin SDK: list_users() error INSUFFICIENT_PERMISSION

Viewed 841

I'm using the Firebase Admin Python SDK to connect to our Firebase instance where are users are stored for a web application. I am attempting to create a job that queries Firebase every day and gets a count of users and then archives this off to our data warehouse to report on it going forward. I've successfully created service account credentials and made sure the credentials are valid by accessing the Google Cloud Platform (following these instructions):

import firebase_admin

creds = firebase_admin.credentials.Certificate("/Users/me/Downloads/service-account-146c01507e2b.json")
default_app = firebase_admin.initialize_app(creds)

However, the instructions are not clear on how I go about authenticating in order to pull back a list of all users. It just says to import the auth class and then run auth.list_users() but doesn't clarify how to authenticate using this class.

When I run firebase_admin.auth.list_users() I get the following error: InvalidArgumentError: Error while calling Auth service (INSUFFICIENT_PERMISSION).

Can anyone help me understand how/where I authenticate with my service account credentials? Thanks!

1 Answers

Firebase Service Account

The Firebase service account should be generated from:

Firebase Console > Project Settings > Service Accounts and clicking Generate new private key

Initialize Firebase SDK

import json
import firebase_admin
from firebase_admin import credentials


FIREBASE_CERT = "credentials/firebase-adminsdk-####-##########.json"

with open(FIREBASE_CERT) as json_file:
  json_data = json.load(json_file)

DEFAULT_CRED = credentials.Certificate(json_data)

app_instance = firebase_admin.initialize_app(DEFAULT_CRED)

firebase_admin.auth.list_users()
Related