set default values and error codes

This commit is contained in:
əlemi 2022-04-18 21:44:40 +02:00
parent 3f647bb561
commit ca45980bcd
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 8 additions and 3 deletions

View file

@ -79,7 +79,7 @@ class MicrosoftAuthenticator(AuthInterface):
async def refresh(self): async def refresh(self):
if not self.refreshToken: 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() self.accessToken = await self.authenticate()
prof = await self.fetch_profile() prof = await self.fetch_profile()
self.selectedProfile = GameProfile(id=prof['id'], name=prof['name']) self.selectedProfile = GameProfile(id=prof['id'], name=prof['name'])
@ -87,7 +87,7 @@ class MicrosoftAuthenticator(AuthInterface):
async def validate(self): async def validate(self):
if not self.accessToken: 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() prof = await self.fetch_profile()
self.selectedProfile = GameProfile(id=prof['id'], name=prof['name']) self.selectedProfile = GameProfile(id=prof['id'], name=prof['name'])
logging.info("Session validated : %s", repr(self.selectedProfile)) logging.info("Session validated : %s", repr(self.selectedProfile))

View file

@ -28,6 +28,9 @@ class MojangAuthenticator(AuthInterface):
def __init__(self, username:str="", password:Optional[str]=None): def __init__(self, username:str="", password:Optional[str]=None):
self.username = username self.username = username
self.password = password self.password = password
self.accessToken = ""
self.clientToken = ""
self.selectedProfile = GameProfile("", username)
def __equals__(self, other) -> bool: def __equals__(self, other) -> bool:
if not isinstance(other, self.__class__): if not isinstance(other, self.__class__):
@ -92,6 +95,8 @@ class MojangAuthenticator(AuthInterface):
) )
async def refresh(self, requestUser:bool = False) -> 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( res = await self._post(
self.AUTH_SERVER + "/refresh", self.AUTH_SERVER + "/refresh",
headers=self.HEADERS, headers=self.HEADERS,
@ -112,7 +117,7 @@ class MojangAuthenticator(AuthInterface):
async def validate(self, clientToken:bool = True) -> AuthInterface: async def validate(self, clientToken:bool = True) -> AuthInterface:
if not self.accessToken: if not self.accessToken:
raise AuthException("/validate", 404, {"message":"No access token"}, {}) raise AuthException("/validate", 0, {"message":"No access token"}, {})
payload = { "accessToken": self.accessToken } payload = { "accessToken": self.accessToken }
if clientToken: if clientToken:
payload["clientToken"] = self.clientToken payload["clientToken"] = self.clientToken