From c67652d7e8e43d3d99c9157c19851fe621a3c445 Mon Sep 17 00:00:00 2001 From: Amund Eggen Svandal Date: Wed, 2 Jan 2019 01:16:02 +0100 Subject: [PATCH] Add option to invalidate previous `access_token`s 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). --- minecraft/authentication.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/minecraft/authentication.py b/minecraft/authentication.py index 9750e03..112bc49 100644 --- a/minecraft/authentication.py +++ b/minecraft/authentication.py @@ -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)