Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Firebase Admin SDK in .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.

like image 348
tempUser Avatar asked Apr 28 '17 17:04

tempUser


People also ask

What is the firebase admin SDK?

The Firebase Admin .NET SDK enables access to Firebase services from privileged environments (such as servers or cloud) in .NET. Currently this SDK provides Firebase custom authentication support. For more information, please visit the Firebase Admin SDK setup guide.

How do I set up a new firebase project?

Firebase automatically provisions resources for your Firebase project. When the process completes, you'll be taken to the overview page for your Firebase project in the Firebase console. If you are setting up a new project, you need to install the SDK for the language of your choice. The Firebase Admin Node.js SDK is available on npm.

Is it possible to use Firebase REST API with OAuth?

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.

How to access Google Cloud Platform resources in Firebase?

Access Google Cloud Platform resources like Cloud Storage buckets and Cloud Firestore databases associated with your Firebase projects. Create your own simplified admin console to do things like look up user data or change a user’s email address for authentication. To use Admin SDK, you need to add firebase-admin npm package to your project first:


1 Answers

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

like image 104
Dominik Avatar answered Oct 15 '22 12:10

Dominik