Firebase Storage Rules with Custom Claims

Firebase Storage Rules with Custom Claims

I am unable to get Firebase Storage work with custom rules and using custom claims.

I am unable to get Firebase Storage work with custom rules and using custom claims.

In my Python Admin panel, I do the following to create the user and assign a claim client_id:

# Standard Auth
import firebase_admin
from firebase_admin import db, storage, auth
cred   = firebase_admin.credentials.Certificate('path_to_cert_json')
app    = firebase_admin.initialize_app(cred, 'config')
bucket = storage.bucket(app=app)

Create User

auth.create_user(email=email)

Create custom claims

auth.set_custom_user_claims(uid, {'client_id': client_id})

Then for Firebase rules, I try to allow the user to only read (or download) files when the file is in a subfolder with the client_id:

File structure on storage:

/{environment}/{client_id}/other_folders_and_files

I set the following storage rules:

service firebase.storage {
  match /b/{bucket}/o {
    match /{environment}/{client_id}/{allPaths=**} {
      allow read: if request.auth.token.client_id == client_id
    }
  }
}

But that gives me an error that Permission is denied.

What am I doing wrong?

Note:

  • client_id is correct and the folder structure is correct, have checked this a million times.


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Top Python Development Companies | Hire Python Developers

After analyzing clients and market requirements, TopDevelopers has come up with the list of the best Python service providers. These top-rated Python developers are widely appreciated for their professionalism in handling diverse projects. When...

Python Firebase Cloud Firestore Example

In this Python Firebase tutorial, we are going to to talk about Python Firebase Cloud Firestore Example. What is Cloud Firestore ? According to Firebase Documentation, Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform

Python GUI Programming Projects using Tkinter and Python 3

Python GUI Programming Projects using Tkinter and Python 3