Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lucasvickers opened this issue Apr 25, 2024 · 3 comments
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@lucasvickers
Copy link

lucasvickers commented Apr 25, 2024

  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:

  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:

  • @google-cloud/pubsub@4.3.3
  • google-auth-library@9.9.0
  • google-gax@4.3.2

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:

  • @google-cloud/pubsub@3.6.0
  • google-auth-library@9.1.0
  • google-gax@4.0.4
@lucasvickers lucasvickers added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Apr 25, 2024
@danielbankhead
Copy link
Member

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

@danielbankhead danielbankhead self-assigned this Jun 4, 2024
@siketyan
Copy link

siketyan commented Jun 5, 2024

Still experiencing the same issue with google-auth-library@9.10.0.

└─┬ 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

@danielbankhead
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants