简体   繁体   English

com.google.cloud.datastore.DatastoreException:请求缺少必需的身份验证凭据

[英]com.google.cloud.datastore.DatastoreException: Request is missing required authentication credential

I am using google app engine and google datastore.我正在使用谷歌应用引擎和谷歌数据存储。 I am using the google library我正在使用谷歌图书馆

com.google.cloud.datastore.Datastore

My sample code is:我的示例代码是:

Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
Key taskKey = datastore.newKeyFactory().setKind(entityName).newKey(id);
//populate some fields....
datastore.put(task);

I am using spring-boot and jetty as a container.我正在使用 spring-boot 和 jetty 作为容器。

On local, it is working properly and the data updated in the google datastore.在本地,它工作正常,数据在谷歌数据存储中更新。

The issue is when im deploying the app to the google-app-engine, im getting the Below exception when i get to datastore.put method.问题是当我将应用程序部署到 google-app-engine 时,当我进入 datastore.put 方法时出现 Below 异常。

com.google.cloud.datastore.DatastoreException: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.translate(HttpDatastoreRpc.java:129)
com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.commit(HttpDatastoreRpc.java:155)
com.google.cloud.datastore.DatastoreImpl$4.call(DatastoreImpl.java:485)

Note: in both, on local environment and google-app-engine, i defined the environment variable GOOGLE_APPLICATION_CREDENTIALS that point to json file with all required credentials generated by google API.注意:在本地环境和 google-app-engine 中,我都定义了环境变量 GOOGLE_APPLICATION_CREDENTIALS,它指向 json 文件,其中包含由 google API 生成的所有必需凭据。

According to the documentation for connecting to Datastore from App Engine in Java , there are several options available, so you can either go with Objectify (third party library), Datastore API or Datastore Client Library .根据Java 中从 App Engine 连接到 Datastore的文档,有几个选项可用,因此您可以使用Objectify (第三方库)、 Datastore APIDatastore Client Library

With the usage of Client Libraries, you must know that they make use of the Application Default Credentials , in such a way that, as documented, if the environment variable GOOGLE_APPLICATION_CREDENTIALS , ADC uses the default service account that App Engine provides for applications running over that service.使用客户端库时,您必须知道它们使用Application Default Credentials ,按照记录的方式,如果环境变量GOOGLE_APPLICATION_CREDENTIALS ,ADC 使用 App Engine 为运行在其上的应用程序提供的默认服务帐户服务。 So in your case, I think you should not define the environment variable, so that App Engine uses its default Service Account.因此,就您而言,我认为您不应定义环境变量,以便 App Engine 使用其默认服务帐户。

if you still struggling with com.google.cloud.datastore.DatastoreException: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.如果您仍在为com.google.cloud.datastore.DatastoreException: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. com.google.cloud.datastore.DatastoreException: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. you can set credentials explicitly, like it is shown in the example below:您可以显式设置凭据,如下例所示:

            Resource credentialsCyberpower = resourceLoader.getResource("classpath:yourservice-datastore-access.json");


            GoogleCredentials credentials = GoogleCredentials.fromStream(credentialsCyberpower.getInputStream())
                  .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
            DatastoreOptions options =
                    DatastoreOptions.newBuilder().setProjectId("XXXXXX").setCredentials(credentials).build();
            Datastore datastore = options.getService();
            ObjectifyService.init(new ObjectifyFactory(datastore));

generate yourservice-datastore-access.json in IAM service accounts.在 IAM 服务帐户中生成yourservice-datastore-access.json working with Objectify 6.0.5使用 Objectify 6.0.5

If you are using <url-stream-handler>urlfetch</url-stream-handler> with Java8 and Objectify 6 you will have to switch into native and enable billing.如果您将<url-stream-handler>urlfetch</url-stream-handler>与 Java8 和 Objectify 6 一起使用,则必须切换到native并启用计费。

I was hit by this issue recently and spend a lot of time on fixing the problem, more info can be found here我最近遇到了这个问题,花了很多时间来解决这个问题,更多信息可以在这里找到

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google IOT 核心-http 桥“请求缺少必需的身份验证凭据” - Google IOT core- http bridge "request is missing required authentication credential " iOS“请求缺少必需的身份验证凭据。需要 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据 - iOS "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential 调用 firebase.messaging.getToken() 时出现“请求缺少身份验证凭据”错误 - "Request is missing authentication credential" error when calling firebase.messaging.getToken() 谷歌云数据存储查询 - Google Cloud Datastore Query's 删除 Google Cloud Datastore 索引 - Google Cloud Datastore index removal App Engine 项目访问谷歌云存储的默认凭据? - Default credential for app engine project accessing google cloud storage? 谷歌云平台中的身份验证 - Authentication in Google Cloud Platform Google Cloud Datastore 和服务帐户:限制访问权限 - Google Cloud Datastore and service accounts: limit access permissions com.google.cloud.ServiceOptions$Builder 类型无法解析。 它是从 required.class 文件中间接引用的 - The type com.google.cloud.ServiceOptions$Builder cannot be resolved. It is indirectly referenced from required .class files Chrome 扩展程序中的 Firebase 谷歌身份验证 - 获取凭据时出错 - Firebase google authentication in Chrome Extension - Error getting credential
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM