From 52e3f70d6ea268b7b531ccd32a31a4fae522968e Mon Sep 17 00:00:00 2001 From: Dominika Date: Sun, 22 May 2022 03:21:38 +0200 Subject: [PATCH] + legacy login functions --- launcher/auth.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 launcher/auth.sh diff --git a/launcher/auth.sh b/launcher/auth.sh new file mode 100755 index 0000000..1fa2687 --- /dev/null +++ b/launcher/auth.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# Authenticate with Mojang's authserver +_AUTH_BASE_URL="https://authserver.mojang.com" + +function escape_json() { + sed 's/["\\]/\\&/g;s/\t/\\t/g' <<< "$1" +} + +# login(username, password) +function login() { + local mail=$(escape_json "$1") + local password=$(escape_json "$2") + + local json=' + { + "agent": { + "name": "Minecraft", + "version": 1 + }, + "username": "'"$mail"'", + "password": "'"$password"'", + "requestUser": true + }' + + curl -s \ + -H "Content-Type: application/json" \ + --data-raw "$json" \ + $_AUTH_BASE_URL/authenticate > auth.json +} + +function refresh() { + local accessToken=$(jq -r '.accessToken' < auth.json) + local clientToken=$(jq -r '.clientToken' < auth.json) + + local json=' + { + "accessToken": "'"$accessToken"'", + "clientToken": "'"$clientToken"'", + "requestUser": true + }' + + curl -s \ + -H "Content-Type: application/json" \ + --data-raw "$json" \ + $_AUTH_BASE_URL/refresh > auth.json +} + +function validate() { + local accessToken=$(jq -r '.accessToken' < auth.json) + local clientToken=$(jq -r '.clientToken' < auth.json) + + local json=' + { + "accessToken": "'"$accessToken"'", + "clientToken": "'"$clientToken"'", + "requestUser": true + }' + + local meow=$(curl -i -s \ + -H "Content-Type: application/json" \ + --data-raw "$json" \ + $_AUTH_BASE_URL/validate) + if [[ "$meow" == *"204"* ]]; then + return 0 + else + return 1 + fi +}