Skip to main content

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

Project description

Mandate

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.

Initialise

    cog = Cognito(
        'pool_id',  # user pool id
        'client_id',  # client id
        user_pool_region='eu-west-2', # optional
        username='your-user@email.com',
        client_secret='secret', # optional
        loop=loop # optional
    )

Register

    cog.add_base_attributes(email='your-user@email.com')
    await cog.register('your-user@email.com', 'password')

admin_create_user is also available:

    await cog.admin_create_user('user@email.com')

Confirm Sign up

    await cog.confirm_sign_up('SIGNUP_CODE', 'your-user@email.com')

admin_confirm_sign_up is also available:

    await cog.admin_confirm_sign_up('user@email.com')

Authenticate

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.admin_update_profile(
        {
            'address': 'foo'
        }
    )

Logout

    await cog.logout()

Development

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.

Source Distribution

mandate-0.2.5.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

mandate-0.2.5-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file mandate-0.2.5.tar.gz.

File metadata

  • Download URL: mandate-0.2.5.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.16 CPython/3.6.3 Linux/4.4.0-101-generic

File hashes

Hashes for mandate-0.2.5.tar.gz
Algorithm Hash digest
SHA256 7ceeff9ad6996e868a86affeeb6176b20a8ac234cfa0b4fc4fcd77fdb57a57b7
MD5 bc01cfe23e1658a2c8729d3d57655d9f
BLAKE2b-256 0491284b2717aa17e91af2ca03adc5ee6cec4f892b046f65e9bca130fcb9cec2

See more details on using hashes here.

File details

Details for the file mandate-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: mandate-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.16 CPython/3.6.3 Linux/4.4.0-101-generic

File hashes

Hashes for mandate-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d4ebb99d8e3d5dfe5f001010e672d8441b1e3b44d0f9c7272c1479c71e0e6b5c
MD5 8c1c2700cbfe96697b22a7119ee87cf4
BLAKE2b-256 195474341f0627751ec4ffa9cb2269a902e089ba1065ae323bad0c674737bd4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page