The authentication module contains functions and classes to facilitate interfacing with Mojang’s Yggdrasil authentication service.

Logging In

The most common use for this module in the context of a client will be to log in to a Minecraft account. The first step to doing this is creating an instance of the AuthenticationToken class after which you may use the authenticate method with the user’s username and password in order to make the AuthenticationToken valid.

class minecraft.authentication.AuthenticationToken(username=None, access_token=None, client_token=None)[source]

Represents an authentication token.


Constructs an AuthenticationToken based on access_token and client_token.

access_token - An str object containing the access_token. client_token - An str object containing the client_token.
A AuthenticationToken with access_token and client_token set.
authenticate(username, password)[source]

Authenticates the user against using username and password parameters.

username - An str object with the username (unmigrated accounts)
or email address for a Mojang account.

password - An str object with the password.

Returns True if successful. Otherwise it will raise an exception.

Upon success, the function returns True, on failure a YggdrasilError is raised. This happens, for example if an incorrect username/password is provided or the web request failed.

exception minecraft.authentication.YggdrasilError(message=None, status_code=None, yggdrasil_error=None, yggdrasil_message=None, yggdrasil_cause=None)[source]

Base Exception for the Yggdrasil authentication service.

status_code = None

int or None. The associated HTTP status code. May be set.

yggdrasil_cause = None

str or None. The “cause” field of the Yggdrasil response: a string containing additional information about the error. May be set.

yggdrasil_error = None

str or None. The “error” field of the Yggdrasil response: a short description such as “Method Not Allowed” or “ForbiddenOperationException”. May be set.

yggdrasil_message = None

str or None. The “errorMessage” field of the Yggdrasil response: a longer description such as “Invalid credentials. Invalid username or password.”. May be set.

Arbitary Requests

You may make any arbitary request to the Yggdrasil service with the _make_request method passing in the AUTH_SERVER as the server parameter.

minecraft.authentication.AUTH_SERVER = ''

The base url for Ygdrassil requests

minecraft.authentication._make_request(server, endpoint, data)[source]

Fires a POST with json-packed data to the given endpoint and returns response.

endpoint - An str object with the endpoint, e.g. “authenticate” data - A dict containing the payload data.
A requests.Request object.

Example Usage

An example of making an arbitary request can be seen here:

payload = {'username': username,
           'password': password}

authentication._make_request(authentication.AUTH_SERVER, "signout", payload)