step-up-labs / firebase-authentication-dotnet

C# library for Firebase Authentication
MIT License
376 stars 129 forks source link

Adding support for user claims #63

Open alexAlchemy opened 6 years ago

alexAlchemy commented 6 years ago

Typically JWT holds claims for users. This is supported in firebase in the other SDK's which can set the claims associated with a user.

https://firebase.google.com/docs/auth/admin/custom-claims

This is almost certainly an enhancement but is it possible to add this feature?

420tech commented 2 years ago

I totally agree with alexAlchemy. I need to retrieve the custom claims from FirebaseAuthentication for each user.

dromerolovo commented 6 months ago

@bezysoftware Any update regarding this?

@420tech

Regarding retrieving custom claims from the client:

I don't know too much about Firebase Auth. But this is something that you can use as a workaround, I've only tested this with email/password provider.

var token = await user.User.GetIdTokenAsync();
//namespace: System.IdentityModel.Tokens.Jwt
var tokenHandler = new JwtSecurityTokenHandler();
var jwtToken = tokenHandler.ReadJwtToken(token);
var claims = jwtToken.Claims;

Then you can find the custom claim that you are interested.

var customClaim = claims.First(claim => claim.Type == "<key-of-claim>");

Regarding setting that's something that should be taken care on the server with any firebase admin sdk. This is a client sdk. Of course you can still use the admin sdk in your client app https://www.nuget.org/packages/FirebaseAdmin but that's something that is not recommended.