gpt4 book ai didi

node.js - 使用 NodeJS 实例化一个 Admin SDK 目录服务对象

转载 作者:行者123 更新时间:2023-12-05 00:47:33 25 4
gpt4 key购买 nike

按照有关如何执行 G Suite 域范围内授权的说明进行操作,请参见此处 https://developers.google.com/admin-sdk/directory/v1/guides/delegation我完成了所有步骤,但现在我坚持在我的应用程序中实现 SDK 目录服务对象,我在前端使用 Angular 7,在后端使用 NodeJs(Firebase 云函数),但此处给出的代码仅支持 Java, Python 和 Go。谁能告诉我如何将其转换为 NodeJS?

最佳答案

希望你现在已经找到了答案,但现在你去吧:

const keys = require('<Path to your privateKey.json file>');
const { JWT } = require('google-auth-library');

async function main() {
const client = new JWT({
email: keys.client_email,
key: keys.private_key,
subject: "<email address of user with admin acceess on G Suite>",
scopes: [<put your scopes here>],
});
const url = `<Your HTTP request>`;
const res = await client.request({ url });
return(res.data);
}

main().catch(console.error);

这是一个很好的例子来说明你的代码应该是什么样子:https://github.com/googleapis/google-auth-library-nodejs/blob/master/samples/jwt.js

google 的示例中唯一缺少的是主题参数。当您尝试访问只有 G Suite 管理员可以访问的 API 时,此参数是必须的,因此您需要模拟管理员帐户。

关于node.js - 使用 NodeJS 实例化一个 Admin SDK 目录服务对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56636523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com