如何使用JWT令牌调用GCP Firestore API

时间:2018-07-23 11:15:17

标签: firebase google-cloud-platform google-cloud-firestore

为了对GCP Firestore API进行身份验证调用,我创建了JWT令牌,如官方文档中所述: https://developers.google.com/identity/protocols/OAuth2ServiceAccount

基于服务帐户文件的令牌生成如下:

       String signedJwt = JWT.create()
               .withKeyId(privateKeyId)
               .withIssuer(credential.getServiceAccountId())

               .withSubject(credential.getServiceAccountId())

.withAudience(“ https://firestore.googleapis.com/firestore.projects.locations.get”)

                .withIssuedAt(new Date(now))
                .withExpiresAt(new Date(now + 3600 * 1000L))
                .sign(algorithm);

然后,我将生成的令牌添加为Bearer标头,如官方文档中所述并调用:

https://firestore.googleapis.com/v1/projects/ {my-project} / locations /

但是API调用失败,并显示以下信息:

{     “错误”:{         “代码”:401,         “ message”:“请求具有无效的身份验证凭据。预期的OAuth 2访问令牌,登录cookie或其他有效的身份验证凭据。请参见https://developers.google.com/identity/sign-in/web/devconsole-project。”         “状态”:“未经授权”     } }

我想念什么吗?

谢谢!

0 个答案:

没有答案