Azure Function中的Firestore .NET客户端库身份验证 [英] Firestore .NET client library authentication in Azure Function
问题描述
我正在C#Azure Function应用中使用Google.Cloud.Firestore 1.0.0-beta22版本.该文档指出要创建一个服务帐户json文件,并创建一个指向该json文件的GOOGLE_APPLICATION_CREDENTIALS环境变量.
I am using Google.Cloud.Firestore version 1.0.0-beta22 in a C# Azure Function app. The documentation states to create a service account json file and create a GOOGLE_APPLICATION_CREDENTIALS environment variable pointing to this json file.
我的问题是我不想将json文件添加到我的源存储库中,即使我不知道运行Azure函数的目录的路径,因此也无法设置环境变量.
My issue is I don't want to add the json file to my source repository, and even if I did I don't know the path to the directory that the Azure Function will be running in, thus I am unable to set the environment variable.
是否有办法将凭据传递到Firestore客户端库,或者有其他解决方法来解决此问题?
Is there a way to pass the credentials to the Firestore client library, or any other workarounds to address this?
推荐答案
经过大量的搜索之后,我发现您可以从Json创建凭据,并使用它创建FirestoreClient,然后将其传递给FirestoreDb.
After much googling I've found that you can create a credential from Json and use this to create a FirestoreClient which you then pass to the FirestoreDb.
var credential = GoogleCredential.FromJson(<JSON AS STRING>);
var channelCredentials = credential.ToChannelCredentials();
var channel = new Channel(FirestoreClient.DefaultEndpoint.ToString(), channelCredentials);
var client = FirestoreClient.Create(channel);
var firestoreDb = FirestoreDb.Create("project id", client);
这篇关于Azure Function中的Firestore .NET客户端库身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!