我的团队目前正在开发一个应用程序,以使用 Admin SDK 在 GCP 中列出我公司的域用户,以实现入职和离职目的。
我们使用服务帐户来执行此操作,并且我们已经添加了admin.directory.user.readonly
范围,在 Google 管理员的高级设置中。 Admin SDK API 已激活,我们可以在 Credentials 区域中看到服务帐户。
当我们调用https://www.googleapis.com/admin/directory/v1/users带有参数的端点viewType=domain_public
and domain=[our domain]
,同时使用生成的访问令牌oauth2l,我们收到以下消息:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Not Authorized to access this resource/api"
}
],
"code": 403,
"message": "Not Authorized to access this resource/api"
}
}
是否存在我们没有预见到的任何域限制?
该服务帐户无权为您的 G Suite 实例调用 Directory APi。它有权执行的操作是在您授予其访问权限的 Directory API 范围的上下文中充当您域中的用户。
获取服务帐户凭据时,您需要添加[电子邮件受保护]参数,以便您充当域管理员,而不是服务帐户。看:
https://developers.google.com/identity/protocols/OAuth2ServiceAccount
以及一些代码示例:
https://developers.google.com/admin-sdk/directory/v1/guides/delegation
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)