Last active
April 26, 2021 03:01
-
-
Save 3ventic/9e66dacbd8e818a32fb2338c3ce36e5e to your computer and use it in GitHub Desktop.
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 | |
# Revokes any Twitch OAuth2 token. | |
# Usage: ./revoke-twitch-token.sh | |
# The script will prompt for the token to avoid leaking a valid token | |
# to history or environment in case an error occurs while attempting to revoke. | |
command -v jq >/dev/null 2>&1 || { echo >&2 "Please install 'jq'."; exit 1; } | |
command -v curl >/dev/null 2>&1 || { echo >&2 "Please install 'curl'."; exit 1; } | |
stty -echo | |
printf "Token: " | |
read TOKEN | |
stty echo | |
echo | |
CLIENTID=`curl -s https://id.twitch.tv/oauth2/validate -H "Authorization: OAuth $TOKEN" | jq .client_id | cut -d'"' -f 2` | |
STATUS=$? | |
echo "Token belongs to client_id '$CLIENTID'" | |
if [ $STATUS -ne 0 ] | |
then | |
echo "Failed to revoke command: unable to get client_id" | |
elif [ -z $CLIENTID ] || [ $CLIENTID -eq "null" ] | |
then | |
echo "Failed to revoke command: invalid token" | |
else | |
curl -XPOST -sf -d "client_id=$CLIENTID&token=$TOKEN" https://id.twitch.tv/oauth2/revoke | |
REVOKED=$? | |
[ $REVOKED -eq 0 ] && echo "Token successfully revoked." || echo "Failed to revoke command: revocation failed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment