Skip to content

Commit 04bf568

Browse files
committed
SDK-1098: Add initial support for getting application profile details from activity details
1 parent 065198f commit 04bf568

File tree

5 files changed

+72
-14
lines changed

5 files changed

+72
-14
lines changed

yoti_python_sdk/activity_details.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
from datetime import datetime
77

88
from yoti_python_sdk import attribute_parser, config
9-
from yoti_python_sdk.profile import Profile
9+
from yoti_python_sdk.profile import Profile, ApplicationProfile
1010

1111

1212
class ActivityDetails:
13-
def __init__(self, receipt, decrypted_profile=None):
13+
def __init__(self, receipt, decrypted_profile=None, decrypted_application_profile=None):
1414
self.decrypted_profile = decrypted_profile
1515
self.user_profile = {} # will be removed in v3.0.0
1616
self.base64_selfie_uri = None
17+
self.application_profile = None
1718

1819
if decrypted_profile and hasattr(decrypted_profile, "attributes"):
1920
decrypted_profile_attributes = decrypted_profile.attributes
@@ -55,6 +56,11 @@ def __init__(self, receipt, decrypted_profile=None):
5556
)
5657

5758
self.ensure_postal_address()
59+
60+
61+
if decrypted_application_profile and hasattr(decrypted_application_profile, "attributes"):
62+
decrypted_application_profile_attributes = decrypted_application_profile.attributes
63+
self.application_profile = ApplicationProfile(decrypted_application_profile_attributes)
5864

5965
self.__remember_me_id = receipt.get("remember_me_id")
6066
self.parent_remember_me_id = receipt.get("parent_remember_me_id")

yoti_python_sdk/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def get_activity_details(self, encrypted_request_token):
7878
receipt = json.loads(response.text).get("receipt")
7979

8080
encrypted_data = proto.current_user(receipt)
81+
encrypted_application_profile = proto.current_application(receipt)
8182

8283
if not encrypted_data:
8384
return ActivityDetails(receipt)
@@ -86,8 +87,12 @@ def get_activity_details(self, encrypted_request_token):
8687
decrypted_data = self.__crypto.decipher(
8788
unwrapped_key, encrypted_data.iv, encrypted_data.cipher_text
8889
)
90+
decrypted_application_data = self.__crypto.decipher(
91+
unwrapped_key, encrypted_application_profile.iv, encrypted_application_profile.cipher_text
92+
)
93+
8994
attribute_list = proto.attribute_list(decrypted_data)
90-
return ActivityDetails(receipt, attribute_list)
95+
return ActivityDetails(receipt, attribute_list, decrypted_application_profile=decrypted_application_data)
9196

9297
def perform_aml_check(self, aml_profile):
9398
if aml_profile is None:

yoti_python_sdk/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
ATTRIBUTE_STRUCTURED_POSTAL_ADDRESS = "structured_postal_address"
1717
ATTRIBUTE_DOCUMENT_IMAGES = "document_images"
1818
ATTRIBUTE_DOCUMENT_DETAILS = "document_details"
19+
ATTRIBUTE_APPLICATION_NAME = "application_name"
20+
ATTRIBUTE_APPLICATION_LOGO = "application_logo"
21+
ATTRIBUTE_APPLICATION_URL = "application_url"
22+
ATTRIBUTE_APPLICATION_RECEIPT_BGCOLOR = "application_receipt_bgcolor"
1923
ANCHOR_SOURCE = "SOURCE"
2024
ANCHOR_VERIFIER = "VERIFIER"
2125
KEY_AGE_VERIFIED = "is_age_verified"

yoti_python_sdk/profile.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from yoti_python_sdk.image import Image
88
from yoti_python_sdk import document_details
99

10+
class BaseProfile:
1011

11-
class Profile:
1212
def __init__(self, profile_attributes):
1313
self.attributes = {}
1414

@@ -44,7 +44,21 @@ def __init__(self, profile_attributes):
4444
)
4545
)
4646

47-
self.ensure_postal_address()
47+
def get_attribute(self, attribute_name):
48+
"""retrieves an attribute based on its name
49+
:param attribute_name:
50+
:return: Attribute
51+
"""
52+
if attribute_name in self.attributes:
53+
return self.attributes.get(attribute_name)
54+
else:
55+
return None
56+
57+
58+
class Profile(BaseProfile):
59+
def __init__(self, profile_attributes):
60+
super(Profile, self).__init__(profile_attributes)
61+
self.ensure_postal_address()
4862

4963
@property
5064
def date_of_birth(self):
@@ -145,15 +159,6 @@ def document_images(self):
145159
def document_details(self):
146160
return self.get_attribute(config.ATTRIBUTE_DOCUMENT_DETAILS)
147161

148-
def get_attribute(self, attribute_name):
149-
"""retrieves an attribute based on its name
150-
:param attribute_name:
151-
:return: Attribute
152-
"""
153-
if attribute_name in self.attributes:
154-
return self.attributes.get(attribute_name)
155-
else:
156-
return None
157162

158163
def ensure_postal_address(self):
159164
if (
@@ -173,3 +178,28 @@ def ensure_postal_address(self):
173178
formatted_address,
174179
structured_postal_address.anchors,
175180
)
181+
182+
def ApplicationProfile(BaseProfile):
183+
184+
def __init__(self, profile_attributes):
185+
super(ApplicationProfile, self).__init__(profile_attributes)
186+
187+
@property
188+
def application_name(self):
189+
"""
190+
application_name is the name of the application set in Yoti Hub
191+
:return: Attribute(str)
192+
"""
193+
return self.get_attribute(config.ATTRIBUTE_APPLICATION_NAME)
194+
195+
@property
196+
def application_url(self):
197+
return self.get_attribute(config.ATTRIBUTE_APPLICATION_URL)
198+
199+
@property
200+
def application_logo(self):
201+
return self.get_attribute(config.ATTRIBUTE_APPLICATION_LOGO)
202+
203+
@property
204+
def application_receipt_bg_color(self):
205+
return self.get_attribute(config.ATTRIBUTE_APPLICATION_RECEIPT_BGCOLOR)

yoti_python_sdk/protobuf/protobuf.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ def current_user(receipt):
2828
merged_user.MergeFromString(decoded_profile_content)
2929
return merged_user
3030

31+
@staticmethod
32+
def current_application(receipt):
33+
if receipt.get("profile_content") is None or receipt.get("profile_content") == '':
34+
return None
35+
36+
application_content = receipt["profile_content"]
37+
decoded_application_content = base64.b64decode(application_content)
38+
39+
merged_application = EncryptedData_pb2.EncryptedData()
40+
merged_application.MergeFromString(decoded_application_content)
41+
42+
return merged_application
43+
3144
@staticmethod
3245
def attribute_list(data):
3346
attribute_list = List_pb2.AttributeList()

0 commit comments

Comments
 (0)