It is a premise of a project that has been Dokcerized once. Last time: Application development with Docker + Python + Flask
├── api
| └── auth.api
├── requirements.txt
└── docker-compose.yaml
auth.py
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash
import os
auth = HTTPBasicAuth()
users = {
os.getenv("BASIC_AUTH_USER"): generate_password_hash(os.getenv("BASIC_AUTH_PASSWORD"))
}
@auth.verify_password
def verify_password(username, password):
if username in users:
return check_password_hash(users.get(username), password)
return False
python
from api.auth import auth
#abridgement
@route('/')
@auth.login_required
def add():
#abridgement
Add @ auth.login_required
to routes that require basic authentication.
docker-compose.yaml
version: '3'
services:
api:
container_name: tool-api
#abridgement
environment:
BASIC_AUTH_USER: "user"
BASIC_AUTH_PASSWORD: "password"
Set the eye path used in ʻauth.py` to an environment variable.
requirements.txt
#abridgement
flask_httpauth
Add the required modules.
Run
$ docker-compose up
Recommended Posts