# Integrating Google Cloud / PubSub into Auth0 an Hook

**URL:** <https://community.auth0.com/t/integrating-google-cloud-pubsub-into-auth0-an-hook/24516>\
**Category:** Get Help\
**Tags:** google, hooks\
**Created:** [April 27, 2019, 12:30am UTC](https://community.auth0.com/t/integrating-google-cloud-pubsub-into-auth0-an-hook/24516 "2019-04-27T00:30:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kideq](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kideq/32/12737_2.png) [@kideq](https://community.auth0.com/u/kideq)\
**Post date:** [April 27, 2019, 12:30am UTC](https://community.auth0.com/t/integrating-google-cloud-pubsub-into-auth0-an-hook/24516/1 "2019-04-27T00:30:11Z")

</div>

I’m having trouble getting Google Cloud to work in a [Auth0.com](http://Auth0.com) Hook. I would simply like to connect to our Google Cloud Pub/Sub and publish a message. But I’m running into trouble when trying to specify PubSub Credentials. I see that in Auth0 hooks we can use Key/Value “Secrets” but Google Pub/Sub requires that we either set an Environment variable to the path of the service\_account file, or manually specify the path to a service\_account file.

const pubsub = new PubSub({  
projectId: ‘your-project-id’,  
keyFilename: ‘/path/to/keyfile.json’  
});

---

<div class="post-metadata">

**Author:** ![kideq](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kideq/32/12737_2.png) [@kideq](https://community.auth0.com/u/kideq)\
**Post date:** [April 27, 2019, 5:26pm UTC](https://community.auth0.com/t/integrating-google-cloud-pubsub-into-auth0-an-hook/24516/3 "2019-04-27T17:26:29Z")

</div>

For anybody having a similar issues (there is no straight forward documentation on this topic that I could find) I encountered 2 solutions:

1----- Instead of using KeyFilename in the google pubsub constructor, use credentials to embed credentials directly. (thx B)

```
var pubsub = new PubSub({
  projectId: 'my-project-id',
  credentials: {
    private_key: secrets.private_key.replace(/\\n/g, '\n'),
    client_email: secrets.client_email
  }
});

```

Be sure to use `replace` to revise the key, because I noticed somewhere in the hook process the key gets corrupted.

2---- Or Send a request to another server that handles the main parts of the process your building.

```
var request = require('request'); 

 request({ 
   method: 'POST', 
  url: '[HTTPS://to_URL](https://to_url/);', 
   headers: { 
    'Content-Type': 'application/x-www-form-urlencoded'
  }, 
  body: { 
    "SomeData": "payload"} 
  }, 
  function(error, response, body) { 
    console.log(user);
    console.log(context);
    cb(error, response) 
});

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [April 29, 2019, 7:19am UTC](https://community.auth0.com/t/integrating-google-cloud-pubsub-into-auth0-an-hook/24516/4 "2019-04-29T07:19:01Z")

</div>

Thanks a lot for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 14, 2019, 7:19am UTC](https://community.auth0.com/t/integrating-google-cloud-pubsub-into-auth0-an-hook/24516/5 "2019-05-14T07:19:01Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
