Tested on Mac, Linux, Windows
Docker + Flask + JWT boilerplate with gunicorn, nginx, and external (dockerized for dev) Postgres database. Good for quickly set up an authentication backend (for example for a frontend development). Implemented user registration, user login, access token, refresh token, and token revocation.
- Use
Pipfilefor dependency management. - Use
Flask-Restfulas the REST API framework. - Use
Flask-JWT-Extendedas the (opinionated) JWT framework. Including features likerefresh tokenandtoken revoking.
- Docker
- nginx
- gunicorn
- flask
- jwt
- Postgres
- redis (Used to store jwt token information)
- external
Postgres - Dockerized
Postgresfor dev
Dev with dockerized Postgres
docker-compose --file docker-compose-dev.yml up --buildStand up external Postgres database
bash db/init.shBuild containers
docker-compose up --buildFull clean up (remove Postgres volume)
docker stop $(docker ps -a -q)
docker-compose rm -fs
docker system prune
rm -rf postgres_dataUser Registration example
{
"email": "test@test.com",
"password": "12345"
}Example in Postman:
Set PROPAGATE_EXCEPTIONS to propagate exceptions from flask-jwt-extended
class Config:
...
PROPAGATE_EXCEPTIONS = TrueMust include Pipfile.lock for pipenv to install system-wide in docker
...
COPY Pipfile.lock /home/project/web
...Use host.docker.internal inside container to access host machine's localhost
DATABASE_URL=postgresql://dev:12345@host.docker.internal:5432/jwt- Should use external
redisfor production
