google-auth-library-nodejs
google-auth-library-nodejs copied to clipboard
Invoking a google cloud function from an app engine
-
What you're trying to do My app engine running a nodeJS application should be able to send a GET request to my google cloud function.
-
What code you've already tried
const url = process.env.SERVICE_ACCOUNT;
const audience = process.env.FUNCTION_GETREPORT_URI;
const { GoogleAuth } = require("google-auth-library");
const auth = new GoogleAuth();
async function getGoogleIdToken() {
try {
const client = await auth.getIdTokenClient(audience);
const res = await client.request({ url });
console.log(res.data);
return res.data;
} catch (e) {
console.log(e, "?");
return null;
}
}
const ID_TOKEN = await getGoogleIdToken();
const file = axios
.get(
`${process.env.FUNCTION_GETREPORT_URI}?start=${start}&end=${end}&brand=${projectID}`,
{
responseType: "arraybuffer",
Authorization: `Bearer ${ID_TOKEN}`,
}
)
- Any error messages you're getting I keep getting 403 forbiddens that I'm not allowed to fetch an id token for that service. I did give my app engine default service account the cloud invoker role and it's been added in the permissions tab of the function.
At this point, I'm not sure what's going on and I'm confused what the issue is.