pycognito is a Python library that provides a simplified interface for interacting with AWS Cognito User Pools, wrapping Boto3's Cognito client. It includes built-in support for the Secure Remote Password (SRP) protocol, making user authentication straightforward. The current version is 2024.5.1, and it typically releases new versions monthly or bi-monthly, incorporating fixes and feature enhancements.
pip install pycognitoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `Cognito` client and authenticate a user using their username and password. It automatically handles the SRP (Secure Remote Password) protocol. Ensure you replace the placeholder values for `USER_POOL_ID`, `CLIENT_ID`, `USERNAME`, and `PASSWORD` with your actual Cognito credentials, ideally loaded from environment variables.
Ensure `PyJWT` is installed (it's a dependency) and review any custom JWT processing code. Most direct usage of `pycognito` should remain unaffected.
Upgrade your Python environment to version 3.8 or newer before installing or running `pycognito`.
Review calls to `admin_create_user` and `admin_reset_user_password` in your application. Consult the latest documentation or GitHub examples for required parameters, especially `client_metadata` and handling of temporary passwords.
Thoroughly test your MFA implementation. Follow the Cognito documentation and `pycognito` examples carefully for `associate_srp_mfa`, `verify_mfa`, and other MFA-related methods to ensure correct sequence and parameter handling.
Install the pycognito library using pip: `pip install pycognito`
Verify the username and password, ensure the user is confirmed in Cognito, confirm the client secret is correctly used if required by your app client, and check that tokens are valid and not expired. For `pycognito.Cognito` initialization, ensure `client_secret` is provided if the app client requires it.
Verify the user's existence and spelling of the username in the Cognito User Pool. If using aliases (email/phone), ensure the correct identifier is passed to the `pycognito` method, and consider checking if the user is confirmed. If 'Prevent user existence errors' is enabled on the app client, this error might be masked as `NotAuthorizedException`.
Review the specific `pycognito` method call and its arguments against the AWS Cognito API documentation for the expected parameter types and formats. Ensure all required parameters are present and correctly formatted.