vb.net 如何在 .NET 中使用 Firebase Admin SDK?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43686262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Firebase Admin SDK in .NET?
提问by tempUser
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.
我有一个用 VB.Net 编写的 Windows 桌面应用程序。我的服务器需要与 Firebase 连接才能向应用程序(Firebase 实时数据库)发送更新。现在我可以使用服务帐户中的“数据库机密”来执行此操作,但由于已弃用,因此我想使用较新的 Firebase Admin SDK。我不需要任何用户的实际身份验证,因为这是使用服务帐户。有没有一种方法可以使用管理 SDK 或任何 3rd Party 库(用于 .NET),这将允许我这样做。结果我的搜索没有成功。这是我在这里的第一个问题。如果有人能指导我朝着正确的方向前进,我将不胜感激。
回答by Dominik
The Firebase Admin SDK was released some time ago and you can find the repository here: https://github.com/firebase/firebase-admin-dotnet
Firebase Admin SDK 已发布一段时间,您可以在此处找到存储库:https: //github.com/firebase/firebase-admin-dotnet
Keep in mind that this is very limited compared to the other admin SDKs.
请记住,与其他管理 SDK 相比,这是非常有限的。
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
回答by Hiranya Jayathilaka
There's currently no Firebase Admin SDK available for the .NET environment. But you can use the Firebase REST APIwith an OAuth token. You will have to use a .NET libraryto kick off the OAuth flow, and obtain a token.
目前没有可用于 .NET 环境的 Firebase Admin SDK。但是您可以通过OAuth 令牌使用Firebase REST API。您必须使用.NET 库来启动 OAuth 流程,并获取令牌。
Update:Firebase Admin .NET SDK is now available. See Dominik's reply.
更新:Firebase Admin .NET SDK 现已推出。请参阅多米尼克的回复。

