How to use Firebase Admin SDK in .NET?

十年热恋 提交于 2019-12-13 15:15:53

问题


I have a windows desktop app written in VB.Net.My server needs to connect with the Firebase to send updates to the app (Firebase Realtime Database). Right now I am able to do this using the "Database secrets" in the service accounts, but since this is deprecated, I would like to use the newer Firebase Admin SDK. I will not be needing the actual authentication of any users since this is using a service account. Is there a way I could use the admin SDK or any 3rd Party library (for .NET) which will allow me to do that. My search didn't turn out to have any success. This is my first question here. I appreciate if somebody could direct me in the right direction.


回答1:


The Firebase Admin SDK was released some time ago and you can find the repository here: https://github.com/firebase/firebase-admin-dotnet

Keep in mind that this is very limited compared to the other admin SDKs.

How to use:

// Initialize the admin SDK with your service account keys.
// This should be called before using the admin SDK e.g. Startup.cs in ASP.NET Core.
// There are other config loader methods besides of FromFile e.g. FromJson etc.
FirebaseApp.Create(new AppOptions()
{
    Credential = GoogleCredential.FromFile("path/to/serviceAccountKey.json"),
});


// Then FirebaseAuth.DefaultInstance will give you the initialized SDK Auth instance.
// E.g.:
await FirebaseAuth.DefaultInstance.SetCustomUserClaimsAsync(uid, claims);

More info: https://firebase.google.com/docs/admin/setup




回答2:


There's currently no Firebase Admin SDK available for the .NET environment. But you can use the Firebase REST API with an OAuth token. You will have to use a .NET library to kick off the OAuth flow, and obtain a token.

Update: Firebase Admin .NET SDK is now available. See Dominik's reply.



来源:https://stackoverflow.com/questions/43686262/how-to-use-firebase-admin-sdk-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!