Gitkit令牌服务API返回403“无法用客户端项目识别”错误

时间:2016-05-28 05:19:42

标签: google-identity-toolkit

我目前正在尝试使用Google Identity Toolkit令牌服务REST API(https://developers.google.com/identity/toolkit/reference/securetoken/rest/v1/token)来生成一个访问令牌,我可以在后端服务器中使用它。

当我在https://securetoken.googleapis.com/v1/token的POST请求中将“authorization_code”指定为“grant_type”并将认证后的gtoken cookie值作为“代码”时,我收到403响应,并显示以下错误消息:

{
  "error": {
    "code": 403,
    "message": "The request cannot be identified with a client project. Please pass a valid API key with the request.",
    "status": "PERMISSION_DENIED"
  }
}

我通过JWT解码器检查了gtoken值,它看起来格式正确。特别是我可以看到aud设置为我的应用程序/客户端ID。文档没有说明指定API密钥 - 通常我希望在Authorization标头中指定。所以我不确定我在这里缺少什么。

任何指向此事的指针都将不胜感激。

1 个答案:

答案 0 :(得分:0)

调用Google Identity Toolkit API(包括令牌服务API)时,需要URL中的API密钥。不过,我建议你看一下新版本的服务 - Firebase Authentication。 Firebase Auth SDK具有令牌服务API的内置支持。