title: How to use Service Account to access GMAIL API for a GSuite email account
body: <p>I want my service account to impersonate one of the users in the GSuite.
  I have</p>
  <ul>
  <li>created a project via GCP</li>
  <li>enabled GMail API in the project</li>
  <li>added a service account to that project</li>
  <li>enabled the <code>domain-wide delegation</code> in the service account settings on the <code>GCP</code></li>
  <li>added an <code>API Client</code> with <code>service account id</code> in advanced settings via Google Admin panel for the <code>GSuite</code></li>
  </ul>
  <p>While going through docs (java), I saw this</p>
  <pre><code>GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream(&quot;MyProject-1234.json&quot;))
      .createScoped(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
      .createDelegated(&quot;user@example.com&quot;);
  </code></pre>
  <p>Here they are specifying which user the service account should impersonate. This code is in java. I need to accomplish the same thing in nodejs.</p>
  <p>While going through documentation of <code>nodejs-client</code> for <code>googleapis</code>, I found this:</p>
  <pre><code>const {google} = require('googleapis');
  
  const auth = new google.auth.GoogleAuth({
    keyFile: '/path/to/your-secret-key.json',
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  });
  </code></pre>
  <p>and</p>
  <pre><code>const {google} = require('googleapis');
  
  const oauth2Client = new google.auth.OAuth2(
    YOUR_CLIENT_ID,
    YOUR_CLIENT_SECRET,
    YOUR_REDIRECT_URL
  );
  
  // set auth as a global default
  google.options({
    auth: oauth2Client
  });
  </code></pre>
  <p><strong>What is the difference between <code>GoogleAuth</code> and <code>OAuth2</code> here?</strong></p>
  <p><strong>How do I set everything up so that my node.js application can access <code>user@abc.xyz</code> mail via the service account?</strong></p>
  <p><strong>How do I specify the <code>email</code> I want to access via <code>service account</code>?</strong></p>