Proof of concept to demonstrate how to use AWS Cognito.
Amazon Cognito provides authentication, authorization, and user management for your web and mobile apps. Your users can sign in directly with a user name and password, or through a third party such as Facebook, Amazon, Google or Apple.
Features:
- sign up
- confirm sign up
- sign in (initiate auth)
- sign out (global)
- get user
- delete user
# aws-cli config
$ alias aws='docker run --rm -it -v ~/.aws:/root/.aws -v $(pwd):/aws amazon/aws-cli'
$ aws configure set aws_access_key_id ${your_aws_access_key_id}
$ aws configure set aws_secret_access_key ${your_aws_secret_access_key}
$ aws configure set region ${your_aws_default_region}
# create stack (user pool)
$ aws cloudformation create-stack --stack-name poc-cognito --template-body file://infrastructure/cloudformation/stack.yaml
# get user_pool_id and user_pool_client_id
$ aws cloudformation describe-stacks --stack-name poc-cognito
Set the follow env variables (./application/.env)
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
USER_POOL_ID
USER_POOL_CLIENT_ID
import services.cognito as cognito
user = {
'username': "[email protected]",
'password': 'john@password',
'attributes': [{
'Name': 'name',
'Value': "John Doe"
}, {
'Name': 'email',
'Value': "[email protected]"
}]
}
cognito.sign_up(user)
cognito.admin_confirm_sign_up(user)
response = cognito.initiate_auth(user)
access_token = response['body']['access_token']
$ export PYTHONPATH=application
$ pytest --cache-clear tests/
- https://docs.aws.amazon.com/cognito/latest/developerguide/what-is-amazon-cognito.html
- https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp.html
If you have any feedback, please contact me at [email protected]