Nodejs-pubsub: Very confused, need to authenticate via App, not environment

Created on 20 Sep 2019  路  5Comments  路  Source: googleapis/nodejs-pubsub

I would like to authenticate my server within the start of Node application which receives messages from Pub/Sub. None of these samples includes the authentication part for Pub/Sub client which receives messages.

In example. How can I add authentication in this file: samples/topics.js

Every single example assumes that everyone uses environment variables. I can get the script work fine if environment variables is set, but reading auth data from JSON is yet unknown. I found out some google-auth-library that creates a JWT client, but for turn of JWT it does not include a single example how to use any of Cloud features with authenticated JWT.

Can somebody help? The documents are kinda confusing when there's tons of redirects on different pages so I cannot find combination for app based auth and usage of Pub/Sub.

pubsub question

Most helpful comment

@MPNull would providing a credentials object in the client config work for you?

const {PubSub} = require('@google-cloud/pubsub');
const pubsub = new PubSub({
  credentials: {
    client_email: '[email protected]',
    private_key: '...'
  }
});

All 5 comments

@MPNull would providing a credentials object in the client config work for you?

const {PubSub} = require('@google-cloud/pubsub');
const pubsub = new PubSub({
  credentials: {
    client_email: '[email protected]',
    private_key: '...'
  }
});

I do believe it works. I'll test it as soon as I get back on PC.

馃憢 @MPNull just a gentle ping, wanted to check in and see if the posted solution worked out for you or not!

I do believe that's it. I have problems to authenticate on Android (Java) so I actually moved to HTTP API instead so I were too bored to rewrite this on server. Can be closed.

Cool, thanks!

Was this page helpful?
0 / 5 - 0 ratings