Google数据存储身份验证问题 - C# [英] Google Datastore authentication issue - C#

查看:740
本文介绍了Google数据存储身份验证问题 - C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用服务帐户凭证文件(我根据文档创建的帐户)连接到我的帐户上的Google数据存储,但在尝试插入实体时遇到验证错误:


Grpc.Core.RpcException:Status(StatusCode = Unauthenticated,
Detail =异常发生在元数据凭证插件中。) p>

我的代码是:

  var db = DatastoreDb.Create(myprojectid); 
Entity entity = new Entity {
Key = db.CreateKeyFactory(mykindname)。CreateIncompleteKey()
};
var keys = await db.InsertAsync(new [] {entity});

GOOGLE_APPLICATION_CREDENTIALS 变量引用凭证文件,并在调用GoogleCredential.GetApplicationDefaultAsync ()来查看凭证对象是否有效,它确实看起来不错...



我看到一些使用GetApplicationDefaultAsync函数创建一些DatastoreService对象的例子 - 但我在最新的.Net API中找不到 DatastoreService 对象(可能在旧版本中存在...): Google.Cloud.Datastore.V1



请注意,我不要希望使用其他身份验证方法:

<1>使用gcloud cli。



2)从Google环境运行(例如应用程序引擎)。

任何想法如何解决这个问题?

解决方案

在Jon Skeet的大力帮助下,问题解决了。

身份验证问题c如果您没有引用所有必需的Datastore dll,则会发生。确保运行数据存储调用的项目上引用了所有dll。



我通过NuGet将Google Datastore lib添加到我的测试项目中并且一切正常!



请注意,在这种情况下,建议启用gRPC日志记录。 `(例如:GrpcEnvironment.SetLogger(新的ConsoleLogger()),你可能会看到是否有加载多个DLL的问题......


I'm trying to connect to the Google Datastore on my account with service account credentials file (which I've created according to the documentation), but I'm encountering with authentication error while trying to insert an entity:

Grpc.Core.RpcException: Status(StatusCode=Unauthenticated, Detail="Exception occured in metadata credentials plugin.")

My code is:

var db = DatastoreDb.Create("myprojectid");
Entity entity = new Entity{
 Key = db.CreateKeyFactory("mykindname").CreateIncompleteKey()
};
var keys = await db.InsertAsync(new[] { entity });

The GOOGLE_APPLICATION_CREDENTIALS variable refers to the credentials file and when calling GoogleCredential.GetApplicationDefaultAsync() to see if the credentials object is valid it indeed looks good...

I saw some earlier examples which used the GetApplicationDefaultAsync function togehether with some DatastoreService object - but I couldn't find the DatastoreService object (probably it was there in old versions...) in the latest .Net API: Google.Cloud.Datastore.V1

Notice that I don't want to use the other authenticaiton methods:

1) Using the gcloud cli.

2) Running from Google environment (app engine for example).

Any idea how to solve this?

解决方案

After the great help of Jon Skeet the issue was solved.

The authentication issues can occur if you don't reference all the required Datastore dlls. Make sure that all the dlls are referenced on the project that are running the calls to the Datastore.

I've added the Google Datastore lib via the NuGet to my test project and everything worked!

Notice that in such cases it is recommended to enable gRPC logging. `(For exmaple: GrpcEnvironment.SetLogger(new ConsoleLogger()), there you'll probably see if there were issues loading several dlls...

这篇关于Google数据存储身份验证问题 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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