Skip to content

Proof of concept to demonstrate how to use AWS Cognito.

License

Notifications You must be signed in to change notification settings

raphaelbh/aws-cognito

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Cognito

Project Status GitHub License

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

Requirements

docker

Installation

# 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

Environment Variables

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

Usage

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']

Tests

$ export PYTHONPATH=application 
$ pytest --cache-clear tests/

Tech Stack

docker aws

Reference

Feedback

If you have any feedback, please contact me at [email protected]

github linkedin