Skip to content

Instantly share code, notes, and snippets.

@a1batross
Last active April 4, 2023 21:20
Show Gist options
  • Save a1batross/11f3c3026aacb580305898d0c191e7de to your computer and use it in GitHub Desktop.
Save a1batross/11f3c3026aacb580305898d0c191e7de to your computer and use it in GitHub Desktop.
#!/bin/sh
SCOPES='read write follow'
if [ "$#" = "1" ]; then
RESPONSE_APP=$(curl -XPOST -F 'client_name=DoYouSuckDicks' -F "redirect_uris=urn:ietf:wg:oauth:2.0:oob" -F "scopes=$SCOPES" -F 'website=https://example.org' https://$1/api/v1/apps)
CLIENT_ID=$(echo $RESPONSE_APP | jq -r .client_id)
CLIENT_SECRET=$(echo $RESPONSE_APP | jq -r .client_secret)
echo "Client id: $CLIENT_ID"
echo "Client secret: $CLIENT_SECRET"
echo "Now open this in browser https://$1/oauth/authorize?client_id=$CLIENT_ID&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=$(echo $SCOPES | sed s/\ /+/g)"
echo "After you get the token, re-run this script: "
echo "$0 $1 $CLIENT_ID $CLIENT_SECRET <token that you received>"
elif [ "$#" = "4" ]; then
FINAL_RESPONSE=$(curl -X POST -F "client_id=$2" -F "client_secret=$3" -F 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' -F "code=$4" -F 'grant_type=authorization_code' -F "scope=$SCOPES" https://$1/oauth/token)
echo $FINAL_RESPONSE
echo "Your token is $(echo $FINAL_RESPONSE | jq -r .access_token)"
else
echo "Usage: $0 <instance_domain>"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment