如何在.NET中使用Firebase Admin SDK? [英] How to use Firebase Admin SDK in .NET?

查看:109
本文介绍了如何在.NET中使用Firebase Admin SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用VB.Net编写的Windows桌面应用程序.我的服务器需要与Firebase连接才能将更新发送到该应用程序(Firebase实时数据库).现在,我可以使用服务帐户中的数据库机密"来执行此操作,但是由于不建议使用此功能,因此我想使用较新的Firebase Admin SDK. 我将不需要任何用户的实际身份验证,因为它使用的是服务帐户. 有没有一种方法可以使用admin SDK或任何第三方库(用于.NET),这将使我能够做到这一点.我的搜索结果没有成功. 这是我的第一个问题.我很高兴有人可以指引我正确的方向.

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.

推荐答案

Firebase Admin SDK已于不久前发布,您可以在此处找到存储库:

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

请记住,与其他管理SDK相比,这是非常有限的.

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

使用方法:

// 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);

更多信息: https://firebase.google.com/docs/admin/setup

这篇关于如何在.NET中使用Firebase Admin SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆