Add option to invalidate previous access_tokens to authenticate

This changes the default behaviour to include `self.client_token`
when using `authenticate`. If `self.client_token` is `None`, a new
token is generated using uuid4 (like the vanilla client does).
This commit is contained in:
Amund Eggen Svandal committed 2019-01-02 01:16:02 +01:00
1 parent 316ea4d63d
commit c67652d7e8
1 file changed
+10 -1
+10 -1
View File
@@ -1,5 +1,6 @@
import requests
import json
import uuid
from .exceptions import YggdrasilError
#: The base url for Ygdrassil requests
@@ -84,7 +85,7 @@ class AuthenticationToken(object):
return True
def authenticate(self, username, password):
def authenticate(self, username, password, invalidate_previous=False):
"""
Authenticates the user against https://authserver.mojang.com using
`username` and `password` parameters.
@@ -93,6 +94,8 @@ class AuthenticationToken(object):
username - An `str` object with the username (unmigrated accounts)
or email address for a Mojang account.
password - An `str` object with the password.
invalidate_previous - A `bool`. When `True`, invalidate
all previously acquired `access_token`s across all clients.
Returns:
Returns `True` if successful.
@@ -110,6 +113,12 @@ class AuthenticationToken(object):
"password": password
}
if not invalidate_previous:
# Include a `client_token` in the payload to prevent existing
# `access_token`s from being invalidated. If `self.client_token`
# is `None` generate a `client_token` using uuid4
payload["clientToken"] = self.client_token or uuid.uuid4().hex
res = _make_request(AUTH_SERVER, "authenticate", payload)
_raise_from_response(res)