From ca45980bcdc0f266a2996cbed9d1b8c3e3a90134 Mon Sep 17 00:00:00 2001 From: alemidev Date: Mon, 18 Apr 2022 21:44:40 +0200 Subject: [PATCH] set default values and error codes --- src/aiocraft/mc/auth/microsoft.py | 4 ++-- src/aiocraft/mc/auth/mojang.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/aiocraft/mc/auth/microsoft.py b/src/aiocraft/mc/auth/microsoft.py index 2294e39..d44d6ec 100644 --- a/src/aiocraft/mc/auth/microsoft.py +++ b/src/aiocraft/mc/auth/microsoft.py @@ -79,7 +79,7 @@ class MicrosoftAuthenticator(AuthInterface): async def refresh(self): if not self.refreshToken: - raise AuthException("refresh", 404, {"error": "Missing refresh token"}, {}) + raise AuthException("/refresh", 0, {"error": "Missing refresh token"}, {}) self.accessToken = await self.authenticate() prof = await self.fetch_profile() self.selectedProfile = GameProfile(id=prof['id'], name=prof['name']) @@ -87,7 +87,7 @@ class MicrosoftAuthenticator(AuthInterface): async def validate(self): if not self.accessToken: - raise AuthException("validate", 404, {"error": "No access token"}, {}) + raise AuthException("/validate", 0, {"error": "No access token"}, {}) prof = await self.fetch_profile() self.selectedProfile = GameProfile(id=prof['id'], name=prof['name']) logging.info("Session validated : %s", repr(self.selectedProfile)) diff --git a/src/aiocraft/mc/auth/mojang.py b/src/aiocraft/mc/auth/mojang.py index c80865a..7905556 100644 --- a/src/aiocraft/mc/auth/mojang.py +++ b/src/aiocraft/mc/auth/mojang.py @@ -28,6 +28,9 @@ class MojangAuthenticator(AuthInterface): def __init__(self, username:str="", password:Optional[str]=None): self.username = username self.password = password + self.accessToken = "" + self.clientToken = "" + self.selectedProfile = GameProfile("", username) def __equals__(self, other) -> bool: if not isinstance(other, self.__class__): @@ -92,6 +95,8 @@ class MojangAuthenticator(AuthInterface): ) async def refresh(self, requestUser:bool = False) -> AuthInterface: + if not self.accessToken or not self.clientToken: + raise AuthException("/refresh", 0, {"message":"No access token or client token"}, {}) res = await self._post( self.AUTH_SERVER + "/refresh", headers=self.HEADERS, @@ -112,7 +117,7 @@ class MojangAuthenticator(AuthInterface): async def validate(self, clientToken:bool = True) -> AuthInterface: if not self.accessToken: - raise AuthException("/validate", 404, {"message":"No access token"}, {}) + raise AuthException("/validate", 0, {"message":"No access token"}, {}) payload = { "accessToken": self.accessToken } if clientToken: payload["clientToken"] = self.clientToken