Skip to content

Commit a0cdf13

Browse files
authored
Merge pull request #48 from MazumaGo/eng-1456-unit_create_customer_token_via_jwt
ENG-1456: add jwt subject support
2 parents f4ae236 + 4e56161 commit a0cdf13

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

unit/models/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,19 @@ def from_json_api(l: List):
332332

333333

334334
class AuthorizedUser(UnitDTO):
335-
def __init__(self, full_name: FullName, email: str, phone: Phone):
335+
def __init__(self, full_name: FullName, email: str, phone: Phone, jwt_subject: Optional[str] = None):
336336
self.full_name = full_name
337337
self.email = email
338338
self.phone = phone
339+
self.jwt_subject = jwt_subject
339340

340341
@staticmethod
341342
def from_json_api(l: List) -> List:
342343
authorized_users = []
343344
for data in l:
344345
authorized_users.append(
345346
AuthorizedUser(
346-
data.get("fullName"), data.get("email"), data.get("phone")
347+
data.get("fullName"), data.get("email"), data.get("phone"), data.get("jwtSubject")
347348
)
348349
)
349350
return authorized_users

unit/models/codecs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@ def default(self, obj):
459459
if isinstance(obj, BusinessContact):
460460
return {"fullName": obj.full_name, "email": obj.email, "phone": obj.phone}
461461
if isinstance(obj, AuthorizedUser):
462-
return {"fullName": obj.full_name, "email": obj.email, "phone": obj.phone}
462+
authorized_user = {"fullName": obj.full_name, "email": obj.email, "phone": obj.phone}
463+
if obj.jwt_subject is not None:
464+
authorized_user["jwtSubject"] = obj.jwt_subject
465+
return authorized_user
463466
if isinstance(obj, Officer):
464467
officer = {"fullName": obj.full_name, "dateOfBirth": date_utils.to_date_str(obj.date_of_birth),
465468
"address": obj.address, "phone": obj.phone, "email": obj.email}

unit/models/customerToken.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ def from_json_api(_id, _type, attributes, relationships):
2121

2222
class CreateCustomerToken(UnitRequest):
2323
def __init__(self, customer_id: str, scope: str, verification_token: Optional[str] = None,
24-
verification_code: Optional[str] = None, expires_in: Optional[int] = None):
24+
verification_code: Optional[str] = None, expires_in: Optional[int] = None, jwt_token: Optional[str] = None):
2525
self.customer_id = customer_id
2626
self.scope = scope
2727
self.verification_token = verification_token
2828
self.verification_code = verification_code
2929
self.expires_in = expires_in
30+
self.jwt_token = jwt_token
3031

3132
def to_json_api(self) -> Dict:
3233
payload = {
@@ -47,6 +48,9 @@ def to_json_api(self) -> Dict:
4748
if self.verification_code:
4849
payload["data"]["attributes"]["verificationCode"] = self.verification_code
4950

51+
if self.jwt_token:
52+
payload["data"]["attributes"]["jwtToken"] = self.jwt_token
53+
5054
return payload
5155

5256
def __repr__(self):

0 commit comments

Comments
 (0)