firebase_admin 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

A pure Dart implementation of the Firebase admin sdk

Currently, only supports admin methods for the following firebase services:

  • authentication
  • realtime database

Example using service account #

import 'package:firebase_admin/firebase_admin.dart';

main() async {
  var app = FirebaseAdmin.instance.initializeApp(AppOptions(
    credential: ServiceAccountCredential('service-account.json'),
  ));

  var link = await app.auth().generateSignInWithEmailLink('jane@doe.com',
      ActionCodeSettings(url: 'https://example.com'));

  print(link);
}

Example using default credentials #

import 'package:firebase_admin/firebase_admin.dart';
import 'package:firebase_admin/src/credential.dart';

void main() async {
  // applicationDefault() will look for credentials in the following locations:
  // * the env variable GOOGLE_APPLICATION_CREDENTIALS
  // * a configuration file, specific for this library, stored in the user's home directory
  // * gcloud's application default credentials
  // * credentials from the firebase tools
  var credential = Credentials.applicationDefault();

  // when no credentials found, login using openid
  // the credentials are stored on disk for later use
  credential ??= await Credentials.login();

  // create an app
  var app = FirebaseAdmin.instance.initializeApp(AppOptions(
      credential: credential ?? Credentials.applicationDefault(),
      projectId: 'some-project'));

  try {
    // get a user by email
    var v = await app.auth().getUserByEmail('jane@doe.com');
    print(v.toJson());
  } on FirebaseException catch (e) {
    print(e.message);
  }
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.1.2 #

  • admin sdk for firebase storage

0.1.1 #

  • look for default credentials in Firebase CLI configurations
  • get credentials by openid login

0.1.0 #

  • admin sdk for firebase realtime database
  • admin sdk for firebase authentication

example/main.dart

import 'package:firebase_admin/firebase_admin.dart';
import 'package:firebase_admin/src/credential.dart';

void main() async {
  // applicationDefault() will look for credentials in the following locations:
  // * the env variable GOOGLE_APPLICATION_CREDENTIALS
  // * a configuration file, specific for this library, stored in the user's home directory
  // * gcloud's application default credentials
  // * credentials from the firebase tools
  var credential = Credentials.applicationDefault();

  // when no credentials found, login using openid
  // the credentials are stored on disk for later use
  credential ??= await Credentials.login();

  var projectId = 'some-project';
  // create an app
  var app = FirebaseAdmin.instance.initializeApp(AppOptions(
      credential: credential ?? Credentials.applicationDefault(),
      projectId: projectId,
      storageBucket: '$projectId.appspot.com'));

  try {
    // get a user by email
    var v = await app.auth().getUserByEmail('jane@doe.com');
    print(v.toJson());
  } on FirebaseException catch (e) {
    print(e.message);
  }

  await for (var v in app.storage().bucket().list()) {
    print(v.name);
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  firebase_admin: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:firebase_admin/firebase_admin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
55
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/database.dart. (-2.48 points)

Analysis of lib/src/database.dart reported 5 hints:

line 10 col 9: 'Firebase' is deprecated and shouldn't be used.

line 17 col 20: 'Firebase' is deprecated and shouldn't be used.

line 19 col 31: The member 'internals' can only be used within 'package:firebase_admin/src/app.dart' or a test.

line 20 col 9: The member 'internals' can only be used within 'package:firebase_admin/src/app.dart' or a test.

line 26 col 3: 'Firebase' is deprecated and shouldn't be used.

Fix lib/src/app/app.dart. (-0.50 points)

Analysis of lib/src/app/app.dart reported 1 hint:

line 5 col 8: Unused import: '../auth/credential.dart'.

Fix lib/src/utils/api_request.dart. (-0.50 points)

Analysis of lib/src/utils/api_request.dart reported 1 hint:

line 17 col 36: The member 'internals' can only be used within 'package:firebase_admin/src/app.dart' or a test.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
clock ^1.0.0 1.0.1
collection ^1.14.11 1.14.12
crypto_keys ^0.1.0 0.1.0+2
dotenv ^2.0.0 2.0.0
firebase_dart ^0.7.15+3 0.7.15+4
gcloud ^0.6.3 0.6.3
http ^0.12.0 0.12.0+4
jose ^0.1.2 0.1.2+1
meta ^1.1.6 1.1.8
openid_client ^0.2.5 0.2.5
path ^1.6.4 1.6.4
x509 ^0.1.0 0.1.0+1
Transitive dependencies
_discoveryapis_commons 0.1.9
args 1.6.0
asn1lib 0.6.4
async 2.4.1
built_collection 4.3.2
built_value 7.0.9
charcode 1.1.3
convert 2.1.1
crypto 2.1.4
dart2_constant 1.0.2+dart2
fixnum 0.10.11
googleapis 0.54.0
http_parser 3.1.4
isolate 2.0.3
logging 0.11.4
matcher 0.12.6
pointycastle 1.0.2
quiver 2.1.3
sortedmap 0.4.2+1
source_span 1.7.0
stack_trace 1.9.3
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
web_socket_channel 1.1.0
Dev dependencies
fake_async ^1.0.0
mockito ^4.1.1
pedantic ^1.9.0 1.9.0
test ^1.0.0