function getAuthenticatedUserOAuth2Client(scopes) {
  return new Promise((resolve, reject) => {
    // Create a client based on client secrets
    const oAuth2Client = new OAuth2Client(
      CLIENT_SECRETS.client_id,
      CLIENT_SECRETS.client_secret,
      CLIENT_SECRETS.redirect_uris[0]
    );

    // Generate the URL to use for consent
    const authorizeUrl = oAuth2Client.generateAuthUrl({
      access_type: 'offline',
      scope: scopes,
    });

    // Open an HTTP server to accept the OAuth2 callback
    const server = http.createServer(async (request, response) => {
      try {
        if (request.url.indexOf('/oauth2callback') > -1) {
          // Acquire the code and close the server.
          const queryString =
            new url.URL(request.url, 'http://localhost:3000').searchParams;
          const code = queryString.get('code');
          response.end('Done!');
          server.destroy();
          // Acquire the tokens
          const r = await oAuth2Client.getToken(code);
          // Update credentials of the OAuth2 client.
          oAuth2Client.setCredentials(r.tokens);
          resolve(oAuth2Client);
        }
      } catch (e) {
        reject(e);
      }
    }).listen(3000, () => {
      // Open default browser and start the flow
      open(authorizeUrl, {wait: false}).then(cp => cp.unref());
    });
    destroyer(server);
  });
}
Create a new OAuth2 client and go through the OAuth2 flow.

@param {!string[]} scopes Required scopes for the desired API requests
@returns {Promise<OAuth2Client>} The resulting Google OAuth2 client