GoodGoodMan
GoodGoodMan

Reputation: 17

How to get custom claims of `FirebaseUser` on unity

I using firebase auth on unity for user login.

When user join, client send join request to my my server and my server will set custom claim(userNumber) to user.(Currently, Server using firebase-admin-dotnet)

After user joined, client re-login for refresh. At this time, i want get custom claim in token. but i can't find relative method in FirebaseUser class..

Upvotes: 0

Views: 575

Answers (1)

MandisaW
MandisaW

Reputation: 1021

Custom claim access is missing from the Unity SDK as of v6.6 (Nov 2019). You can add a server function that returns the custom claims for the current user:

// Either use an existing User ID
UserRecord user = await FBAuth.GetUserAsync (uid);
return user.CustomClaims; // user.CustomClaims ["userNumber"]

// OR use a verified ID token
FirebaseToken token = await FBAuth.VerifyIdTokenAsync (idToken);
return token.Claims; // token.Claims ["userNumber"]

Important: If you use a billed-usage server, like Cloud Functions, this approach will incur billing charges, unlike a built-in Firebase method.

Other platforms (Android, iOS, web) have this method already (getIdTokenResult), so I submitted a feature request to Firebase to include it in a future version.

Upvotes: 1

Related Questions