Proof of concept to demonstrate how to create a API Authorizer with Cognito.
Tech Stack:
- ApiGateway
- Cognito
- JWT
Update bootstrap/docker-compose.yaml with the correct env variables:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGION
$ (cd bootstrap && docker-compose up)Set the follow env variables (application/.env)
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGIONUSER_POOL_IDUSER_POOL_CLIENT_ID
Getting access token
import application.cognito as cognito
user = {
'username': 'raphaeldias.ti@gmail.com',
'password': 'Mudar@123'
}
jwt = cognito.initiate_auth(user)
access_token = jwt['body']['access_token'] Requesting api
import requests
headers = {'Authorization' : 'Bearer ' + $access_token}
response = requests.get($API_URL, headers=headers)Set the follow env variables (tests/.env)
API_URL
$ export PYTHONPATH=application
$ pytest --cache-clear tests/If you have any feedback, please contact me at raphaeldias.ti@gmail.com