From d1aa75e87636339c6c628b165159573b7972548b Mon Sep 17 00:00:00 2001 From: Samuel Vasco Date: Tue, 22 Jul 2025 16:52:22 -0400 Subject: [PATCH 1/3] feat: add jwt subject to authorized user entity --- unit/models/__init__.py | 5 +++-- unit/models/codecs.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/unit/models/__init__.py b/unit/models/__init__.py index aef251e..19c3d2c 100644 --- a/unit/models/__init__.py +++ b/unit/models/__init__.py @@ -332,10 +332,11 @@ def from_json_api(l: List): class AuthorizedUser(UnitDTO): - def __init__(self, full_name: FullName, email: str, phone: Phone): + def __init__(self, full_name: FullName, email: str, phone: Phone, jwt_subject: Optional[str] = None): self.full_name = full_name self.email = email self.phone = phone + self.jwt_subject = jwt_subject @staticmethod def from_json_api(l: List) -> List: @@ -343,7 +344,7 @@ def from_json_api(l: List) -> List: for data in l: authorized_users.append( AuthorizedUser( - data.get("fullName"), data.get("email"), data.get("phone") + data.get("fullName"), data.get("email"), data.get("phone"), data.get("jwtSubject") ) ) return authorized_users diff --git a/unit/models/codecs.py b/unit/models/codecs.py index 6e78950..6f85cef 100644 --- a/unit/models/codecs.py +++ b/unit/models/codecs.py @@ -459,7 +459,7 @@ def default(self, obj): if isinstance(obj, BusinessContact): return {"fullName": obj.full_name, "email": obj.email, "phone": obj.phone} if isinstance(obj, AuthorizedUser): - return {"fullName": obj.full_name, "email": obj.email, "phone": obj.phone} + return {"fullName": obj.full_name, "email": obj.email, "phone": obj.phone, "jwtSubject": obj.jwt_subject} if isinstance(obj, Officer): officer = {"fullName": obj.full_name, "dateOfBirth": date_utils.to_date_str(obj.date_of_birth), "address": obj.address, "phone": obj.phone, "email": obj.email} From ed366d29115b39b169fc86ca2e91b4a7d451efb2 Mon Sep 17 00:00:00 2001 From: Samuel Vasco Date: Wed, 23 Jul 2025 10:09:35 -0400 Subject: [PATCH 2/3] feat: add optional jwt_token field to CreateCustomerToken DTO --- unit/models/customerToken.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/unit/models/customerToken.py b/unit/models/customerToken.py index 856ab64..b8a5b15 100644 --- a/unit/models/customerToken.py +++ b/unit/models/customerToken.py @@ -21,12 +21,13 @@ def from_json_api(_id, _type, attributes, relationships): class CreateCustomerToken(UnitRequest): def __init__(self, customer_id: str, scope: str, verification_token: Optional[str] = None, - verification_code: Optional[str] = None, expires_in: Optional[int] = None): + verification_code: Optional[str] = None, expires_in: Optional[int] = None, jwt_token: Optional[str] = None): self.customer_id = customer_id self.scope = scope self.verification_token = verification_token self.verification_code = verification_code self.expires_in = expires_in + self.jwt_token = jwt_token def to_json_api(self) -> Dict: payload = { @@ -47,6 +48,9 @@ def to_json_api(self) -> Dict: if self.verification_code: payload["data"]["attributes"]["verificationCode"] = self.verification_code + if self.jwt_token: + payload["data"]["attributes"]["jwtToken"] = self.jwt_token + return payload def __repr__(self): From 4e56161236986c9b97c94a406e9a9cefd90f1644 Mon Sep 17 00:00:00 2001 From: Samuel Vasco Date: Wed, 23 Jul 2025 11:26:16 -0400 Subject: [PATCH 3/3] feat: make jwtSubject field optional in authorized user serialization --- unit/models/codecs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/unit/models/codecs.py b/unit/models/codecs.py index 6f85cef..aed24b2 100644 --- a/unit/models/codecs.py +++ b/unit/models/codecs.py @@ -459,7 +459,10 @@ def default(self, obj): if isinstance(obj, BusinessContact): return {"fullName": obj.full_name, "email": obj.email, "phone": obj.phone} if isinstance(obj, AuthorizedUser): - return {"fullName": obj.full_name, "email": obj.email, "phone": obj.phone, "jwtSubject": obj.jwt_subject} + authorized_user = {"fullName": obj.full_name, "email": obj.email, "phone": obj.phone} + if obj.jwt_subject is not None: + authorized_user["jwtSubject"] = obj.jwt_subject + return authorized_user if isinstance(obj, Officer): officer = {"fullName": obj.full_name, "dateOfBirth": date_utils.to_date_str(obj.date_of_birth), "address": obj.address, "phone": obj.phone, "email": obj.email}