Search code examples
pythonminecraftheadless-browsermicrosoft-account

Authenticating a Minecraft Microsoft account with Python


What even am I doing

So, as Minecraft Java has been slowly switching over to using Microsoft based accounts instead of solely Mojang accounts, I have been trying to put together an authentication method for a small launcher project I've been working on.

The First Issue.

I've been following a piece of documentation here, which had instructions on what GET and POST requests to send to which URLs, and how to parse them, etc. It's worked pretty well, except for The First Issue.

It was a dark and stormy night, and the Microsoft Authentication URL used Javascript for redirects, so the Requests library I was using in Python could not follow the redirects. There might be a way to parse the HTML content and find the redirections or something, but that is way above my head, because I am still new to even Python.

So I looked around for a solution that would let me follow the JavaScript redirects, and the best solution (in concept) looked to be using a headless browser. This led me down a long path until I came face to face with The Second Issue.

The Second Issue.

I looked around for a headless browser that I could use, and I found a couple:

  • Selenium, or
  • PyQT WebEngine or WebKit (I know there are lots of others but I chose these and used them for examples)

From here, the issue isn't so much an issue to fix, but the issue of I don't know what I'm doing.

I looked into Selenium, and it looked promising, but the fact that I had to download a WebDriver confused me in terms of how I would package that, since this is going to be used for a distributed application.

I then looked into PyQT WebEngine, and it just confused me in all respects, so basically I just need some info on maybe how to use it. I also don't need to have to use PyQT to launch a window, or design my UI, or anything else. I already am planning to use Kivy for the GUI. I just need a headless browser or some other solution to follow Javascript redirects when sending a POST request to a certain URL.

So,

From here I just want to ask advice on which route I should take, since there seems to be a broad amount of options I could use. I've already mentioned what I need, so any advice on how or what I should use, in terms of headless browsers, libraries, etc.

Also if anyone has any other suggestions for how to authenticate a Microsoft account, please let me know.

I'm almost done

If there is anything I could answer or clarify, just let me know. I will highly appreciate all advice or suggestions.

Thanks, Pyrotex7


Solution

  • Well to resolve this - I just went with PyQt in the end after messing around for a while.