From 0b7a8218e7abe0ebcd2abd7ef952133385df322c Mon Sep 17 00:00:00 2001 From: Tobias Quadfasel Date: Tue, 3 Sep 2024 16:03:35 +0200 Subject: [PATCH 1/2] feat(auth): Add dash-auth package In order to be able to authenticate with the app, a simple approach using dash-auth with environment-based secrets is used for now. --- poetry.lock | 21 ++++++++++++++++++++- pyproject.toml | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 25a3107..81adf6d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -294,6 +294,25 @@ dev = ["PyYAML (>=5.4.1)", "coloredlogs (>=15.0.1)", "fire (>=0.4.0)"] diskcache = ["diskcache (>=5.2.1)", "multiprocess (>=0.70.12)", "psutil (>=5.8.0)"] testing = ["beautifulsoup4 (>=4.8.2)", "cryptography", "dash-testing-stub (>=0.0.2)", "lxml (>=4.6.2)", "multiprocess (>=0.70.12)", "percy (>=2.0.2)", "psutil (>=5.8.0)", "pytest (>=6.0.2)", "requests[security] (>=2.21.0)", "selenium (>=3.141.0,<=4.2.0)", "waitress (>=1.4.4)"] +[[package]] +name = "dash-auth" +version = "2.3.0" +description = "Dash Authorization Package." +optional = false +python-versions = ">=3.8" +files = [ + {file = "dash_auth-2.3.0-py3-none-any.whl", hash = "sha256:2fa72d4ee128b4f9cf0c958157a986ffcd0b93d43b54d64e3cef5976ab7e0abe"}, + {file = "dash_auth-2.3.0.tar.gz", hash = "sha256:72df43248c15e121f8d5d710981e880deb2df546b564f2951a10ca50d7d92f6d"}, +] + +[package.dependencies] +dash = ">=1.1.1" +flask = "*" +werkzeug = "*" + +[package.extras] +oidc = ["authlib"] + [[package]] name = "dash-core-components" version = "2.0.0" @@ -2143,4 +2162,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "a6af9cf3858b3e05a3ac81716c79d6a3ed8e797da13391b2fc3e8c383741d00b" +content-hash = "ba2dd726c43c7c463de4924ac99d989972a002033106b6918824eaee0100bb03" diff --git a/pyproject.toml b/pyproject.toml index 061a0aa..17ad0f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ gunicorn = "^23.0.0" pyodbc = "^5.1.0" pandas = "^2.2.2" openai = "^1.43.0" +dash-auth = "^2.3.0" [tool.poetry.group.docs.dependencies] mkdocs = "^1.6.0" From 60206f48ef142f1f69af02b1855ba0f339b0743b Mon Sep 17 00:00:00 2001 From: Tobias Quadfasel Date: Tue, 3 Sep 2024 16:05:18 +0200 Subject: [PATCH 2/2] feat(auth): Add basic authentication to app --- app/app.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/app.py b/app/app.py index 9b97855..8cf7baa 100644 --- a/app/app.py +++ b/app/app.py @@ -1,6 +1,8 @@ import json +import os from typing import Any, Dict, Tuple +import dash_auth import pandas as pd from app_styles import header_style from dash import ( @@ -22,6 +24,10 @@ from sql_utils import execute_query, test_db_connection external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"] app = Dash(__name__, external_stylesheets=external_stylesheets) +auth = dash_auth.BasicAuth( + app, + {os.getenv("APP_UNAME"): os.getenv("APP_PW")}, +) app.index_string = header_style notification_md = """