我正在尝试使用nodejs库访问google reseller api,它有非常shi.。。我指的是零零碎碎的文档。 我尝试按照这里的示例进行操作,但在第3步失败,出现以下错误:
code: 403,
errors: [
{
domain: 'global',
reason: 'insufficientPermissions',
message: 'Authenticated user is not authorized to perform this action.'
}
]
我的配置是这样的:
const OAUTH2_SCOPES = [
"https://www.googleapis.com/auth/admin.directory.user",
"https://www.googleapis.com/auth/apps.order",
"https://www.googleapis.com/auth/siteverification",
"https://www.googleapis.com/auth/cloud-platform",
];
const authJWT = new google.auth.JWT({
keyFile: JSON_PRIVATE_KEY_FILE,
scopes: OAUTH2_SCOPES,
subject: RESELLER_ADMIN_USER,
email: "gsuite-reseller@some-cool-name-because-why-not.iam.gserviceaccount.com",
});
使用基本的谷歌fu,我发现了这个线程,这表明我的问题与冒充有关。 因此,我在subject
属性中与我的帐户email交换了电子邮件,该帐户具有指定的所有者权限。 我也给了服务帐户所有者的权利,因为在这一点上我是相当无知的。 不幸的是,这只将错误消息更改为:
status: 401,
statusText: 'Unauthorized'
有人知道哪里出了问题吗? 401提示缺少凭据。 除了服务帐户的凭据外,我是否还必须指定我的私人电子邮件凭据? 如果是,那么在哪里? 我在google.auth.jwt.options
对象上没有找到任何听起来很有希望的属性。
全域委派
所做的唯一事情是允许服务帐户代表用户主题
将引发错误参考资料: