Google 使用服务帐户进行 Admin SDK 身份验证
Google Admin SDK authentication with service account
我的团队目前正在开发一个应用程序,使用 Admin SDK 在 GCP 中列出我公司的域用户,用于入职和离职目的。
我们正在使用服务帐户来执行此操作,并且我们已在 Google 管理员的高级设置中添加了 admin.directory.user.readonly
范围。 Admin SDK API 已激活,我们可以在凭据区域看到服务帐户。
当我们调用 https://www.googleapis.com/admin/directory/v1/users endpoint with the parameters viewType=domain_public
and domain=[our domain]
, while using an access token generated with 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 实例调用目录 APi。它有权执行的操作是在您授予它访问权限的目录 API 范围内充当您域中的用户。
获取服务帐户凭据时,您需要添加 sub=admin@yourdomain.com 参数,以便您充当域管理员,而不是服务帐户。参见:
https://developers.google.com/identity/protocols/OAuth2ServiceAccount
一些代码示例位于:
https://developers.google.com/admin-sdk/directory/v1/guides/delegation
我的团队目前正在开发一个应用程序,使用 Admin SDK 在 GCP 中列出我公司的域用户,用于入职和离职目的。
我们正在使用服务帐户来执行此操作,并且我们已在 Google 管理员的高级设置中添加了 admin.directory.user.readonly
范围。 Admin SDK API 已激活,我们可以在凭据区域看到服务帐户。
当我们调用 https://www.googleapis.com/admin/directory/v1/users endpoint with the parameters viewType=domain_public
and domain=[our domain]
, while using an access token generated with 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 实例调用目录 APi。它有权执行的操作是在您授予它访问权限的目录 API 范围内充当您域中的用户。
获取服务帐户凭据时,您需要添加 sub=admin@yourdomain.com 参数,以便您充当域管理员,而不是服务帐户。参见:
https://developers.google.com/identity/protocols/OAuth2ServiceAccount
一些代码示例位于:
https://developers.google.com/admin-sdk/directory/v1/guides/delegation