Skip to content

Instantly share code, notes, and snippets.

@danbars
danbars / index.js
Last active March 17, 2024 09:36
Generate Google access token for service-account in Cloudflare workers environment
/**
You can use the code below in Cloudfalre worker environment to generate a Google access token
for a service-account.
Run this code in a worker cron so you always have a fresh token in your KV that can be used by other workers.
The generated token here will be valid for 3600 seconds, but you can change that in your code.
The code assumes that you have a KV mapped to 'PROPERTIES' in you wrangler.toml file
You must create a service-user and assign to it the roles that you need in google console.
Then take the JSON that you get and paste it below