Skip to content
This repository was archived by the owner on Apr 2, 2023. It is now read-only.

Commit 87a0f8c

Browse files
authored
Merge pull request #1 from alphatoasterous/master
Added parameters for using custom authentication servers
2 parents 972d76a + e41662c commit 87a0f8c

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

yggdrasil/authenticate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
url = 'https://authserver.mojang.com'
44
headers = {'Content-Type': 'application/json'}
55

6-
def authenticate(username:str, password:str, agentName:str = 'Minecraft', clientToken:str = None, requestUser:str = False):
6+
def authenticate(username:str, password:str, agentName:str = 'Minecraft', clientToken:str = None, requestUser:str = False, authServer:str = url):
77
'''
88
Authenticates a user using their password.
99
Parameters:
@@ -12,9 +12,10 @@ def authenticate(username:str, password:str, agentName:str = 'Minecraft', client
1212
agentName - Agent, defaults to Minecraft, can also be Scrolls
1313
clientToken - Client identifier, must be random and identical per request
1414
requestUser - If set to True, request for user object too
15+
authServer - Authentication server, defaults to authserver.mojang.com
1516
Returns: Formatted JSON, see API documentation
1617
'''
1718
data = json.dumps({"agent":{"name":agentName,"version":1}, "username":username, "password":password, "clientToken":clientToken, "requestUser":requestUser})
18-
response = json.loads(requests.post(url + '/authenticate', data=data, headers=headers).text)
19+
response = json.loads(requests.post(authServer + '/authenticate', data=data, headers=headers).text)
1920
if 'error' in response: raise Exception(f"{response['error']}: {response['errorMessage']}")
2021
else: return response

yggdrasil/invalidate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
url = 'https://authserver.mojang.com'
44
headers = {'Content-Type': 'application/json'}
55

6-
def invalidate(accessToken:str, clientToken:str):
6+
def invalidate(accessToken:str, clientToken:str, authServer:str = url):
77
'''
88
Invalidates accessTokens using a client/access token pair.
99
Parameters:
1010
accessToken - Valid accessToken, gained from authenticate()
1111
clientToken - Identical to the clientToken used to get the accessToken in the first place
12+
authServer - Authentication server, defaults to authserver.mojang.com
1213
Returns: True if success, otherwise the error
1314
'''
1415
data = json.dumps({"accessToken":accessToken, "clientToken":clientToken})
15-
try: response = json.loads(requests.post(url + '/invalidate', data=data, headers=headers).text)
16+
try: response = json.loads(requests.post(authServer + '/invalidate', data=data, headers=headers).text)
1617
except json.decoder.JSONDecodeError: return True
1718
if 'error' in response: raise Exception(f"{response['error']}: {response['errorMessage']}")
1819
return False

yggdrasil/refresh.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
url = 'https://authserver.mojang.com'
44
headers = {'Content-Type': 'application/json'}
55

6-
def refresh(accessToken:str, clientToken:str, requestUser:bool = False):
6+
def refresh(accessToken:str, clientToken:str, requestUser:bool = False, authServer:str = url):
77
'''
88
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.
99
Parameters:
1010
accessToken - Valid accessToken, gained from authenticate()
1111
clientToken - Identical to the clientToken used to get the accessToken in the first place
1212
requestUser - If set to True, request for user object too
13+
authServer - Authentication server, defaults to authserver.mojang.com
1314
Returns: Formatted JSON, see API documentation
1415
'''
1516
data = json.dumps({"accessToken":accessToken, "clientToken":clientToken, "requestUser":requestUser})
16-
response = json.loads(requests.post(url + '/refresh', data=data, headers=headers).text)
17+
response = json.loads(requests.post(authServer + '/refresh', data=data, headers=headers).text)
1718
if 'error' in response: raise Exception(f"{response['error']}: {response['errorMessage']}")
1819
else: return response

yggdrasil/signout.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
url = 'https://authserver.mojang.com'
44
headers = {'Content-Type': 'application/json'}
55

6-
def signout(username:str, password:str):
6+
def signout(username:str, password:str, authServer:str = url):
77
'''
88
Invalidates accessTokens using an account's username and password.
99
Parameters:
1010
username - Username of agent/Mojang email (if migrated)
1111
password - Password for the account used
12+
authServer - Authentication server, defaults to authserver.mojang.com
1213
Returns: True if success, otherwise the error
1314
'''
1415
data = json.dumps({"username":username, "password":password})
15-
try: response = json.loads(requests.post(url + '/signout', data=data, headers=headers).text)
16+
try: response = json.loads(requests.post(authServer + '/signout', data=data, headers=headers).text)
1617
except json.decoder.JSONDecodeError: return True
1718
if 'error' in response: raise Exception(f"{response['error']}: {response['errorMessage']}")
1819
return False

yggdrasil/validate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
url = 'https://authserver.mojang.com'
44
headers = {'Content-Type': 'application/json'}
55

6-
def validate(accessToken:str, clientToken:str = None):
6+
def validate(accessToken:str, clientToken:str = None, authServer:str = url):
77
'''
88
Checks if an accessToken is usable for authentication with a Minecraft server.
99
Parameters:
1010
accessToken - Valid accessToken, gained from authenticate()
1111
clientToken - Identical to the clientToken used to get the accessToken in the first place
12+
authServer - Authentication server, defaults to authserver.mojang.com
1213
Returns: Boolean, if accessToken is valid
1314
'''
1415
data = json.dumps({"accessToken":accessToken, "clientToken":clientToken})
15-
try: response = json.loads(requests.post(url + '/validate', data=data, headers=headers).text)
16+
try: response = json.loads(requests.post(authServer + '/validate', data=data, headers=headers).text)
1617
except json.decoder.JSONDecodeError: return True
1718
return False

0 commit comments

Comments
 (0)