googleapis / google-auth-library-nodejs

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

Type definitions in google-auth-library >= 9.5.0 incompatible with client libraries #1768

Closed AlexLloyd0 closed 6 months ago

AlexLloyd0 commented 6 months ago

Workaround

Use an older version of google-auth-library: "google-auth-library": "^9.4.2 <9.5.0",

Bug report

Environment details

Steps to reproduce

  1. Add "@google-cloud/storage": "^7.7.0","google-auth-library": ">=9.5.0" to package.json
  2. Yarn install
  3. See type error when building code
  const auth = new GoogleAuth({});

  const client = await auth.getClient();

  const targetServiceAccount =
    'TARGET-SERVICE-ACCOUNT@YOUR-PROJECT.iam.gserviceaccount.com';
  const impersonated = new Impersonated({
    sourceClient: client,
    targetPrincipal: targetServiceAccount,
    lifetime: 3600, // Token lifetime in seconds
    targetScopes: ['https://www.googleapis.com/auth/devstorage.read_write'],
  });

  return new Storage({
    projectId: 'YOUR-PROJECT-ID',
    authClient: impersonated,
  });
       libs/core-services/src/CloudStorageService.ts:36:5 - error TS2322: Type 'Impersonated' is not assignable to type 'AuthClient | GoogleAuth<JSONClient> | undefined'.
         Type 'Impersonated' is not assignable to type 'AuthClient'.
           Property 'addSharedMetadataHeaders' is protected but type 'AuthClient' is not a class derived from 'AuthClient'.

         34 |   return new Storage({
         35 |     projectId: 'YOUR-PROJECT-ID',
       > 36 |     authClient: impersonated,
            |     ^
         37 |   });
         38 | };
         39 | 

       Found 1 error.
ddelgrosso1 commented 6 months ago

Moving this issue from cloud-node to auth as it seems auth related.

danielbankhead commented 6 months ago

@AlexLloyd0 That's fascinating, do you mind sharing the output of npm ls google-auth-library? Additionally does removing node_modules and the package lock make any difference (rm -rf node_modules/ package-lock.json in the package's root directory)?

AlexLloyd0 commented 6 months ago

Hi @danielbankhead, thanks for the reply. I can't actually repro this any more - I should have recorded the exact package versions and hashes.