Skip to content

Commit

Permalink
Add check for the OIDC configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Rusakov committed Oct 1, 2024
1 parent da7b66a commit e000f9e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion default_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import requests
from dotenv import load_dotenv
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import gettext_lazy as _

load_dotenv()
Expand Down Expand Up @@ -306,7 +307,18 @@ def discover_endpoints(discovery_url: str) -> dict:
"django.contrib.auth.backends.ModelBackend",
)

OIDC_ENABLED = os.environ.get("OIDC_ENABLED", "False") == "True"
def check_oidc() -> bool:
if os.environ.get("OIDC_ENABLED", "False") == "False":
return False
missing = []
for x in ["OIDC_RP_CLIENT_ID", "ZITADEL_PROJECT", "OIDC_OP_BASE_URL", "OIDC_PRIVATE_KEYFILE"]:
if not os.environ.get(x):
missing.append(x)
if missing:
raise ImproperlyConfigured(f"OIDC is enabled, but missing required parameters {missing}")
return True

OIDC_ENABLED = check_oidc()
if OIDC_ENABLED:
INSTALLED_APPS.append('mozilla_django_oidc')
MIDDLEWARE.append('mozilla_django_oidc.middleware.SessionRefresh')
Expand Down

0 comments on commit e000f9e

Please sign in to comment.