https://github.com/raphaelbh/aws-cognito
Proof of concept to demonstrate how to use AWS Cognito.
https://github.com/raphaelbh/aws-cognito
access-token auth authentication authorization aws cognito docker python user-pool
Last synced: 2 months ago
JSON representation
Proof of concept to demonstrate how to use AWS Cognito.
- Host: GitHub
- URL: https://github.com/raphaelbh/aws-cognito
- Owner: raphaelbh
- License: mit
- Created: 2022-01-24T20:42:34.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-02-25T11:58:22.000Z (about 3 years ago)
- Last Synced: 2025-01-25T20:11:28.652Z (4 months ago)
- Topics: access-token, auth, authentication, authorization, aws, cognito, docker, python, user-pool
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AWS Cognito
[](#)
[](#)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
[](https://www.docker.com/)
## Installation
```bash
# 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 VariablesSet 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
```python
import services.cognito as cognitouser = {
'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
```bash
$ export PYTHONPATH=application
$ pytest --cache-clear tests/
```## Tech Stack
[](https://www.docker.com/)
[](https://aws.amazon.com/)## Reference
- 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## Feedback
If you have any feedback, please contact me at [email protected]
[](https://github.com/raphaelbh)
[](https://www.linkedin.com/in/raphaelbh/)