Skip to content

Instantly share code, notes, and snippets.

@air
Last active June 17, 2022 02:19
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save air/01dc784a18b8c1c9dbcb9514b38c04ee to your computer and use it in GitHub Desktop.
Save air/01dc784a18b8c1c9dbcb9514b38c04ee to your computer and use it in GitHub Desktop.
Let's use the Realms API to download our world backup!
#!/bin/bash
# you need httpie (apt-get install httpie)
# you need to replace <these things> with your details
# run with 'source' to export vars to your shell for experimentation
# 1. authenticate to get an access token
auth_server=https://authserver.mojang.com
user=<your login email>
password=<your account password>
client_token=any-constant-string
# log in
response=$(http POST ${auth_server}/authenticate username=${user} password=${password} clientToken=${client_token} agent:='{"name": "Minecraft", "version": 1}')
# strip double quotes
access_token=$(echo ${response} | jq .accessToken | sed 's/"//g')
# 2. Utility: validate an access token is still valid
# http POST ${auth_server}/validate accessToken=${access_token} clientToken=${client_token}
# 3. Utility: refresh the token, getting a new accessToken without having to give password
# http POST ${auth_server}/refresh accessToken=${access_token} clientToken=${client_token}
# 4. access Realms!
# server. Note the real Minecraft client uses pc.realms.minecraft.net
realms_server=https://pc.realms.minecraft.net
# your UUID from https://mcuuid.net, I believe the trimmed version is correct
uuid=<your trimmed UUID>
# your username, e.g. notch
user_id=<your username>
# Minecraft version
version=1.11.2
# is this user allowed to access Realms? see http://wiki.vg/Realms_API
http --verbose GET ${realms_server}/mco/available "Cookie:sid=token:${access_token}:${uuid};user=${user_id};version=${version}"
@WillemvdPijl
Copy link

This is for java edition right? It's a shame that bedrock doesn't provide an api. I would love to make an automatic task for mcpe_viz

@air
Copy link
Author

air commented Oct 22, 2019

Yep Java edition. The final scripts are in my minecraft-tools repo. The API must be around, just not documented - maybe you could network sniff it?

@NCarlsonMVP
Copy link

Can we use this in any way for Bedrock?
https://wiki.vg/Realms_API

My friends and I were looking into creating a discord bot specifically for bedrock realms, but I'm not sure that is possible :/

@MikkelIJ
Copy link

can you clarify how the "client token" works ?

@air
Copy link
Author

air commented Feb 11, 2020

can you clarify how the "client token" works ?

The value doesn't matter functionally, but it has to be there as I remember. You can set it as you like and keep it consistent for a client.
The best ref I can find is https://github.com/Chris54721/OpenMCAuthenticator#client-tokens

Example of how I set it, https://github.com/air/minecraft-tools/blob/master/login.sh#L16

@MikkelIJ
Copy link

MikkelIJ commented Feb 12, 2020 via email

@beneshed
Copy link

Does anyone else get dns issues?

@air
Copy link
Author

air commented Jun 25, 2020

Yep looks like the host mcoapi.minecraft.net no longer exists! We need to find where the auth server is these days.

@air
Copy link
Author

air commented Nov 12, 2020

This is now fixed, thanks to Brian McCullom who located the new server at pc.realms.minecraft.net.

@a-couple-objects
Copy link

Tried to translate this to python, got 403 forbidden?

username = input('starting first time setup\nenter your username:')
email = input('enter your mojang account email (this information is only sent to mojang, i never see it)\n')
password = input('enter your mojang account password\n')
clientauth = input('enter a client token (this is like a password, treat\nit like one, preferably \nno spaces or special characters)\n')
response = requests.post(url='https://authserver.mojang.com/authenticate', cookies={'username': username, 'password': password, 'clientToken': clientauth, 'agent': '{"name": "Minecraft", "version": 1}'})
print(response)

@air
Copy link
Author

air commented Apr 16, 2021

Tried to translate this to python, got 403 forbidden?

One observation, the POST to authserver (line 15 in my gist) doesn't use cookies (like you're doing). I think it's just URL params. Only the GET to Realms uses cookies.

@Plagiatus
Copy link

For those who may want to know, bedrock's endpoint is: https://bedrock.realms.minecraft.net/

Are you sure? I'm getting an ENOTFOUND Error when I try to use that. pocket.realms.minecraft.net however does at least return my requests, so I'd expect this one to be the correct endpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment