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
Pipfile
for dependency management. - Use
Flask-Restful
as the REST API framework. - Use
Flask-JWT-Extended
as the (opinionated) JWT framework. Including features likerefresh token
andtoken revoking
.
- Docker
- nginx
- gunicorn
- flask
- jwt
- Postgres
- redis (Used to store jwt token information)
- external
Postgres
- Dockerized
Postgres
for dev
Dev with dockerized Postgres
docker-compose --file docker-compose-dev.yml up --build
Stand up external Postgres
database
bash db/init.sh
Build containers
docker-compose up --build
Full clean up (remove Postgres
volume)
docker stop $(docker ps -a -q)
docker-compose rm -fs
docker system prune
rm -rf postgres_data
User 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 = True
Must 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
redis
for production