node.js - 错误 : Service accounts cannot invite attendees without Domain-Wide Delegation of Authority

标签 node.js google-api google-oauth google-calendar-api service-accounts

我使用 JWT token 作为服务帐户的身份验证,如果我在事件中添加参与者,我会收到上述错误,我将其开发为服务,所以我可以在不使用 oauth2 授权的情况下解决这个问题吗?

  const scopes = ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/gmail.send']
    const calendar = google.calendar({ version: "v3" });

    let rawdata = fs.readFileSync('googleCalendar\\calendarcred.json');
    let CREDENTIALS = JSON.parse(rawdata);
    let auth = new google.auth.JWT(
        CREDENTIALS.client_email,
        null,
        CREDENTIALS.private_key,
        scopes
    );

最佳答案

为了在 Google 日历中使用服务帐户,您需要设置 Perform Google Workspace Domain-Wide Delegation of Authority到您的 gsuite 帐户。

工作区 (Gsutie) 管理员授权服务帐户后,您就可以运行模拟。请记住将身份验证设置为您希望服务帐户模拟的域中的用户。

import { JWT } from "google-auth-library";

  const auth = (await google.auth.getClient({
    scopes: ["https://www.googleapis.com/auth/admin.directory.user"],
  })) as JWT;

  auth.subject = process.env.GOOGLE_ADMIN_EMAIL;

或者,一旦服务帐户被授予访问域的权限,我认为您也可以与服务帐户共享日历,这应该可以直接访问日历,而无需模拟域中的用户。但是我认为它不会发送通知电子邮件。

关于node.js - 错误 : Service accounts cannot invite attendees without Domain-Wide Delegation of Authority,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67301923/

相关文章:

node.js - TCP 服务器的 GCP Compute Engine 防火墙规则

javascript - 在 PHP 中使用时间轴 Google Chart API - 日期/时间格式问题

javascript - 如何获取所有标记为已完成的 Google 日历目标和提醒

javascript - 如何使用 JavaScript 为 Google API 生成访问 token (以供将来使用)?

google-oauth - Api google adwords - oAuth2.0 的 client_secret

javascript - 是否可以限制 Node 中的异步任务?

node.js - 将 AMAZON.DURATION 添加到当前时间

javascript - 如何在 Javascript 中将 CSS 选择器转换为 XPath?

javascript - 谷歌视觉API

ios - 如何使用 Google 离线访问 token 在 iOS 后台进行身份验证?