Run google cloud function in bubble

Hello all,

Am trying to invoke google cloud functions in bubble, however no success till now.
As google has mandated authentication now, can anyone help how do we do that please ?

Thanks

you can use express() to create api endpoints in your google cloud functions. You can then connect those endpoints in the Bubble API Connector.

const express = require("express");
const app = express();

app.post('/api/create/example', (req, res) =>{
(async () => {
    try{
        let data = req.body.data
        const result = await doSomething(data);
        return res.status(200).json({status: "SUCCESS"});
    }
    catch(error){
        functions.logger.log("Error: ", error)
        return res.status(500).send(error);
    }
})();});

exports.app = functions.https.onRequest(app)

The url will be:
https://{timezone}-{project-name}.cloudfunctions.net/app/api/create/example

Thanks much for the reply, have done both nodejs and python endpoint.

Since these requires authentication, its becomes more tricky and am unable to find a way how to authenticate gcp functions via bubble.

Any pointers here would be helpful.

Thanks

Are you talking about Authenticating a Google Service Account or authenticating a user’s google account before being able to use the API?

The steps in this video is what I used to have a user log into their google account and return back to bubble with access tokens and then you can get a Token to be used with the Authentication Bearer header.

1 Like

Thanks much, this is more towards google user login, that is something which I have.
Was referring to GCP functions ( example written in express.js) and we can’t call the same without authentication.

Am struggling how to add authentication in bubble for the same.

Sample API endpoint : https://region.cloudfunctions.net/api-name

Any help here is much appreciated

I am not understanding how you are having an issue in calling google cloud functions to run with authentication. Here is an example of how I pass an API-Key or it will respond with a 401 code and say unauthorized but that’s only because I added the code for that.


If I understand correctly, your access to API is public in Google cloud meaning set to “AllUsers” and then you are managing the authentication via code.

image

I recently had this question so will share what I’ve learned in case it benefits anyone. For triggering a cloud function via the bubble api connector, it requires an ID token for an ‘audience’ (which seems to just be your function endpoint) and optionally a specific service account. This documentation shows how to generate the required token in a number of different ways. This token then goes in your Authorization header as Bearer <your generated ID token>. The default service account may have broad permissions, so consider replacing the default with a more restricted service account with invoke permissions only for this function. As a disclaimer I do not consider myself a GCP expert, so I’m open to corrections/improvements

The above did not end up being suitable for my use case, so just ended up spending another day looking into this. The issue with my initial response is that the ID tokens generated in this way are short lived and expire after an hour. While it is more secure to manage the refresh of short lived tokens, this is excessive for my use case. The alternative of having a persistent API key is not available out of the box in gcloud as far as I can tell, but there is a more involved way to achieve it via a service called cloud endpoints. Following this blog post got me most of the way there but had to adapt a few items to get it to work for me - if I manage to get some time I will try to document how I implemented it.