FirebaseNetAdmin 1.0.0

Install-Package FirebaseNetAdmin -Version 1.0.0
dotnet add package FirebaseNetAdmin --version 1.0.0
<PackageReference Include="FirebaseNetAdmin" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FirebaseNetAdmin --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FirebaseNetAdmin, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install FirebaseNetAdmin as a Cake Addin
#addin nuget:?package=FirebaseNetAdmin&version=1.0.0

// Install FirebaseNetAdmin as a Cake Tool
#tool nuget:?package=FirebaseNetAdmin&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

FirebaseNetAdmin NuGet

FirebaseNetAdmin is a .NET library for interacting with Firebase Database and Storage. The interface of library is similar to offical Google Node, Java (Admin) SDKs.

Initialization

Supports both JSON and P12 config files. In order to give permissions to use your Firebase Database and Storage you need first in your Firebase app create service account with corresponding permissions. After creating the service account you will be prompted to download either JSON file or P12 file, recommended is JSON file. Download that file and attach to your project.

  • JSON file
var credentials = new JSONServiceAccountCredentials("your-file.json");
var firebaseClient = new FirebaseAdmin(credentials);
  • P12 file
var credentials = new P12ServiceAccountCredentials("your-file.p12", "your-secret", "your-service-account", "your-database");
var firebaseClient = new FirebaseAdmin(credentials);

Auth

Create token for some userId which should be used by client to authenticate against Firebase Database, that token could be used in client sdks by calling firebase.auth().signInWithCustomToken(token)

 var token = firebaseClient.Auth.CreateCustomToken(userId);

Database

Getting reference on some node of Database use firebaseClient.Database.Ref("endpoint") for example firebaseClient.Database.Ref("users/12/details")

Query database

Following reference query methods are available

  • StartAt
  • EndAt
  • EqualTo
  • LimitToFirst
  • LimitToLast
  • OrderBy

Note: when using filters you should have index on that field, otherwise exception will throw saying specify index on the field.

For getting data

  • Get
  • GetArray
  • GetWithKeyInjected
  • GetArrayWithKeyInjected

with their corresponding async methods

Examples: Let's say you have this structure in Firebase:

-users/{userId}/events

                  --EventKey1
                  ---- CodeId: 1
                  ---- IsRead: true,
                  ---- Timestamp: 1502047422150
                  --EventKey2
                  ---- CodeId: 2
                  ---- IsRead: false,
                  ---- Timestamp: 1502047422279

Let's assume we have UserHistory class

class UserHistory {
            public int CodeId { get; set; }
            public bool IsRead { get; set; }
            public long Timestamp { get; set; }
}

and can query via


var result = firebaseClient.Database.Ref("users/330/events")
                .OrderBy("isRead").LimitToLast(1)
                .Get<UserHistory>();

We can inject key into model by inheriting UserHistory: KeyEntity and instead of calling .Get<UserHistory>() call .GetWithKeyInjected<UserHistory>() like:

var result = firebaseClient.Database.Ref("users/330/events")
                .OrderBy("isRead").LimitToLast(1)
                .GetWithKeyInjected<UserHistory>();

Update database

  • Push
  • Set
  • Update
  • Delete

With corresponding async methods. Methods are functioning exactly like their counterparts in NodeJS or Java SDKs.

Examples:

Push

var result = firebaseClient.Database.Ref("/users/30/details").Push(new Detail())

Bulk update

var result = firebaseClient.Database.Ref("/users/30/details").Update(new Dictionary<string, object>() {
                { "codeId", 20 } ,
                { "info","info"} ,
                { "sub/info","subinfo"} ,
             });

Set

var result = firebaseClient.Database.Ref("/test").Set(new Test1());

Delete

firebaseClient.Database.Ref("/test").Delete();

Storage

Following storage methods are supported

  • GetPublicUrl
  • GetSignedUrl
  • RemoveObjectAsync
  • GetObjectMetaDataAsync
  • MoveObjectAsync

Examples:

var result = await firebaseClient.Storage.GetObjectMetaDataAsync("test/my-image");

var publicUrl = firebaseClient.Storage.GetPublicUrl("my-image");

var signedUrl = firebaseClient.Storage.GetSignedUrl(new Firebase.Storage.SigningOption()
             {
                 Action = Firebase.Storage.SigningAction.Write,
                 Path = "my-image",
                 ContentType = "image/jpeg",
                 ExpireDate = DateTime.Now + new TimeSpan(0, 0, 0, 0, 60000000)
             });

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 2,678 10/27/2017

Initial release