Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system for handling minecraft authentication #129

Merged
merged 12 commits into from Aug 6, 2023
Merged

Add system for handling minecraft authentication #129

merged 12 commits into from Aug 6, 2023

Conversation

ItsDrike
Copy link
Member

@ItsDrike ItsDrike commented Jun 14, 2023

This adds a full implementation of authentication using the Yggdrasil system (for non-migrated accounts, i.e. non-Microsoft accounts), and an implementation for handling Microsoft accounts.

Why should this be in mcproto?

Any online minecraft server requires players going through login to contact a minecraft API, verifying that the connecting account is "official" (as opposed to "warez"). After which you establish an encrypted communication with the server.

Not supporting authentication would therefore mean that mcproto would be limited to just offline servers (that is, for the actual logging in, obviously status requesting will still work). That clearly isn't ideal, and so mcproto should have support for players to authenticate with their official minecraft accounts, when connecting to online servers.

Requirements for Microsoft auth

The microsoft authorization requires anyone using it to first create a Microsoft Azure application, and then go to Authentication tab of the create app, and set Allow public client flows to Yes. We then use the Application (client) ID of this application during the OAuth2 flow.

Not only that, Minecraft recently limited access to their https://api.minecraftservices.com API, which means you will have to go through a form to request access to the API for your client: https://help.minecraft.net/hc/en-us/articles/16254801392141.

Obtaining approved Client ID to test with

Unfortunately, mcproto isn't a full launcher, or a similar project that's distributed to people as a simple binary which could contain a client ID. Mcproto is a library, and as such, the individual projects using it should be responsible for applying for this API access. Registering a single Client ID belonging to mcproto doesn't make sense here, as it would essentially just be placed in plain text to our code-base, allowing people to use the API however they wish, or even very easily edit the python code of this library.

I have submitted this form, and I was actually able to get my Client ID approved by Minecraft. That said, this ID is purely for my personal testing and potentially for testing done in the CI. I will not share this ID with anyone, except perhaps mcproto maintainers, who would need it for further development. As a user of this library, you will need to get your own Client ID approved for your specific project, and use it with mcproto afterwards.

Testing of these implementations

The Yggdrasil system is currently untested, as I don't have any non-migrated accounts available to test it with. I have followed the wiki.vg documentation on it, which does explain the entire process pretty well, but nevertheless, it's important to mention that this system was not actually tested.

The Microsoft OAuth2 system is fully tested and works as expected.

Notes

This PR also mentions the lack of synchronous alternatives for these newly added methods, so it resolves #128

@ItsDrike ItsDrike added p: 2 - normal Normal priority t: feature New request or feature a: API Related to exposed core API of the project labels Jun 14, 2023
mcproto/auth/account.py Outdated Show resolved Hide resolved
This adds support for minecraft authentication utilizing the Mojang
authserver (API). This system does not yet include any way to actually
authenticate, only to manage the already authenticated account.

This system is technically a part of the "Yggdrasil" system, however the
regular Yggdrasil authentication (using plaintext username and password)
is not currently a part of this.

This commit also adds httpx as a dependency, as it's used to make the
necessary HTTP requests.
This adds an implementation of the "Yggdrasil" system for
authentication, whcih uses plaintext username/email and password to
obtain the access token (Bearer), which can then be used to interract
with the mojang API.

The Yggdrasil system only supports unmigrated (non-Microsoft) accounts.
Migrated accounts will not be able to login with it.

WARNING: This system is entirely based on the wiki.vg documentation, and
it has NOT actually been tested. This is because I don't have access to
any non-migrated minecraft accounts, and so I don't have any viable
accounts to test this implementation with. However the wiki.vg
documentation is quite good and covers how the system work in great
detail, so this *should* work fine.
The original structure used an `Account` class that contained
interactions for both the yggdrasil system and the new xbox live
(microsoft) system.

This change isolates these into their own files, with each system having
their own Account class, being a subclass of a new base `Account` class.
Following issue #128, this explains the lack of synchronous alternatives
to the new API calls.

This issue established, that while the low level interactions will
provide support for both sync and async, any non-related functionalities
that potentially could use an async version will only have an async
version, lowering the burden of maintaining these.
@ItsDrike ItsDrike force-pushed the auth branch 3 times, most recently from 4adf12e to 9b44772 Compare August 6, 2023 10:32
@ItsDrike ItsDrike marked this pull request as ready for review August 6, 2023 10:43
@ItsDrike ItsDrike merged commit 9e2e38c into main Aug 6, 2023
10 of 12 checks passed
@ItsDrike ItsDrike deleted the auth branch August 6, 2023 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: API Related to exposed core API of the project p: 2 - normal Normal priority t: feature New request or feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drop synchronous counterparts?
1 participant