簡體   English   中英

錯誤:服務帳戶無法在沒有全域授權的情況下邀請與會者

[英]Error: Service accounts cannot invite attendees without Domain-Wide Delegation of Authority

我使用 JWT 令牌作為服務帳戶的身份驗證如果我在活動中添加參與者,我會收到上述錯誤,我將其作為服務開發,所以我可以在不使用 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 日歷一起使用,您需要為您的 gsuite 帳戶設置執行 Google Workspace 域范圍內的授權

工作區 (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;

或者,一旦服務帳戶被授予對域的訪問權限,我認為您也可以與服務帳戶共享日歷,這應該使其可以直接訪問日歷,而無需模擬域上的用戶。 但是我認為它不會發送通知電子郵件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM