aboutsummaryrefslogtreecommitdiff
path: root/bin/google-oauth2
blob: 3ef43b99f68b03ce443da804ff7084f2063ae102 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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