googleapis / google-auth-library-nodejs

🔑 Google Auth Library for Node.js
Apache License 2.0
1.73k stars 383 forks source link

GoogleAuth cannot be used with googleapis: Google Service Account Auth #1852

Closed mster429 closed 3 months ago

mster429 commented 3 months ago

I faced same issue recently with google calender api (freebusy) when I try to authenticate with google service account.

const auth = new GoogleAuth({
      scopes: ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly'],
      keyFile: './src/serviceaccount.json'
    });
const client = await auth.getClient();
const calendar = google.calendar({ version: 'v3', auth: client });

npm ls google-auth-library output is as follows

image

Any help is appreciated. Thanks

Exact Error Message: No overload matches this call. Overload 1 of 2, '(version: "v3"): Calendar', gave the following error. Argument of type '{ version: string; auth: JSONClient | Compute; }' is not assignable to parameter of type '"v3"'. Overload 2 of 2, '(options: Options): Calendar', gave the following error. Type 'JSONClient | Compute' is not assignable to type 'string | BaseExternalAccountClient | OAuth2Client | GoogleAuth<JSONClient> | undefined'. Type 'ExternalAccountAuthorizedUserClient' is not assignable to type 'string | BaseExternalAccountClient | OAuth2Client | GoogleAuth<JSONClient> | undefined'. Type 'ExternalAccountAuthorizedUserClient' is missing the following properties from type 'OAuth2Client': certificateCache, certificateExpiry, certificateCacheFormat, refreshTokenPromises, and 27 more.

danielbankhead commented 3 months ago

Hey @mster429, you can pass the GoogleAuth instance directly to google.calendar’s auth parameter; no need for the getClient call.