Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between auth.uid and auth.token.sub in Firebase Realtime Database security rules

What is the difference between auth.uid and auth.token.sub in Firebase Realtime Database security rules?

I assume they are the same (user has only 1 uid) but they have different descriptions, would love to know a definitive answer.

auth.uid : A unique user id, guaranteed to be unique across all providers.

auth.token.sub : The user's Firebase UID. This is unique within a project.

Cheers

like image 333
Edward Avatar asked Dec 01 '16 21:12

Edward


People also ask

What is the use of uid in Firebase?

So after you authenticate the users, the uid will be in the authentication page in firebase. That id will help you later in the firebase database also and it is easier to use and add in the database. Can easily be gotten using this: FirebaseUser user=FirebaseAuth.

What is auth token in Firebase?

When a user or device successfully signs in, Firebase creates a corresponding ID token that uniquely identifies them and grants them access to several resources, such as Firebase Realtime Database and Cloud Storage. You can re-use that ID token to identify the user or device on your custom backend server.

Is Firebase uid safe?

The correct way to secure user related resources is via a Firebase ID token. Database/Storage rules already rely on this mechanism. You cannot just rely on the correct user ID being provided. That provides no security.

What file should be used for Realtime Database security rules?

To access your rules from the Firebase console, select your project, then in the left-hand navigation panel, click Realtime Database. Click Rules once you're in the correct database or storage bucket. To access your rules from the Firebase CLI, go to the rules file noted in your firebase. json file.


1 Answers

They are exactly the same. auth.uid is provided for backwards compatibility (auth.token didn't used to exist in the Security Rules) and ease-of-use: sub is not a commonly understood term for an ID, whereas uid is a bit easier to understand and you don't have to dive into the token contents.

like image 110
Michael Bleigh Avatar answered Oct 20 '22 01:10

Michael Bleigh