+ legacy login functions

launcher
Dominika 2022-05-22 03:21:38 +02:00
parent b07b817ddf
commit 52e3f70d6e
1 changed files with 68 additions and 0 deletions

68
launcher/auth.sh Executable file
View File

@ -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
}