Last active
August 14, 2022 08:24
-
-
Save iansedano/e0b259ab9c63ebddd22658f697026c19 to your computer and use it in GitHub Desktop.
Google OAuth flow bash script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage | |
# | |
# . get_token.sh [CLIEND_ID] [CLIENT_SECRET] [SCOPE] | |
# | |
# Script will prompt you to visit a url to get the auth code, | |
# and wait for you to provide them and then output the tokens. | |
CLIENT_ID=$1 | |
CLIENT_SECRET=$2 | |
SCOPE=$3 | |
REDIRECT_URI="urn:ietf:wg:oauth:2.0:oob" | |
AUTH_CODE_URL="https://accounts.google.com/o/oauth2/v2/auth?"` | |
`"client_id=${CLIENT_ID}&scope=${SCOPE}&response_type=code&"` | |
`"redirect_uri=${REDIRECT_URI}" | |
echo "get your auth code from: | |
${AUTH_CODE_URL} | |
" | |
read -p "Enter the authorization code:" AUTH_CODE | |
CURL_DATA="client_id=${CLIENT_ID}&"` | |
`"client_secret=${CLIENT_SECRET}&"` | |
`"code=${AUTH_CODE}&"` | |
`"redirect_uri=${REDIRECT_URI}&"` | |
`"grant_type=authorization_code" | |
printf "\n" | |
echo $CURL_DATA | |
curl --request POST --data $CURL_DATA https://oauth2.googleapis.com/token | |
printf "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment