capless / warrant

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

admin_create_user TemporaryPassword can't be a blank string #72

Open saintmood opened 6 years ago

saintmood commented 6 years ago

Hi, there is an issue with admin_create_user method, related to temporary_password. Let's assume I'm going to create a new user, and want Cognito generates password for that new user. Currently I am getting an error, because blank string is not allowed, as well as None.

Since I'm not able to make a pull request, I will post possible solution here:

def admin_create_user(self, username, temporary_password=None, attr_map=None, **kwargs):
        """
        Create a user using admin super privileges.
        :param username: User Pool username
        :param temporary_password: The temporary password to give the user.
        Leave blank to make Cognito generate a temporary password for the user.
        :param attr_map: Attribute map to Cognito's attributes
        :param kwargs: Additional User Pool attributes
        :return response: Response from Cognito
        """
        admin_create_request = {'UserPoolId': self.user_pool_id, 'Username': username,
                                'UserAttributes': dict_to_cognito(kwargs, attr_map)}

        if temporary_password is not None:
            admin_create_request['TemporaryPassword'] = temporary_password

        response = self.client.admin_create_user(**admin_create_request)
        kwargs.update(username=username)
        self._set_attributes(response, kwargs)

        response.pop('ResponseMetadata')
        return response