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.
Import
from mandate import Cognito
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
await cog.register(
email='your-user@email.com', username='myuser', password='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.update_profile(
{
'address': 'foo'
}
)
Or as admin
await cog.admin_update_profile(
username='other-user',
attrs={'gender':'potato'}
)
Delete user
await cog.admin_delete_user(username='user.email@example.com')
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
Built Distribution
File details
Details for the file mandate-2.0.1.tar.gz
.
File metadata
- Download URL: mandate-2.0.1.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.7.12 Darwin/20.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00f54fd15164fdc67098d3603f8a3c07d3dad4cc085b04ee06a1821cf32ec9cd |
|
MD5 | 2b3e39ab81831e7f27467c1a448c1293 |
|
BLAKE2b-256 | c4ad58b093edd8cc71ed4a1c90275c23468851f5afbb255977521d677b066403 |
File details
Details for the file mandate-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: mandate-2.0.1-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.7.12 Darwin/20.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91fa2c88682da681ddc273fac2aa199f63a1f7213ee5db334f1b63827fe2120e |
|
MD5 | 1db9f5e2e4f78b10f980fc51178d281e |
|
BLAKE2b-256 | 9d75b0f2d346faa301d4f2b7321a60ec1e621b6eed3f1c61533d23de4b6dc796 |