firebase_auth_token 1.0.5 copy "firebase_auth_token: ^1.0.5" to clipboard
firebase_auth_token: ^1.0.5 copied to clipboard

Extract user from verified Firebase Auth id token. The Firebase public key is cached and updated autimatically.

firebase_auth_token #

Extract user from verified Firebase Auth id token.

Watch on GitHub Star on GitHub pub package

Getting started #

There is just one class FirebaseAuthToken with the methods getUserFromToken({authentication-token}) and getDataFromToken({authentication-token}) which will return a AuthUser / Map<String, dynamic> object if the token is valid or else it will throw an exception.

// Get the AuthUser object
final user = await FirebaseAuthToken.getUserFromToken('{token}');

// If there are custom claims in the token then you can use the method
// getCustomClaim(String)
final isAdmin = user.getCustomClaim('isAdmin');
if (isAdmin) {
    ...
}

// -or- getCustomClaims((data) => CustomClaims(data)) to create
// a custom object for the custom claims
class CustomClaims {
    final bool isAdmin;
    CustomClaims(Map<String, dynamic> data) : isAdmin = data['isAdmin'] as bool;
}
final customClaims = user.getCustomClaims((data) => CustomClaims(data));
if (customClaims.isAdmin) {
    ...
}

// -or- if you want to skip the provided objects you can use the raw data below to create a custom object.
final data = await FirebaseAuthToken.getDataFromToken('{token}');


License #

This project is licensed under the MIT License - see the license file for details.

3
likes
130
pub points
70%
popularity

Publisher

unverified uploader

Extract user from verified Firebase Auth id token. The Firebase public key is cached and updated autimatically.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

http, jose, synchronized

More

Packages that depend on firebase_auth_token