From e14d27f9998b0a33988addc0c97db21823533a00 Mon Sep 17 00:00:00 2001 From: alemidev Date: Wed, 16 Feb 2022 02:47:14 +0100 Subject: [PATCH] code is optional? idk --- aiocraft/client.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/aiocraft/client.py b/aiocraft/client.py index 4b0fa59..7c47572 100644 --- a/aiocraft/client.py +++ b/aiocraft/client.py @@ -42,7 +42,7 @@ class MinecraftClient(CallbacksHolder, Runnable): port:int options:ClientOptions - _authenticator:AuthInterface + _authenticator:MicrosoftAuthenticator _username:str code:str @@ -57,7 +57,7 @@ class MinecraftClient(CallbacksHolder, Runnable): def __init__( self, server:str, - code:str, + login_code:str = '', online_mode:bool = True, username:str = '', client_id:str = '', # TODO maybe hardcode defaults? @@ -76,7 +76,7 @@ class MinecraftClient(CallbacksHolder, Runnable): self.options = ClientOptions(**kwargs) - self.code = code + self.code = login_code self._username = username self._authenticator = MicrosoftAuthenticator(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri) self.online_mode = online_mode @@ -118,18 +118,16 @@ class MinecraftClient(CallbacksHolder, Runnable): return # Don't spam Auth endpoint! try: await self._authenticator.validate() # will raise an exc if token is invalid - self._authenticated = True - return except AuthException: if self._authenticator.refreshable: await self._authenticator.refresh() self._logger.warning("Refreshed Token") - else: + elif self.code: await self._authenticator.login(self.code) self._logger.info("Logged in with OAuth code") - self._authenticated = True - return - raise ValueError("No token or credentials to authenticate") # This should never happen + else: + raise ValueError("No refreshable auth or code to login") + self._authenticated = True async def change_server(self, server:str): restart = self.started