From 5a993957e2da30e949bbcc9631fb7d6cf5a6b646 Mon Sep 17 00:00:00 2001 From: Daniel Ballard Date: Fri, 2 Aug 2024 16:51:14 -0400 Subject: [PATCH 1/2] better username evaluation in get_user_obj --- pycognito/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pycognito/__init__.py b/pycognito/__init__.py index bd28318a..56dee825 100644 --- a/pycognito/__init__.py +++ b/pycognito/__init__.py @@ -310,6 +310,13 @@ def get_user_obj( what we'd like to display to the users :return: dictionary of the Cognito user response """ + # try to detect the username from self or the attribute list if not set + if username is None: + if attribute_list is None: + username = self.username + else: + username = self.username or attribute_list.get("Username") + return self.user_class( username=username, attribute_list=attribute_list, From 9ded5cce6ef1bb6f8990fe2ccc3b316ac4c4ae4e Mon Sep 17 00:00:00 2001 From: Daniel Ballard Date: Fri, 2 Aug 2024 17:07:50 -0400 Subject: [PATCH 2/2] use metadata for username not attribute_list --- pycognito/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pycognito/__init__.py b/pycognito/__init__.py index 56dee825..f0c56596 100644 --- a/pycognito/__init__.py +++ b/pycognito/__init__.py @@ -310,12 +310,12 @@ def get_user_obj( what we'd like to display to the users :return: dictionary of the Cognito user response """ - # try to detect the username from self or the attribute list if not set + # try to detect the username from self or from the metadata if not set if username is None: - if attribute_list is None: + if metadata is None: username = self.username else: - username = self.username or attribute_list.get("Username") + username = self.username or metadata.get("username") return self.user_class( username=username,