NabuCasa / pycognito

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

Unable to get user data #232

Open CGarces-Apser opened 7 months ago

CGarces-Apser commented 7 months ago

I'm trying to fetch data from a user using pycognito.

This code give all de users in the pool, so the connection to AWS is working fine

    c = Cognito(
        cognito_service.COGNITO_USER_POOL_ID, cognito_service.COGNITO_APP_CLIENT_ID
    )
    response = c.get_users(attr_map={})

But the same code using get_user_obj

    c = Cognito(
        cognito_service.COGNITO_USER_POOL_ID, cognito_service.COGNITO_APP_CLIENT_ID
    )
    response = c.get_user_obj(username=username, attribute_list=[{}])

Always return a dummy object with all values set to None except for the username that is populated allways, also with not existing users.

I have tested also get_user

    c = Cognito(
        cognito_service.COGNITO_USER_POOL_ID,
        cognito_service.COGNITO_APP_CLIENT_ID,
        username=username,
    )
    response = c.get_user(attr_map={})

That raise a boto3 exception

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

My cognito pool use only "email", not "username" for login, I'm not sure if is de reason for the error.

Any hint to solve my issues fetching the user data?

wazy commented 3 months ago

This is because get_user uses the user's access token to get their information. If you just want to get a user's information without them having logged in and having a token then you should use admin_get_user

https://github.com/NabuCasa/pycognito/blob/559462af7e91a9a5b85aa79278c83b030aa05a47/pycognito/__init__.py#L609