FirebaseNetAdmin 1.0.0
dotnet add package FirebaseNetAdmin --version 1.0.0
NuGet\Install-Package FirebaseNetAdmin -Version 1.0.0
<PackageReference Include="FirebaseNetAdmin" Version="1.0.0" />
paket add FirebaseNetAdmin --version 1.0.0
#r "nuget: FirebaseNetAdmin, 1.0.0"
// 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
FirebaseNetAdmin
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)
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
- BouncyCastle (>= 1.8.1)
- jose-jwt (>= 2.4.0)
- NetLegacySupport.Tuple (>= 1.1.1)
- Newtonsoft.Json (>= 10.0.3)
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 | 7,381 | 10/27/2017 |
Initial release