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:
1 parent
316ea4d63d
commit
c67652d7e8
1 file changed
+10
-1
@@ -1,5 +1,6 @@
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
import uuid
|
||||||
from .exceptions import YggdrasilError
|
from .exceptions import YggdrasilError
|
||||||
|
|
||||||
#: The base url for Ygdrassil requests
|
#: The base url for Ygdrassil requests
|
||||||
@@ -84,7 +85,7 @@ class AuthenticationToken(object):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def authenticate(self, username, password):
|
def authenticate(self, username, password, invalidate_previous=False):
|
||||||
"""
|
"""
|
||||||
Authenticates the user against https://authserver.mojang.com using
|
Authenticates the user against https://authserver.mojang.com using
|
||||||
`username` and `password` parameters.
|
`username` and `password` parameters.
|
||||||
@@ -93,6 +94,8 @@ class AuthenticationToken(object):
|
|||||||
username - An `str` object with the username (unmigrated accounts)
|
username - An `str` object with the username (unmigrated accounts)
|
||||||
or email address for a Mojang account.
|
or email address for a Mojang account.
|
||||||
password - An `str` object with the password.
|
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:
|
||||||
Returns `True` if successful.
|
Returns `True` if successful.
|
||||||
@@ -110,6 +113,12 @@ class AuthenticationToken(object):
|
|||||||
"password": password
|
"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)
|
res = _make_request(AUTH_SERVER, "authenticate", payload)
|
||||||
|
|
||||||
_raise_from_response(res)
|
_raise_from_response(res)
|
||||||
|
|||||||
Reference in new issue
Block a user