#!/bin/sh # # Reads client secret and client token from STDIN (slightly better than as # args, which are public), one in each line respectively. # # Calls into Google's OAuth2 API with that info to retrieve an access token, # which is output to STDOUT. # # CLIENT_ID is the only argument taken by this script. CLIENT_ID=$1 read -r CLIENT_SECRET read -r REFRESH_TOKEN curl --silent \ --data client_id=$CLIENT_ID \ --data client_secret=$CLIENT_SECRET \ --data grant_type=refresh_token \ --data refresh_token=$REFRESH_TOKEN \ 'https://www.googleapis.com/oauth2/v4/token' | jq -r .access_token