improved token serialization/deserialization
This commit is contained in:
parent
6e189bcd17
commit
89635a4c28
2 changed files with 9 additions and 6 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
from .token import *
|
||||||
|
from .packet import Packet
|
||||||
|
from .definitions import *
|
|
@ -18,7 +18,7 @@ def _raise_from_json(endpoint:str, data:dict):
|
||||||
raise AuthException(f"[{action}] {err_type} : {err_msg}")
|
raise AuthException(f"[{action}] {err_type} : {err_msg}")
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Profile:
|
class GameProfile:
|
||||||
id : str
|
id : str
|
||||||
name : str
|
name : str
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class Token:
|
||||||
username : str
|
username : str
|
||||||
accessToken : str
|
accessToken : str
|
||||||
clientToken : str
|
clientToken : str
|
||||||
selectedProfile : Profile
|
selectedProfile : GameProfile
|
||||||
|
|
||||||
AGENT_NAME = "Minecraft"
|
AGENT_NAME = "Minecraft"
|
||||||
AGENT_VERSION = 1
|
AGENT_VERSION = 1
|
||||||
|
@ -74,10 +74,10 @@ class Token:
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data:dict):
|
def from_dict(cls, data:dict):
|
||||||
return cls(
|
return cls(
|
||||||
username=data["selectedProfile"]["name"],
|
username=data["username"] if "username" in data else data["selectedProfile"]["name"],
|
||||||
accessToken=data["accessToken"],
|
accessToken=data["accessToken"],
|
||||||
clientToken=data["clientToken"],
|
clientToken=data["clientToken"],
|
||||||
selectedProfile=Profile(**data["selectedProfile"]),
|
selectedProfile=GameProfile(**data["selectedProfile"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -100,7 +100,7 @@ class Token:
|
||||||
username=username,
|
username=username,
|
||||||
accessToken=res["accessToken"],
|
accessToken=res["accessToken"],
|
||||||
clientToken=res["clientToken"],
|
clientToken=res["clientToken"],
|
||||||
selectedProfile=Profile(**res["selectedProfile"])
|
selectedProfile=GameProfile(**res["selectedProfile"])
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -118,7 +118,7 @@ class Token:
|
||||||
|
|
||||||
self.accessToken = res["accessToken"]
|
self.accessToken = res["accessToken"]
|
||||||
self.clientToken = res["clientToken"]
|
self.clientToken = res["clientToken"]
|
||||||
self.selectedProfile = Profile(**res["selectedProfile"])
|
self.selectedProfile = GameProfile(**res["selectedProfile"])
|
||||||
|
|
||||||
if "user" in res:
|
if "user" in res:
|
||||||
self.username = res["user"]["username"]
|
self.username = res["user"]["username"]
|
||||||
|
|
Loading…
Reference in a new issue