Search code examples
node.jsgoogle-cloud-platformgoogle-cloud-pubsub

Is it possible to authenticate google cloud PUB/SUB Node.js API Client with access token?


Is it possible to authenticate google cloud pub/sub nodejs client without service account using access token received with OAuth flow?

I tried before you begin section but it requires service account. Is it possible to use client library without service account?


Solution

  • For local testing, you should be able to use the gcloud command line tool to get an app default token, and then just not specify auth programmatically in your app:

    gcloud auth application-default login

    const pubsubClient = new PubSub();
    const topic = pubsubClient.topic('mytopic');
    // ...etc...
    

    Please do not use this for any sort of production environment outside of trying out code on your local machine, because it's much more likely to leak credentials and other problems. For production, you'll want to go back to the service account flow.