Package: yggdrasil-py
yggdrasil-pyOpen-source Python 3.6+ wrapper bySam Carsonfor theMojang Yggdrasil authentication service.Please referencethe documentationfor extra information.Install via PyPI using the following command:pip install yggdrasil-pyThis wrapper is supported only for Python 3.6 and above because of the use of f-strings when anExceptionis raised. You could easily modify the code to use%sformatting or the.format()function, but they are not as efficient.Minecraft 1.6 introduced a new authentication scheme calledYggdrasilwhich completely replaces theprevious authentication system. Mojang's other game, Scrolls, uses this method of authentication as well.Since a recentpull request, support has been added for custom authentication servers. As far as I am aware, the only instance of this isely.by.AuthenticateAuthenticates a user using their password.defauthenticate(username:str,password:str,agentName:str='Minecraft',clientToken:str=None,requestUser:str=False,authServer:str=url):Arguments:String(required)Username of agent/Mojang email (if migrated)String(required)Password for the account usedString(optional)Agent, defaults toMinecraft, can also beScrollsString(optional)Client identifier, must be random and identical per requestBoolean(optional)If set toTruerequest for user object too (default isFalse)String(optional)Custom authentication server. Defaults tohttps://authserver.mojang.comResponse:Check the Authenticate section ofthe documentationfor details.Example:fromyggdrasilimportauthenticateimportrandomrandomClientToken=random.randint(10000,99999)mc=authenticate('test@example.com','p455w0rd','Minecraft',randomClientToken,False)print(mc['accessToken'])RefreshRefreshes 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.defrefresh(accessToken:str,clientToken:str,requestUser:bool=False,authServer:str=url):Arguments:String(required)ValidaccessToken, gained fromauthenticate()String(required)Identical to theclientTokenused to get theaccessTokenin the first placeBoolean(optional)If set toTruerequest for user object too (default isFalse)String(optional)Custom authentication server. Defaults tohttps://authserver.mojang.comResponse:Check the Refresh section ofthe documentationfor details.Example:fromyggdrasilimportrefreshprint(refresh(mc['accessToken'],randomClientToken))# Note: invalidates inputted accessTokenValidateChecks if an accessToken is usable for authentication with a Minecraft server.defvalidate(accessToken:str,clientToken:str=None,authServer:str=url):Arguments:String(required)ValidaccessToken, gained fromauthenticate()String(optional)Identical to theclientTokenused to get theaccessTokenin the first placeString(optional)Custom authentication server. Defaults tohttps://authserver.mojang.comResponse:Returns Boolean for whetheraccessTokenis valid (andclientTokenmatch, if defined)Example:fromyggdrasilimportvalidateprint(validate(mc['accessToken'],randomClientToken))SignoutInvalidates accessTokens using an account's username and password.defsignout(username:str,password:str,authServer:str=url):Arguments:String(required)Username of agent/Mojang email (if migrated)String(required)Password for the account usedString(optional)Custom authentication server. Defaults tohttps://authserver.mojang.comResponse:ReturnsTrueunless error thrownExample:fromyggdrasilimportsignoutprint(signout('test@example.com','p455w0rd'))InvalidateInvalidates accessTokens using a client/access token pair.definvalidate(accessToken:str,clientToken:str,authServer:str=url):Arguments:String(required)ValidaccessToken, gained fromauthenticate()String(required)Identical to theclientTokenused to get theaccessTokenin the first placeString(optional)Custom authentication server. Defaults tohttps://authserver.mojang.comResponse:ReturnsTrueunless error thrownExample:fromyggdrasilimportinvalidateprint(signout(mc['accessToken'],randomClientToken))