yggdrasil/scripts/tokenmaker.sh

35 lines
807 B
Bash
Executable file

#!/bin/bash
if [ "$#" -eq 2 ]; then
EMAIL="$1"
PASSWORD="$2"
else
read -r -p "username : " EMAIL
read -r -s -p "password (silent) : " PASSWORD
echo ''
fi
HEADERS="Content-Type: application/json"
PAYLOAD="{\"username\":\"$EMAIL\",\"password\":\"$PASSWORD\"}"
AUTH_TOKEN=$(curl -s -d "$PAYLOAD" -H "$HEADERS" -X POST https://authserver.mojang.com/authenticate)
if [[ -z "$AUTH_TOKEN" ]]; then
echo "[!] empty response from auth server"
exit
fi
if [[ $AUTH_TOKEN == *ForbiddenOperationException* ]]; then
echo "[!] invalid credentials"
exit
fi
if ! command -v jq &> /dev/null
then
echo "$AUTH_TOKEN"
else
ACCESSTOKEN=$(echo "$AUTH_TOKEN" | jq .accessToken)
CLIENTTOKEN=$(echo "$AUTH_TOKEN" | jq .clientToken)
echo "accessToken: $ACCESSTOKEN"
echo "clientToken: $CLIENTTOKEN"
fi