gax-nodejs
gax-nodejs copied to clipboard
Library fails with "this.auth.getUniverseDomain is not a function" when using pubsub
-
Is this a client library issue or a product issue? Appears to be a library issue
-
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
- 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/[email protected]
- [email protected]
- [email protected]
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/[email protected]
- [email protected]
- [email protected]
It appears the google-auth-library
is outdated, please update it to the latest version (9.10.0 or later).
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
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.
Actually, this functionality is currently available via the authClient
parameter.