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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
ItsDrike
force-pushed
the
auth
branch
6 times, most recently
from
June 15, 2023 15:10
ea7c674
to
7817374
Compare
ItsDrike
force-pushed
the
auth
branch
6 times, most recently
from
June 24, 2023 19:46
aa81069
to
3f7a8dc
Compare
ItsDrike
force-pushed
the
auth
branch
3 times, most recently
from
August 5, 2023 15:55
11d03c3
to
5f83894
Compare
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
force-pushed
the
auth
branch
3 times, most recently
from
August 6, 2023 10:32
4adf12e
to
9b44772
Compare
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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