dolor.yggdrasil¶
Code for interfacing with Mojang’s Yggdrasil API.
- class AuthenticationToken(*, access_token=None, client_token=None, username=None, password=None)[source]¶
Bases:
objectAn abstraction over the Yggdrasil API.
- Parameters
access_token (
str, optional) – The client’s access token.client_token (
str, optional) – The client’s client token. Must be present ifaccess_tokenis specified.username (
str, optional) – The client’s username.password (
str, optional) – The client’s password. Must be present ifusernameis specified.
- auth_server = 'https://authserver.mojang.com'¶
- headers = {'content-type': 'application/json'}¶
- agent = {'name': 'Minecraft', 'version': 1}¶
- class Profile(name, id)[source]¶
Bases:
objectRepresents the profile of an
AuthenticationToken.- property uuid¶
A
uuid.UUIDrepresentation of the profile’s id.
- async ensure(*, try_validate=False)[source]¶
Ensures that the authentication token is authenticated.
If
usernameis populated, thenauthenticate()will be run. Else, iftry_validateisTrue, then it will see if the authentication token is valid by runningvalidate(). If it’s not valid ortry_validateisFalse, thenrefresh()will be called.- Parameters
try_validate (
bool) – Whether to try to validate before refreshing the token.
- async validate()[source]¶
Checks whether the authentication token is valid.
Requires the
access_tokenattribute to be populated.- Returns
Whether the authentication token is valid.
- Return type
bool
- async refresh()[source]¶
Refreshes the authentication token.
Requires the
access_tokenattribute to be populated.Populates the
profileattribute.
- async authenticate(invalidate_prev=False)[source]¶
Authenticates the authentication token.
Requires the
usernameattribute to be populated.Populates the
profileattribute.- Parameters
invalidate_prev (
bool) – Whether or not to invalidate previous access tokens.
- async signout()[source]¶
Invalidates previous access tokens by using the username and password.
Requires the
usernameattribute to be populated.
- async invalidate()[source]¶
Invalidates previous access tokens by using the access and client tokens.
Requires the
access_tokenattribute to be populated.
- async make_request(endpoint, data, ok_status_code=200)[source]¶
A general function for making a request to the Yggdrasil API.
- Parameters
endpoint (
str) – The endpoint to make the request to.data (
dict) – The data to send.ok_status_code (
int, optional) – The status code to expect. Any other will result in anYggdrasilError.
- Returns
The data received from the Yggdrasil API.
Noneis returned if anaiohttp.ContentTypeErroris raised when getting the data.- Return type
dictorNone- Raises
YggdrasilError – If the returned status code is different than expected.