nodejs-pubsub
nodejs-pubsub copied to clipboard
Issue with PubSub client using provided JWTAccess
JWTAccess
clients not used with pubsub
The following snippet constructs a jwtaccess token client and then tries to apply that as an authClient
to pubsub
const {GoogleAuth, JWTAccess, OAuth2Client} = require('google-auth-library');
const {PubSub} = require('@google-cloud/pubsub');
key = require("/path/to/svc_account.json");
const projectId = yourproject';
const aud = "https://pubsub.googleapis.com/google.pubsub.v1.Publisher";
const jwtClient = new JWTAccess();
jwtClient.fromJSON(key);
const md = jwtClient.getRequestHeaders(aud);
console.log(md);
const pubsub = new PubSub({
projectId: projectId,
authClient: jwtClient,
});
pubsub.getTopics((err, topic) => {
if (err) {
console.log(err);
return;
}
topic.forEach(function(entry) {
console.log(entry.name);
});
});
however, it seems the provided client is ignored. the error thrown:
}
Error: 16 UNAUTHENTICATED: Failed to retrieve auth metadata with error: getHeaders.then is not a function
at Object.callErrorFromStatus (/jwt_access_token/node/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
at Object.onReceiveStatus (/jwt_access_token/node/node_modules/@grpc/grpc-js/build/src/client.js:180:52)
at Object.onReceiveStatus (/jwt_access_token/node/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:365:141)
at Object.onReceiveStatus (/jwt_access_token/node/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:328:181)
at /jwt_access_token/node/node_modules/@grpc/grpc-js/build/src/call-stream.js:187:78
at processTicksAndRejections (node:internal/process/task_queues:78:11) {
code: 16,
details: 'Failed to retrieve auth metadata with error: getHeaders.then is not a function',
metadata: Metadata { internalRepr: Map(0) {}, options: {} },
note: 'Exception occurred in retry method that was not classified as transient'
}
i maynot be specifying the client correctly but i think you should be able to set an authClient
:
new PubSub(options?: ClientConfig): PubSub
--> constructor(options?: ClientConfig);
-->
export interface ClientConfig extends gax.GrpcClientOptions {
apiEndpoint?: string;
servicePath?: string;
port?: string | number;
sslCreds?: gax.grpc.ChannelCredentials;}
-->
export interface GrpcClientOptions extends GoogleAuthOptions {
auth?: GoogleAuth;
grpc?: GrpcModule;
}
-->
export interface GoogleAuthOptions<T extends AuthClient = JSONClient> {
/**
* An `AuthClient` to use
*/
authClient?: T;
using
- "@google-cloud/pubsub": "^2.19.0",
- "google-auth-library": "^7.14.1",