I'm trying to create a Python script that can log into an online Minecraft server (me and my friends have one set up) and send the chat messages to our discord server.
I have no issue with the bot part and I have it working when the server is in offline mode, but when it's in online mode I need to authenticate with microsoft. I tried A ton of different ways of doing it but I settled on using the Python library minecraft_launcher_lib I've already setup Azure and have that working.
The problem comes when sending the POST request to "https://api.minecraftservices.com/authentication/login_with_xbox" to get the access token. This is the code that minecraft_launcher_lib uses to send the request to minecraft:
def authenticate_with_minecraft(userhash: str, xsts_token: str) -> MinecraftAuthenticateResponse:
"""
Authenticate with Minecraft. This function is called during :func:`complete_login`, so you need to use this function ony if :func:`complete_login` doesnt't work for you.
:param userhash: The Hash you get from :func:`authenticate_with_xbl`
:param xsts_token: The Token you get from :func:`authenticate_with_xsts`
"""
parameters = {
"identityToken": f"XBL3.0 x={userhash};{xsts_token}"
}
header = {
"Content-Type": "application/json",
"user-agent": get_user_agent(), # get_user_agent() Returns "minecraft-launcher-lib/6.0"
"Accept": "application/json"
}
r = requests.post("https://api.minecraftservices.com/authentication/login_with_xbox", json=parameters, headers=header)
print(r.json()) # this prints json returned from minecraft servers
return r.json()
My code doesn't throw an error, instead I get an error back form minecraft server:
{'path': '/authentication/login_with_xbox', 'errorMessage': 'Invalid app registration, see https://aka.ms/AppRegInfo for more information'}
The link takes me to an article on minecraft.net talking about how new programs need to register an AppID to use minecraft API.
I would like some help with how to register the AppID, because the form requests an "application ID" as well as a "Tenant ID" not sure what those should be or what a "Tenant ID" does.
I would also like some help with what the uger-agent parameter actualy does, and what the header should be when I register my new AppID.
According to this support Article, new created Azure Apps must apply for the Permission to use the Minecraft API using this form. If your App don't have the Permission api.minecraftservices.com will return a 403.
wiki:https://wiki.vg/Microsoft_Authentication_Scheme
Apply for request access URL:https://aka.ms/mce-reviewappid