Skip to content

A dart-native implementation of the Firebase Admin SDK, forked from cachapa/firedart

License

Notifications You must be signed in to change notification settings

netantho/Dartbase-Admin-SDK

 
 

Repository files navigation

Dartbase Admin SDK™️

A dart-native implementation of the Firebase Admin SDK.

This library is a fork of cachapa's client firebase sdk; cachapa/firedart; modified and converted to support admin only firebase features. This library also uses these files from appsup-dart/firebase_admin to enable admin authentication to firebase because it is not documented on firebase's official documentation (May 2020):

  • user_record.dart.
  • token_handler.dart

Currently supported:

  • Firebase Auth
  • Firestore
  • Firebase Storage

INCOMPLETE README

Dependencies

Add firedart to your pubspec.yaml file:

dependencies:
  firedart: [latest version]

Firebase Auth

The Firebase class implements the necessary functionality for managing accounts. It currently only supports Email/Password sign-in, so make sure it's enabled under Authentication -> Sign-in Method.

You'll also need to go to your Firebase Console, open Project Settings and under the General tab copy the Web API Key.

Note: in order to reduce external dependencies this library doesn't include a mechanism for persisting tokens. Please look at the following examples based on SharedPreferences and Hive.

Usage

import 'package:firedart/firedart.dart';

Firebase has a singleton version which should be enough for most use cases. You'll need to initialise it with your API key and a token store (see note above):

Firebase.initialize(apiKey, await HiveStore());
await Firebase.instance.signIn(email, password);
var user = await Firebase.instance.getUser();

Alternatively you can instantiate your own Firebase object:

var firebaseAuth = Firebase.(apiKey, await PreferencesStore());
await firebaseAuth.signIn(email, password);
var user = await firebaseAuth.getUser();

Further usage examples can be found in the integration tests.

Limitations

  • Currently the only supported authentication provider is Email/Password.

Firestore

The Firestore class is a basic implementation of the service's RPC interface. The API is similar (but not identical) to that of the official SDK.

Usage

import 'package:firedart/firedart.dart';

As with Firebase, Firestore offers a singleton version that needs to be initialised with your Project ID, which you can find under Project Settings -> General:

Firestore.initialize(projectId);
var map = await Firestore.instance.collection("users").get();
var users = UserCollection.fromMap(map);

You can also instantiate your own Firestore object. Please note that if your database requires authenticated access, you'll need to pass along an instance of Firebase.

var firebaseAuth = Firebase.(apiKey, await HiveStore());
var firestore = Firestore(projectId, auth: firebaseAuth);

await firebaseAuth.signIn(email, password);
var map = await firestore.collection("users").get();
var users = UserCollection.fromMap(map);

Further usage examples can be found in the integration tests.

Using the Firestore Admin SDK

Limited support is provided for using the Firestore Admin SDK. See (example/admin.dart)[example/admin.dart].

Limitations

  • Collection queries (limit, sort, etc.) are currently not supported.
  • The data is not cached locally.
  • Failed writes (e.g. due to network errors) are not retried.
  • Closed streams are not automatically recovered.

Regenerating the RPC stubs

The Firestore RPC stubs are based on Google's official protobuf definition files from googleapis.

To regenerate them, you will need to check out both googleapis and protobuf.

Set the PROTOBUF and GOOGLEAPIS environment variables to point to your clones of the above repositories respectively, and then run:

$ tool/regenerate.sh

Debugging

For debugging Firebase Auth you can use VerboseClient, an HTTP client that logs all communication to the console. The logs can expose sensitive data including passwords and keys, so it's recommended to only enable it for development builds. In Flutter this can be achieved using the kReleaseMode constant from the foundation package:

var client = !kReleaseMode ? VerboseClient() : http.Client();
var firebaseAuth = Firebase(apiKey, await PreferencesStore(), httpClient: client);

Securing Tokens

If you're running your code in an environment that requires securing access tokens, you can extend TokenStore to persist data in a secure maner, e.g. by encrypting the data or storing it in an external vault. Example implementations can be found in token_store.dart.

About

A dart-native implementation of the Firebase Admin SDK, forked from cachapa/firedart

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 99.7%
  • Shell 0.3%