P粉9208354232023-08-18 19:36:09
Try something like the following, making sure domain-wide delegation is configured from your workspace account to the service account.
subject is the user on the domain you want the service account to impersonate.
let google = require('googleapis'); let privateKey = require("./privatekey.json"); var jwtClient = new google.auth.JWT({ email: privateKey.client_email, key: privateKey.private_key, scopes: ['https://www.googleapis.com/auth/calendar'], subject: 'user@domain.com' }); jwtClient.authorize(function (error, tokens) { if (error) { console.log(error); return; } else { console.log("Successfully connected!"); } });