Skip to content

Commit

Permalink
Add basic auth as new authentication option
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl committed Nov 12, 2024
1 parent aaa589e commit 1b5284f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
"[email protected]": "$2y$10$ZgcGQlsvMoMRmmW4Y.nUVuVHc.vOJsOA7iXAPXWPFy9DX2S7oeTDa", # nosemgrep: generic.secrets.security.detected-bcrypt-hash.detected-bcrypt-hash
},
)

ui = MesopUI(auth=auth)
{% else %}
ui = MesopUI()
Expand Down

0 comments on commit 1b5284f

Please sign in to comment.