code is optional? idk

This commit is contained in:
əlemi 2022-02-16 02:47:14 +01:00
parent 6d3205c5c6
commit e14d27f999
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -42,7 +42,7 @@ class MinecraftClient(CallbacksHolder, Runnable):
port:int port:int
options:ClientOptions options:ClientOptions
_authenticator:AuthInterface _authenticator:MicrosoftAuthenticator
_username:str _username:str
code:str code:str
@ -57,7 +57,7 @@ class MinecraftClient(CallbacksHolder, Runnable):
def __init__( def __init__(
self, self,
server:str, server:str,
code:str, login_code:str = '',
online_mode:bool = True, online_mode:bool = True,
username:str = '', username:str = '',
client_id:str = '', # TODO maybe hardcode defaults? client_id:str = '', # TODO maybe hardcode defaults?
@ -76,7 +76,7 @@ class MinecraftClient(CallbacksHolder, Runnable):
self.options = ClientOptions(**kwargs) self.options = ClientOptions(**kwargs)
self.code = code self.code = login_code
self._username = username self._username = username
self._authenticator = MicrosoftAuthenticator(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri) self._authenticator = MicrosoftAuthenticator(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
self.online_mode = online_mode self.online_mode = online_mode
@ -118,18 +118,16 @@ class MinecraftClient(CallbacksHolder, Runnable):
return # Don't spam Auth endpoint! return # Don't spam Auth endpoint!
try: try:
await self._authenticator.validate() # will raise an exc if token is invalid await self._authenticator.validate() # will raise an exc if token is invalid
self._authenticated = True
return
except AuthException: except AuthException:
if self._authenticator.refreshable: if self._authenticator.refreshable:
await self._authenticator.refresh() await self._authenticator.refresh()
self._logger.warning("Refreshed Token") self._logger.warning("Refreshed Token")
else: elif self.code:
await self._authenticator.login(self.code) await self._authenticator.login(self.code)
self._logger.info("Logged in with OAuth code") self._logger.info("Logged in with OAuth code")
self._authenticated = True else:
return raise ValueError("No refreshable auth or code to login")
raise ValueError("No token or credentials to authenticate") # This should never happen self._authenticated = True
async def change_server(self, server:str): async def change_server(self, server:str):
restart = self.started restart = self.started