我们在使用服务帐户访问经销商 API 时遇到问题。带有客户端机密的示例运行良好,但我们需要在 k8s (Kubernetes Engine) 中部署它,而不需要定期刷新 oauth 会话(尤其是这样做一次,因为在 docker 容器中有点困难)。
虽然有很多关于如何使用 python 执行此操作的文档,但我们找不到任何使用服务帐户获取访问权限的方法。
我们尝试了两个帐户,一个是默认计算引擎,一个是直接为我们的用例创建的。两者都获得了 G Suite 中的经销商范围。
https://www.googleapis.com/auth/apps.order,
https://www.googleapis.com/auth/admin.directory.user,
https://www.googleapis.com/auth/siteverification,
"googleapi: Error 403: Authenticated user is not authorized to perform this action., insufficientPermissions"
虽然在使用时我们不断收到错误
client, err = google.DefaultClient(ctx, reseller.AppsOrderScope)
if err != nil {
log.Fatal("creating oauth client failed", zap.Error(err))
}
subs, err := client.Subscriptions.List().Do()
if err != nil {
log.Fatal("listing subscriptions failed", zap.Error(err))
}
我在 StackOverflow 上的一篇文章中读到,Reseller API 需要用户模拟,但在整个 Google 和 oauth2 和客户端 lib 存储库中搜索此内容并没有找到执行此操作的方法。Python 这样做就像端到端教程中描述的那样
credentials = ServiceAccountCredentials.from_json_keyfile_name(
JSON_PRIVATE_KEY_FILE,
OAUTH2_SCOPES).create_delegated(RESELLER_ADMIN_USER)
但是对于 Go,我找不到任何记录在案的方法。