fix: replace url script was too rigid

This commit is contained in:
gabdevele
2026-06-17 19:23:38 +02:00 Unverified
parent 5f02ef6548
commit b8554830e4
+12 -7
View File
@@ -9,15 +9,20 @@ ROOT = pathlib.Path(__file__).resolve().parents[1]
def env(name: str, default: str = "") -> str:
value = os.getenv(name, default).strip()
if not value:
raise SystemExit(f"missing env: {name}")
return value.rstrip("/")
return os.getenv(name, default).strip().rstrip("/")
def infer_base_url(kind: str) -> str:
hosts = env("DJANGO_ALLOWED_HOSTS") or env("CIE_AUTH_ALLOWED_HOSTS")
items = [host.strip() for host in hosts.split(",") if host.strip() and host.strip() != "*"]
for host in items:
if kind in host:
return f"https://{host}"
raise SystemExit(f"missing env for {kind}: set explicit base URL or include hostname in allowed hosts")
TA = env("DJANGO_TRUST_ANCHOR")
PROVIDER_ISSUER = env("DJANGO_PROVIDER_ISSUER")
RP_BASE = env("DJANGO_RP_BASE_URL")
TA = env("DJANGO_TRUST_ANCHOR") or infer_base_url("fa")
PROVIDER_ISSUER = env("DJANGO_PROVIDER_ISSUER") or f"{infer_base_url('provider')}/oidc/op"
RP_BASE = env("DJANGO_RP_BASE_URL") or infer_base_url("rp")
RP_ISSUER = f"{RP_BASE}/oidc/rp"
PROVIDER_BASE = PROVIDER_ISSUER.removesuffix("/oidc/op")