capless / warrant

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

get_user() AccessToken error #110

Closed pontigol closed 6 years ago

pontigol commented 6 years ago

Hi,

When I try:

from warrant import Cognito

u = Cognito('your-user-pool-id','your-client-id',
    username='bob')

user = u.get_user(attr_map={"given_name":"first_name","family_name":"last_name"})

as specified in the docs I get:

botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter AccessToken, value: None, type: <class 'NoneType'>, valid types: <class 'str'>

get_users() (in plural) works perfectly fine but get_user()gives me above error. What am i doing wrong?

Best regards, Pontus

ghost commented 6 years ago

Hello Pontus,

It looks like the "access_token" parameter is required for the .get_user() method.

Can you try:

from warrant import Cognito

u = Cognito('your-user-pool-id','your-client-id',
    username='bob', access_token='your-access-token')

user = u.get_user(attr_map={"given_name":"first_name","family_name":"last_name"})
pontigol commented 6 years ago

Hi Chris,

Thanks for the reply. That means the user from which I want information has to log in, and my api can then get the user's information. So there is no way I can get user information as an admin outside of the context of a logged-in user? And why can I access the same user information without an access token when I call get_users() (in plural)? That seems inconsistent to me, and it is also not what it looks like in the documentation but maybe it just needs to be updated.

ghost commented 6 years ago

There's a method called admin_get_user() with only user_pool_id and username parameters that will return the get_user_obj.

https://github.com/capless/warrant/blob/ff2e4793d8479e770f2461ef7cbc0c15ee784395/warrant/__init__.py#L478-L498

Perhaps you could try:

from warrant import Cognito

u = Cognito('your-user-pool-id','your-client-id',
    username='bob')

user = u.admin_get_user(attr_map={"given_name":"first_name","family_name":"last_name"})
pontigol commented 6 years ago

Thanks, that did work! I am closing this issue then. I think the documentation could use some corrections on when tokens are needed and not but unfortunately I don't have time to contribute myself. Thanks again!