如何使用 .net core 连接到 Cloud Firestore DB? [英] How to connect to Cloud Firestore DB with .net core?

查看:23
本文介绍了如何使用 .net core 连接到 Cloud Firestore DB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止所有示例 使用 Google Cloud Firestore 和 .net 显示您使用以下命令连接到 Firestore 数据库:

So far all the examples of using Google Cloud Firestore with .net show that you connect to your Firestore db by using this command:

FirestoreDb db = FirestoreDb.Create(projectId);

但这是否跳过了身份验证步骤?我似乎找不到连接它以使用 Google 服务帐户的示例.我猜您需要使用服务帐户的 private_key/private_key_id/client_email 进行连接?

But is this skipping the step of authentication? I can't seem to find an example of wiring it up to use a Google service account. I'm guessing you need to connect using the service account's private_key/private_key_id/client_email?

推荐答案

但这是否跳过了身份验证步骤?

But is this skipping the step of authentication?

没有.它将使用默认的应用程序凭据.如果您在 Google Cloud Platform(AppEngine、GCE 或 GKE)上运行,它们将只是实例的默认服务帐户凭据.否则,您应该设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量以引用服务帐户凭据文件.

No. It will use the default application credentials. If you're running on Google Cloud Platform (AppEngine, GCE or GKE), they will just be the default service account credentials for the instance. Otherwise, you should set the GOOGLE_APPLICATION_CREDENTIALS environment variable to refer to a service account credential file.

来自用户指南的主页 你提到:

From the home page of the user guide you referred to:

在 Google Cloud Platform 上运行时,无需采取任何措施进行身份验证.

When running on Google Cloud Platform, no action needs to be taken to authenticate.

否则,验证 API 调用的最简单方法是下载服务帐户 JSON 文件,然后设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量以引用它.凭据将自动用于身份验证.有关详细信息,请参阅身份验证入门指南.

Otherwise, the simplest way of authenticating your API calls is to download a service account JSON file then set the GOOGLE_APPLICATION_CREDENTIALS environment variable to refer to it. The credentials will automatically be used to authenticate. See the Getting Started With Authentication guide for more details.

使用非默认凭据有点尴尬;这个最近的问题给出了一个例子.

It's somewhat more awkward to use non-default credentials; this recent issue gives an example.

这篇关于如何使用 .net core 连接到 Cloud Firestore DB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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