1

I'm looking to build a CLI application (most likely in C#) for Linux, Windows and Mac. The App will all access some of my API's, arleady deployed in the cloud. These API's are protected using Firebase Auth. At the moment Auth is done via my website and I support Social Sign in such as GitHub, Google etc.

Now when it comes to adding auth into a CLI app I'm completely stumped. I've been Googling this and can't find anything that walks through what you need to use. Do I need to package the Admin SKD? How to do I protect my Firebase keys (do the need to be in the CLI app)?

Can anyone point me in the right direction here please?

Many thanks in advance

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
MetaCoder
  • 368
  • 5
  • 22
  • I was actually writing a post on "Firebase Authentication for CLI apps" right now :) But with NodeJS and Go. If you want to take a look at Go sample, checkout [this Gist](https://gist.github.com/DharmarajX24/bf68d942ba9be72384ea76295b5196ea). I'll update my post below if I write one with C# but the flow should be same irrespective of the language. – Dharmaraj Feb 06 '23 at 11:31

1 Answers1

1

For email and password authentication, you can use Firebase Auth REST API to create/login a user with provided credentials.
For OAuth providers such as Google and Github, you can follow OAuth 2.0 Device Authorization Flow described in RFC 8628 and then call Firebase's 'sign in with OAuth credential' to create the user in Firebase Authentication. Here's the general flow for Google Auth:

  1. Request device and user code from the OAuth provider (e.g. Google)
  2. Open the returned link in a browser and ask user to enter the code shown (user may have to open the browser in any other device if current one cannot open a browser e.g. in VMs)
  3. Keep polling for access token till you get the token or any of the errors listed in RFC 8628 section 3.5.
  4. Create/SignIn the user with Firebase using sign in with OAuth credentials REST API using the accessToken returned in previous step.

The last API will return Firebase Authentication's idToken and refreshToken that you can use to further authentication users in your backend.

Checkout OAuth 2.0 for limited input device apps for more information.


Do I need to package the Admin SDK?

No, the Admin SDK must be used only on server side as it has privileged access to your Firebase resources like bypassing security rules.

How to do I protect my Firebase keys (do the need to be in the CLI app)?

The keys are meant to be public (like an identifier for your project). See Is it safe to expose Firebase apiKey to the public? for more information.

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
  • Thank you so much for this info. Is there any concret examples of this / Tutorials. I've done this in Spring before but trying to learn C# and figure out Firebase seems to be too much right now – MetaCoder Feb 23 '23 at 17:33