gax-nodejs icon indicating copy to clipboard operation
gax-nodejs copied to clipboard

Library fails with "this.auth.getUniverseDomain is not a function" when using pubsub

Open lucasvickers opened this issue 10 months ago • 3 comments

  1. Is this a client library issue or a product issue? Appears to be a library issue

  2. Did someone already solve this? Related to the following posts, but I'm unable to resolve:

  • https://github.com/googleapis/gax-nodejs/issues/1557
  • https://stackoverflow.com/questions/77976313/gcp-pub-sub-client-is-failing-above-version-4-0-0-with-auth-error
  1. Do you have a support contract? No

Environment details

  • OS: OS X 14.4.1
  • Node.js version: v21.7.2
  • npm version: 10.5.0
  • gax-nodejs version: 4.3.2

Steps to reproduce

I'm attempting to run the following code:

  const {PubSub} = require('@google-cloud/pubsub');
  const {OAuth2Client} = require('google-auth-library');

  token = "...";  // access_token generated externally

  const gax = new OAuth2Client();
  gax.setCredentials({access_token: token});

  const pubsub = new PubSub({
    projectId: projectId,
    auth: gax
  });

  const [topics] = await pubsub.getTopics();

With the newest versions of each library, I get the following error:

TypeError: this.auth.getUniverseDomain is not a function
    at GrpcClient.createStub (.../node_modules/google-gax/build/src/grpc.js:312:54)

Libraries:

I confirmed in my package-lock.json there are no old versions present in the dependencies. Attached for reference: package-lock.json

Following instructions on related links, I tried downgrading to various different versions, but similar errors continue. Random example:

TypeError: this.auth.getClient is not a function
    at GrpcClient._getCredentials (.../node_modules/@google-cloud/pubsub/node_modules/google-gax/build/src/grpc.js:145:40)

Libraries:

lucasvickers avatar Apr 25 '24 19:04 lucasvickers

It appears the google-auth-library is outdated, please update it to the latest version (9.10.0 or later).

danielbankhead avatar Jun 04 '24 17:06 danielbankhead

Still experiencing the same issue with [email protected].

└─┬ firebase-admin 12.1.1
  ├─┬ @google-cloud/firestore 7.7.0
  │ └─┬ google-gax 4.3.3
  │   └── google-auth-library 9.10.0
  └─┬ @google-cloud/storage 7.11.1
    └── google-auth-library 9.10.0

siketyan avatar Jun 05 '24 08:06 siketyan

I see, the auth parameter wants a GoogleAuth instance rather than an AuthClient. This should work:

import { PubSub } from "@google-cloud/pubsub";
import { GoogleAuth, OAuth2Client } from "google-auth-library";

const token = "..."; // access_token generated externally
const projectId = "..."; // optional, can often be automatically determined

const auth = new GoogleAuth({
  authClient: new OAuth2Client({
    credentials: {
      access_token: token,
    },
  }),
});

const pubsub = new PubSub({ auth, projectId });

const [topics] = await pubsub.getTopics();

Some Google libraries include support for auth: GoogleAuth | AuthClient and I think this should as well. I'll whip up a PR to add this functionality.

danielbankhead avatar Jun 05 '24 18:06 danielbankhead

Actually, this functionality is currently available via the authClient parameter.

danielbankhead avatar Aug 07 '24 19:08 danielbankhead