我已通过 console.developers.google.com 创建了服务帐户客户端。生成的密钥、.p12 证书、启用 DwD 等等...
然后我继续在管理员中担任描述者API参考 https://developers.google.com/identity/protocols/OAuth2ServiceAccount。 (HTTP/REST 版本)。其中包括在 Google 管理 -> 安全 -> 高级设置中为这些客户端 ID 指定范围。当前管理员安全配置状态 https://i.stack.imgur.com/moV0q.png在我成功交换访问令牌的代码并请求我的域下的用户列表后,我收到了此响应。
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Not Authorized to access this resource/api"
}
],
"code": 403,
"message": "Not Authorized to access this resource/api"
}
}
请求为 GET,授权承载 ya29.ElrxA8F[acctoken 的其余部分]
谷歌开发控制台仪表板在 Admin SDK 中显示带有错误请求的图表
您必须将您的客户模拟为指定用户
所以我错过了:json auth 有效负载中的“sub”参数:
这是正确的 json 对象(当然包含您的 id 等),您需要使用它从服务帐户访问您的管理 SDK:
{
"iss":"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com",
“子”:“[电子邮件受保护] /cdn-cgi/l/email-protection",
“范围”:“googleapis.com/auth/prediction”,
“aud”:“googleapis.com/oauth2/v4/token”,
“exp”:1328554385,“iat”:1328550785
}
看一眼谷歌管理sdk参考 https://developers.google.com/identity/protocols/OAuth2ServiceAccount#authorizingrequests更多细节。 (带有“sub”参数的部分)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)