capless / warrant

Python library for using AWS Cognito. With support for SRP.
Apache License 2.0
468 stars 192 forks source link

Question: Get user information, missing attributes #47

Closed jonasao closed 6 years ago

jonasao commented 6 years ago

I am attempting to read user information from AWS Cognito using the get_user() method, but I am unsure if it works as expected.

What I am doing:

u = Cognito(.....)
user = u.get_user(attr_map={'given_name': 'firstname', 'family_name': 'lastname'})

I would have expected this method call to expose the values of 'firstname' and 'lastname' as separate properties, or as a single "data" property of the object "user", but unfortunately - no.

The values are only exposed via the user._data private property. Is this a bug, or am I missing something?

armicron commented 6 years ago

What is in your self._data? Which attribute are you trying to get?

>>> user_obj = user.get_user(attr_map={'given_name': 'firstname', 'family_name': 'lastname'})
>>> user_obj._data
{'email': '111@zzz.co,', 'firstname': 'Jenkins'}
>>> user_obj.firstname
'Jenkins'
jonasao commented 6 years ago

self.data exposes the correct list of AWS Cognito attributes I am asking for, with the correct mapping of attribute names, according to the specifications mentioned above.

{
  'email': '....@gmail.com', 
  'lastname': 'Ols...', 'firstname': 'Jon.....',
  'custom:kit_app2': 'M24', 
  'custom:kit_app1': 'DM'
}

My problem is that all these values resides in a "private" object, not exposed via normal properties or "getter" methods.

armicron commented 6 years ago

It should be exposed as an attribute if it's in self._dict or self._metadata. Can you try to debug the __getattr__ method? https://github.com/capless/warrant/blob/d109924e9e2a2cad34eb0f539f7491cef7585dbf/warrant/__init__.py#L64-L68

jonasao commented 6 years ago

I am able to get the values via the self.__getattr__() method, but this is still i private method. Shouldn't this method have been a public method of the user object?

armicron commented 6 years ago

self.__getattr__(self, 'attribute_name') is equal to self.attribute_name if self.attribute_name wasn't defined.

3.3.2. Customizing attribute access

jonasao commented 6 years ago

Ah, of course, my bad. Thanks!