如何使用.net核心连接到Cloud Firestore DB? [英] How to connect to Cloud Firestore DB with .net core?
问题描述
到目前为止,所有示例将Google Cloud Firestore与.net结合使用的a>表明您使用以下命令连接到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.
从用户指南的首页 :
在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核心连接到Cloud Firestore DB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!