Skip to content

Commit

Permalink
added respinse class dict function to each class
Browse files Browse the repository at this point in the history
rest  in progress
  • Loading branch information
moonlightnexus committed Apr 5, 2024
1 parent ca95975 commit c725684
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
7 changes: 4 additions & 3 deletions trustauthx/authlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def delete_permission(self, rol_id, foreground=False, **Permission_) -> DeletePe
response = requests.delete(url, headers=headers, params=params, data=json.dumps(data))
self.reinitialize_all(foreground)
return response.json()

class AuthLiteClient():
instances = []

Expand Down Expand Up @@ -626,7 +626,7 @@ def re_auth(self, code):
response.text)
)

def get_user(self, token) -> dict:
def get_user(self, token, return_class=False) -> User|dict:
"""
Validates the given authentication token and returns user data.
Expand Down Expand Up @@ -654,7 +654,8 @@ def get_user(self, token) -> dict:
rtn.pop("sub")
rtn["email"] = sub["email"]
rtn["uid"] = sub["uid"]
return rtn
if not return_class:return User(rtn).to_dict()
else: return User(rtn)
else:raise HTTPError(
'Request failed with status code : {} \n this code contains a msg : {}'.format(
response.status_code,
Expand Down
36 changes: 34 additions & 2 deletions trustauthx/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class Permission:
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)


def to_dict(self):
return asdict(self)
@dataclass
class Role:
"""
Expand All @@ -26,39 +28,69 @@ class Role:
name: str
permissions: List[Permission]


def to_dict(self):
return asdict(self)
@dataclass
class GetAllRolesResponse:
roles_list: List[Role]
roles_json_list: List[Dict[str, Union[str, List[Dict[str, str]]]]]

def to_dict(self):
return asdict(self)
@dataclass
class AddRoleResponse:
org_id: str
rol_id: str
name: str
permissions: List[Permission]

def to_dict(self):
return asdict(self)
@dataclass
class DeleteRoleResponse:
org_id: str
rol_id: str
name: str
permissions: List[Permission]

def to_dict(self):
return asdict(self)
@dataclass
class AddPermissionResponse:
org_id: str
rol_id: str
permissions: List[Dict[str, str]]

def to_dict(self):
return asdict(self)

@dataclass
class DeletePermissionResponse:
org_id: str
rol_id: str
permissions: List[Permission]

def to_dict(self):
return asdict(self)

@dataclass
class User:
iss: str
jti: str
access_token: str
type: str
exp: float
refresh_token: str
refresh_exp: int
scope: List[str]
img: str
name: str
iat: int
email: str
uid: str

def to_dict(self):
return asdict(self)

"""# Demo data
demo_get_all_roles_response = GetAllRolesResponse(roles=[
Expand Down

0 comments on commit c725684

Please sign in to comment.