validate_firebase_auth

Creator: coderz1093

Last updated:

0 purchases

validate_firebase_auth Image
validate_firebase_auth Images

Languages

Categories

Add to Cart

Description:

validate firebase auth

validate_firebase_auth #




A small package that verifies Firebase Auth Tokens when writing server-side Dart code. Perfect for use with the Dart Functions Framework!
The validation follows these steps, and validation is done with the openid_client package. Give their repo a star along with this one if you find this package useful! Their package does all the heavy cryptography lifting!
Getting Started #
Validating is easy! Just

Create a FirebaseAuthValidator()
Initialize with validator.init()
Validate JWT with validator.validate()

final jwt = '...'; // Generated with a client library and sent with the request
final validator = FirebaseAuthValidator();
await validator.init();
final idToken = await validator.validate(jwt);
copied to clipboard
Specifiying Project Id #
If you are running this code on a Google Cloud service (like Cloud Run or GCE), the project id will discovered automatically when you run validator.init() . You can specify a project id manually using validator.init(projectId: projectId)
Using in Tests #
You can easily mock a FirebaseAuthValidator using mocktail, the type safe and null safe tool for mocking objects in tests. For example:
import 'package:mocktail/mocktail.dart';

class MockFirebaseAuthValidator extends Mock implements FirebaseAuthValidator { }

class MockIdToken extends Mock implements IdToken { }

void main() {
late FirebaseAuthValidator validator;
late idToken token;

setUp(() {
validator = MockFirebaseAuthValidator();
idToken = MockIdToken();

when(() => validator.init()).thenAnswer((_) async => null);
when(() => validator.validate()).thenAnswer((_) async => idToken);

when(() => idToken.isVerified).thenReturn(true);
});
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.