Skip to main content

Async wrapper for AWS cognito. Heavily based on capless/warrant

Project description


Async fork of warrant.

Part of the code was provided by the warrant contributors as part of that software. This code has been duplicated here as allowed by the Apache License 2.0. The warrant code is copyright of the warrant contributors. Any other code is copyright of mandate contributors.


    cog = Cognito(
        'pool_id',  # user pool id
        'client_id',  # client id
        user_pool_region='eu-west-2', # optional
        client_secret='secret', # optional
        loop=loop # optional


    await cog.register('', 'password')

admin_create_user is also available:

    await cog.admin_create_user('')

Confirm Sign up

    await cog.confirm_sign_up('SIGNUP_CODE', '')

admin_confirm_sign_up is also available:

    await cog.admin_confirm_sign_up('')


All the below examples can be called with or without admin_ variants.

Per the documentation, when running a backend server, you can use the admin_ methods for authentication and user-related activities. For example:

    await cog.admin_authenticate(password)

Technically, the non-admin workflow can also be used with, however I have not got this to work with app secrets! Help would be appreciated here.

    await cog.authenticate(password)
botocore.errorfactory.NotAuthorizedException: An error occurred (NotAuthorizedException) when calling the RespondToAuthChallenge operation: Unable to verify secret hash for client <client id>

If you create an app without app secrets, you should also be able to use the non-admin versions without issues.

Forgot password

    await cog.initiate_forgot_password()
    # Get the code from the email
    await cog.confirm_forgot_password(code, new_password)

Get user attributes

    await cog.admin_authenticate('password')
    user = await cog.get_user()

Change password

    await cog.admin_authenticate(old_password)
    await cog.change_password(old_password, new_password)

Update profile

    await cog.admin_authenticate(password)
    await cog.update_profile(
            'address': 'foo'

Or as admin

    await cog.admin_update_profile(


    await cog.logout()


Install poetry, then to install the dependencies:

poetry install

Unit tests

python -m unittest discover tests

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mandate, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size mandate-1.0.0-py3-none-any.whl (17.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size mandate-1.0.0.tar.gz (16.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page