Last active
August 26, 2021 09:21
-
-
Save jason-dark/d53cbfcac26aa937b2d9798f85790663 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { google } = require('googleapis'); | |
const privatekey = require('./private-key.json'); // This was downloaded when you created your Service Account Key | |
const scopes = ['https://www.googleapis.com/auth/gmail.settings.basic']; | |
const auth = async (user) => { | |
try { | |
const jwtClient = new google.auth.JWT( | |
privatekey.client_email, | |
null, | |
privatekey.private_key, | |
scopes, | |
user // User who will be impersonated with this JWT client | |
); | |
await jwtClient.authorize(); | |
return jwtClient; | |
} catch (err) { | |
return err; | |
} | |
} | |
// Users who will be impersonated | |
const users = [ | |
'user1@email.com', | |
'user2@email.com', | |
'user3@emai.com' | |
]; | |
for (const user of users) { | |
auth(user).then((jwtClient) => { | |
// make request with JWT Client | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment