fix: don't login when code's missing, clear it after use

This commit is contained in:
əlemi 2022-08-25 19:24:27 +02:00
parent 617a477be9
commit 7bc7a14457
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 6 additions and 1 deletions

View file

@ -82,7 +82,9 @@ class MinecraftClient:
try:
await self.authenticator.refresh()
self.logger.warning("Refreshed Token")
except AuthException:
except AuthException as e:
if not self.authenticator.code:
raise e # no code to login, re-raise refresh exc
await self.authenticator.login()
self.logger.info("Logged in")
self._authenticated = True

View file

@ -72,7 +72,10 @@ class MicrosoftAuthenticator(AuthInterface):
)
async def login(self): # TODO nicer way to get code?
if not self.code:
raise AuthException("/login", 0, {"error": "Missing login code"}, {})
self.accessToken = await self.authenticate(self.code)
self.code = None # this is only valid once
prof = await self.fetch_profile()
self.selectedProfile = GameProfile(id=prof['id'], name=prof['name'])
logging.info("Successfully logged into Microsoft account")