Skip to content

Instantly share code, notes, and snippets.

@ChristianOConnor
Created January 13, 2023 20:38
Show Gist options
  • Save ChristianOConnor/e250cdda91f5a2521b23188d78c84326 to your computer and use it in GitHub Desktop.
Save ChristianOConnor/e250cdda91f5a2521b23188d78c84326 to your computer and use it in GitHub Desktop.
var express = require("express");
var app = express();
require("dotenv").config();
const GoogleAuth = require("google-auth-library").GoogleAuth;
const cors = require("cors");
app.use(
cors({ origin: process.env.ORIGIN, credentials: process.env.CREDENTIALS })
);
app.get("/hello", async function (req, res) {
const keyInJsn = JSON.parse(process.env.CREDENTIALS_STR);
const auth = new GoogleAuth({
credentials: keyInJsn,
});
const url = process.env.RUN_APP_URL;
//Create your client with an Identity token.
const client = await auth.getIdTokenClient(url);
const result = await client.request({ url });
const resData = result.data;
res.send(resData);
});
var server = app.listen(8081, function () {
var host = server.address().address;
var port = server.address().port;
console.log("Example app listening at http://localhost:", port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment