【发布时间】:2019-05-06 17:35:22
【问题描述】:
我们在域范围委派的服务帐户身份验证方面遇到问题。 主要问题是很难调查和调试身份验证配置,所以 我们想询问一些如何调试配置的提示。 或者,也许我们缺少一些配置选项,您可以指出它们。
我们的流程是:
- 创建启用了域范围委派的 SA(=服务帐户)。
- 在 GSuite 管理控制台 (https://support.google.com/a/answer/162106?hl=en) 中验证 SA。
- 使用凭证文件中的client_id。 (现在是电子邮件)
- 范围以逗号分隔,中间没有空格。
- 确保选中“安全性 > API 参考 > API 参考 -> '启用 API 访问'”。
对于某些 GSuite 域,这是有效的配置,但我们得到了一些域,该配置会导致:
google.auth.exceptions.RefreshError: ('unauthorized_client: 客户端未授权使用此方法检索访问令牌。', '{\n "error": "unauthorized_client",\n "error_description": "客户端未授权使用此方法检索访问令牌。"\n}')
据我们了解,这是表示未将 client_id 和范围添加到“管理 API 客户端访问”页面的错误。 (=经过身份验证的客户端列表)
我们确实确保我们请求的 GSuite 域具有正确的 client_id 和添加到经过身份验证的客户端列表中的范围 + 具有“启用 API 访问”。 我们甚至与他们一起创建了共享桌面并自己完成以完全确定这一点。 但错误仍然存在。
但是,我们无法在我们的测试 GSuite 域上复制此问题。 我们使用与客户端相同的 SA 尝试了几个选项:
- 模拟帐户没有访问资源的权限。 结果是:
googleapiclient.errors.HttpError: https://www.googleapis.com/admin/directory/v1/users?customer=my_customer&alt=json 返回“未授权访问此资源/api”>
- 范围只是部分:
google.auth.exceptions.RefreshError: ('access_denied: 请求的客户端未授权。', '{\n "error": "access_denied",\n "error_description": "请求的客户端未授权。"\n} ')
- 未选中“启用 API 访问”。
googleapiclient.errors.HttpError: https://www.googleapis.com/admin/directory/v1/users?customer=my_customer&alt=json 返回“域不能使用 api。”
- 我们从客户端收到的错误(“客户端未经授权无法使用此方法检索访问令牌。”),只有当 client_id 根本不在经过身份验证的客户端列表中时,我们才能进行复制。 但我们确信,有问题的 GSuite 域在“管理 API 客户端访问”页面中对 SA 进行了身份验证。
我们正在使用这些范围:https://www.googleapis.com/auth/userinfo.profile,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/gmail.readonly,https://www.googleapis.com/auth/plus.login,https://www.googleapis.com/auth/calendar.readonly,https://www.googleapis.com/auth/contacts.readonly, https://www.googleapis.com/auth/admin.directory.user.readonly
您对如何调试/解决此问题有任何想法吗?
【问题讨论】:
标签: google-api google-oauth service-accounts google-workspace