diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 981d26d..d9d8aa8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: matrix: python-version: ["3.12", "3.11", "3.10"] app-type: ["fastapi+mesop", "mesop", "nats+fastapi+mesop"] - authentication: ["google", "none"] + authentication: ["none", "google", "basic"] fail-fast: false runs-on: ubuntu-latest timeout-minutes: 15 diff --git a/cookiecutter.json b/cookiecutter.json index 2a74388..de846c7 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -3,5 +3,5 @@ "project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}", "app_type": ["fastapi+mesop", "mesop", "nats+fastapi+mesop"], "python_version": ["3.12", "3.11", "3.10"], - "authentication": ["none", "google"] + "authentication": ["none", "google", "basic"] } diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 182c350..c59858e 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -8,7 +8,7 @@ version = "0.1.0" name = "{{cookiecutter.project_slug}}" dependencies = [ - "fastagency[autogen,mesop,server{% if "fastapi" in cookiecutter.app_type %},fastapi{% endif %}{% if "nats" in cookiecutter.app_type %},nats{% endif %}{% if cookiecutter.authentication == "google" %},firebase{% endif %}]>=0.3.0", + "fastagency[autogen,mesop,server{% if "fastapi" in cookiecutter.app_type %},fastapi{% endif %}{% if "nats" in cookiecutter.app_type %},nats{% endif %}{% if cookiecutter.authentication == "google" %},firebase{% elif cookiecutter.authentication == "basic" %},basic_auth{% endif %}]>=0.3.0", {%- if cookiecutter.authentication == "google" %} "PyYAML>=6.0.2", {% endif %} diff --git "a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/deployment/main_{% if \"nats\" in cookiecutter.app_type %}3{% else %}2{% endif %}_mesop.py" "b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/deployment/main_{% if \"nats\" in cookiecutter.app_type %}3{% else %}2{% endif %}_mesop.py" index ac53660..1976c0e 100644 --- "a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/deployment/main_{% if \"nats\" in cookiecutter.app_type %}3{% else %}2{% endif %}_mesop.py" +++ "b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/deployment/main_{% if \"nats\" in cookiecutter.app_type %}3{% else %}2{% endif %}_mesop.py" @@ -6,7 +6,8 @@ from fastagency.adapters.fastapi import FastAPIAdapter from fastagency.app import FastAgency from fastagency.ui.mesop import MesopUI{% if cookiecutter.authentication == "google" %} -from fastagency.ui.mesop.auth.firebase import FirebaseAuth, FirebaseConfig{% endif %} +from fastagency.ui.mesop.auth.firebase import FirebaseAuth, FirebaseConfig{% elif cookiecutter.authentication == "basic" %} +from fastagency.ui.mesop.auth.basic_auth import BasicAuth{% endif %} fastapi_url = "http://localhost:8008" @@ -26,6 +27,19 @@ allowed_users=allowed_users, ) +ui = MesopUI(auth=auth) +{%- elif cookiecutter.authentication == "basic" %} +auth = BasicAuth( + # TODO: Replace `allowed_users` with the desired usernames and their + # bcrypt-hashed passwords. One way to generate bcrypt-hashed passwords + # is by using online tools such as https://bcrypt.online + # Default password for all users is `password` + allowed_users={ + "admin": "$2y$10$ZgcGQlsvMoMRmmW4Y.nUVuVHc.vOJsOA7iXAPXWPFy9DX2S7oeTDa", # nosemgrep: generic.secrets.security.detected-bcrypt-hash.detected-bcrypt-hash + "user@example.com": "$2y$10$ZgcGQlsvMoMRmmW4Y.nUVuVHc.vOJsOA7iXAPXWPFy9DX2S7oeTDa", # nosemgrep: generic.secrets.security.detected-bcrypt-hash.detected-bcrypt-hash + }, +) + ui = MesopUI(auth=auth) {% else %} ui = MesopUI()