Home > Net >  Update Firebase Auth user claims via rest API
Update Firebase Auth user claims via rest API

Time:10-06

At the moment I update user claims in a firebase function like so:

await admin.auth().setCustomUserClaims(...);

However I'm moving to use CloudRun, and I need a way to update user claims via the REST API. The docs don't seem to mention a way to do this. I'm using the dart package https://pub.dev/packages/googleapis and this doesn't even include Firebase auth stuff. Does anyone know if it's possible?

CodePudding user response:

This is one of those cases where it's really handy that the Firebase Admin SDKs are open source, as we can check how it implements the setCustomUserClaims function. You can see in there that it calls the accounts:update auth REST endpoint, which is documented in the reference documentation for updating a user profile.

So you will need to:

  1. Authenticate as a user who is at least an editor on the project.
  2. Build a request with a customAttributes property for the new claims.
  3. Call the accounts:update auth REST endpoint.

CodePudding user response:

I actually went for a solution similar to the one detailed in this article, you mirror the user claims in firestore collection and have a trigger to update the authentication objects. This makes it simple for my rest based stuff to update claims.

  • Related