Firebase: 如何将身份验证添加到 CLI 应用程序中

huangapple go评论60阅读模式
英文:

Firebase: How to add authentication into a cli application

问题

I'm looking to build a CLI application (most likely in C#) for Linux, Windows, and Mac. The App will access some of my APIs, already deployed in the cloud. These APIs 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 SDK? How do I protect my Firebase keys (do they need to be in the CLI app)?

Can anyone point me in the right direction here please?

Many thanks in advance.

英文:

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

答案1

得分: 2

以下是您要翻译的内容:

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 the user to enter the code shown (the user may have to open the browser on any other device if the current one cannot open a browser, e.g., in VMs)
  3. Keep polling for an access token until you get the token or any of the errors listed in RFC 8628 section 3.5.
  4. Create/Sign in the user with Firebase using sign in with OAuth credentials REST API using the accessToken returned in the previous step.

The last API will return Firebase Authentication's idToken and refreshToken that you can use to further authenticate 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 the server side as it has privileged access to your Firebase resources like bypassing security rules.

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

The keys are meant to be public (like an identifier for your project). See https://stackoverflow.com/questions/37482366/is-it-safe-to-expose-firebase-apikey-to-the-public for more information.

英文:

For email and password authentication, you can use Firebase Auth REST API to create/login a user with provided credentials. <br>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.

<hr />

> 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 https://stackoverflow.com/questions/37482366/is-it-safe-to-expose-firebase-apikey-to-the-public for more information.

huangapple
  • 本文由 发表于 2023年2月6日 19:06:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75360514.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定