![]() |
VOOZH | about |
dotnet add package FirebaseNetAdmin --version 1.0.0
NuGet\Install-Package FirebaseNetAdmin -Version 1.0.0
<PackageReference Include="FirebaseNetAdmin" Version="1.0.0" />
<PackageVersion Include="FirebaseNetAdmin" Version="1.0.0" />Directory.Packages.props
<PackageReference Include="FirebaseNetAdmin" />Project file
paket add FirebaseNetAdmin --version 1.0.0
#r "nuget: FirebaseNetAdmin, 1.0.0"
#:package FirebaseNetAdmin@1.0.0
#addin nuget:?package=FirebaseNetAdmin&version=1.0.0Install as a Cake Addin
#tool nuget:?package=FirebaseNetAdmin&version=1.0.0Install as a Cake Tool
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.
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.
var credentials = new JSONServiceAccountCredentials("your-file.json");
var firebaseClient = new FirebaseAdmin(credentials);
var credentials = new P12ServiceAccountCredentials("your-file.p12", "your-secret", "your-service-account", "your-database");
var firebaseClient = new FirebaseAdmin(credentials);
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);
Getting reference on some node of Database use firebaseClient.Database.Ref("endpoint") for example firebaseClient.Database.Ref("users/12/details")
Following reference query methods are available
Note: when using filters you should have index on that field, otherwise exception will throw saying specify index on the field.
For getting data
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>();
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();
Following storage methods are supported
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)
});
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net46 net46 is compatible. net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 10,780 | 10/27/2017 |
Initial release