import { Auth as googleAuth } from "googleapis"; export async function authViaServiceAccount( scopes: string[], onBehalfOf: string, keyFile: string, ) { const auth = new googleAuth.JWT({ keyFile, scopes, subject: onBehalfOf, // we need to impersonate the user we want to crawl a given user email; to be able to read their emails }); await auth.authorize(); return auth; }