27 lines
1.1 KiB
Bash
27 lines
1.1 KiB
Bash
|
#!/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
|