From 960d8647437f7127a6de167b974b8f7aafc77130 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Thu, 19 Jan 2023 10:04:51 +0100 Subject: Added first few utilities --- bin/google-oauth2 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 bin/google-oauth2 (limited to 'bin/google-oauth2') diff --git a/bin/google-oauth2 b/bin/google-oauth2 new file mode 100755 index 0000000..3ef43b9 --- /dev/null +++ b/bin/google-oauth2 @@ -0,0 +1,20 @@ +#!/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 \ No newline at end of file -- cgit v1.2.3