aboutsummaryrefslogtreecommitdiff
path: root/bin/google-oauth2
diff options
context:
space:
mode:
Diffstat (limited to 'bin/google-oauth2')
-rwxr-xr-xbin/google-oauth220
1 files changed, 20 insertions, 0 deletions
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