Python wrapper for Mojang's Yggdrasil authentication service.
Project description
yggdrasil-py
Open-source Python 3.6+ wrapper by Sam Carson for the Mojang Yggdrasil authentication service. Please reference the documentation for extra information.
Install via PyPI using the following command: pip install yggdrasil-py
This wrapper is supported only for Python 3.6 and above because of the use of f-strings when an Exception
is raised. You could easily modify the code to use %s
formatting or the .format()
function, but they are not as efficient.
Minecraft 1.6 introduced a new authentication scheme called Yggdrasil which completely replaces the previous authentication system. Mojang's other game, Scrolls, uses this method of authentication as well.
Authenticate
Authenticates a user using their password.
def authenticate(username:str, password:str, agentName:str = 'Minecraft', clientToken:str = None, requestUser:str = False):
Arguments:
- String (required) Username of agent/Mojang email (if migrated)
- String (required) Password for the account used
- String (optional)
Agent, defaults to
Minecraft
, can also beScrolls
- String (optional) Client identifier, must be random and identical per request
- Boolean (optional)
If set to
True
request for user object too (default isFalse
)
Response:
- Check the Authenticate section of the documentation for details.
Example:
from yggdrasil import authenticate
import random
randomClientToken = random.randint(10000,99999)
mc = authenticate('test@example.com','p455w0rd', 'Minecraft', randomClientToken, False)
print(mc['accessToken'])
Refresh
Refreshes a valid accessToken. It can be used to keep a user logged in between gaming sessions and is preferred over storing the user's password in a file.
def refresh(accessToken:str, clientToken:str, requestUser:bool = False):
Arguments:
- String (required)
Valid
accessToken
, gained fromauthenticate()
- String (required)
Identical to the
clientToken
used to get theaccessToken
in the first place - Boolean (optional)
If set to
True
request for user object too (default isFalse
)
Response:
- Check the Refresh section of the documentation for details.
Example:
from yggdrasil import refresh
print(refresh(mc['accessToken'], randomClientToken))
# Note: invalidates inputted accessToken
Validate
Checks if an accessToken is usable for authentication with a Minecraft server.
def validate(accessToken:str, clientToken:str = None):
Arguments:
- String (required)
Valid
accessToken
, gained fromauthenticate()
- String (optional)
Identical to the
clientToken
used to get theaccessToken
in the first place
Response:
- Returns Boolean for whether
accessToken
is valid (andclientToken
match, if defined)
Example:
from yggdrasil import validate
print(validate(mc['accessToken'], randomClientToken))
Signout
Invalidates accessTokens using an account's username and password.
def signout(username:str, password:str):
Arguments:
- String (required) Username of agent/Mojang email (if migrated)
- String (required) Password for the account used
Response:
- Returns
True
unless error thrown
Example:
from yggdrasil import signout
print(signout('test@example.com','p455w0rd'))
Invalidate
Invalidates accessTokens using a client/access token pair.
def invalidate(accessToken:str, clientToken:str):
Arguments:
- String (required)
Valid
accessToken
, gained fromauthenticate()
- String (required)
Identical to the
clientToken
used to get theaccessToken
in the first place
Response:
- Returns
True
unless error thrown
Example:
from yggdrasil import invalidate
print(signout(mc['accessToken'], randomClientToken))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for yggdrasil_py-1.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1399a8f0dbde9e0f5b9f93178b6413f2a02a9ce36676e960d316372b5b66e1d |
|
MD5 | 37b20b41b4ffa6932ebe90b10123815c |
|
BLAKE2b-256 | 6904ef9fc36359c2aa762a531b1e36a684ba71952d9ebb05b93a237f20f5979b |