https://github.com/raphaelbh/aws-apigateway-authorizer
Proof of concept to demonstrate how to create a API Authorizer with Cognito.
https://github.com/raphaelbh/aws-apigateway-authorizer
api apigateway authentication authorizer aws cloudformation cognito docker jwt
Last synced: about 2 months ago
JSON representation
Proof of concept to demonstrate how to create a API Authorizer with Cognito.
- Host: GitHub
- URL: https://github.com/raphaelbh/aws-apigateway-authorizer
- Owner: raphaelbh
- Created: 2022-01-27T11:31:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-04-13T21:39:14.000Z (about 4 years ago)
- Last Synced: 2025-01-25T20:11:28.612Z (over 1 year ago)
- Topics: api, apigateway, authentication, authorizer, aws, cloudformation, cognito, docker, jwt
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AWS API Authorizer + Cognito
[](#)
Proof of concept to demonstrate how to create a API Authorizer with Cognito.
Tech Stack:
- ApiGateway
- Cognito
- JWT
## Requirements
[](https://www.docker.com/)
## Installation
Update `bootstrap/docker-compose.yaml` with the correct env variables:
- `AWS_ACCESS_KEY_ID`
- `AWS_SECRET_ACCESS_KEY`
- `AWS_DEFAULT_REGION`
```bash
$ (cd bootstrap && docker-compose up)
```
## Usage
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`
Getting access token
```python
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
```python
import requests
headers = {'Authorization' : 'Bearer ' + $access_token}
response = requests.get($API_URL, headers=headers)
```
## Running Tests
Set the follow env variables (tests/.env)
- `API_URL`
```bash
$ export PYTHONPATH=application
$ pytest --cache-clear tests/
```
## Tech Stack
[](https://www.docker.com/)
[](https://www.python.org/)
[](https://aws.amazon.com/)
## Reference
- https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-integrate-with-cognito.html
## Feedback
If you have any feedback, please contact me at raphaeldias.ti@gmail.com
[](https://github.com/raphaelbh)
[](https://www.linkedin.com/in/raphaelbh/)