googleapis/google-auth-library-nodejs

GoogleAuth cannot be used with googleapis: Google Service Account Auth

mster429 opened this issue · 1 comments

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.

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