From 1808e98450e4729dd27f1ed823b204b6058bb84c Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 9 May 2023 04:21:43 +0200 Subject: [PATCH] feat: added tokenmaker script for bash --- scripts/tokenmaker.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 scripts/tokenmaker.sh diff --git a/scripts/tokenmaker.sh b/scripts/tokenmaker.sh new file mode 100755 index 0000000..47951ae --- /dev/null +++ b/scripts/tokenmaker.sh @@ -0,0 +1,35 @@ +#!/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