Skip to content

Instantly share code, notes, and snippets.

@jmehnle
jmehnle / pre_request.js
Last active December 1, 2021 01:11 — forked from dinvlad/pre_request.js
Auto-generate Google Access and ID tokens from a Service Account key and save it in Postman
/* This script auto-generates a Google OAuth token from a Service Account key,
* and stores that token in the "access_token" variable in Postman.
*
* Prior to invoking it, set the following variables in a Postman environment:
* - "service_account_key": the contents of your service account key.
* - "scope": a space-separated list of Google API scopes, e.g.:
* "https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.metadata"
*
* Then, paste this script into the "Pre-request Script" section
* of a Postman request or collection.