dolor.yggdrasil

Code for interfacing with Mojang’s Yggdrasil API.

exception YggdrasilError(status, info)[source]

Bases: Exception

An error from the Yggdrasil API.

class AuthenticationToken(*, access_token=None, client_token=None, username=None, password=None)[source]

Bases: object

An 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 if access_token is specified.

  • username (str, optional) – The client’s username.

  • password (str, optional) – The client’s password. Must be present if username is specified.

profile

The authentication token’s associated profile.

Type

Profile or None

auth_server = 'https://authserver.mojang.com'
headers = {'content-type': 'application/json'}
agent = {'name': 'Minecraft', 'version': 1}
class Profile(name, id)[source]

Bases: object

Represents the profile of an AuthenticationToken.

property uuid

A uuid.UUID representation of the profile’s id.

async ensure(*, try_validate=False)[source]

Ensures that the authentication token is authenticated.

If username is populated, then authenticate() will be run. Else, if try_validate is True, then it will see if the authentication token is valid by running validate(). If it’s not valid or try_validate is False, then refresh() 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_token attribute to be populated.

Returns

Whether the authentication token is valid.

Return type

bool

async refresh()[source]

Refreshes the authentication token.

Requires the access_token attribute to be populated.

Populates the profile attribute.

async authenticate(invalidate_prev=False)[source]

Authenticates the authentication token.

Requires the username attribute to be populated.

Populates the profile attribute.

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 username attribute to be populated.

async invalidate()[source]

Invalidates previous access tokens by using the access and client tokens.

Requires the access_token attribute 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 an YggdrasilError.

Returns

The data received from the Yggdrasil API. None is returned if an aiohttp.ContentTypeError is raised when getting the data.

Return type

dict or None

Raises

YggdrasilError – If the returned status code is different than expected.