parse authentik issuer path correctly

This commit is contained in:
2026-04-03 19:24:54 +02:00
parent 7e5f2bb06a
commit ba0612efb8

View File

@@ -1,8 +1,8 @@
from __future__ import annotations
import time
from functools import cached_property
from typing import Any
from urllib.parse import urlparse, urlunparse
import httpx
from jose import JWTError, jwt
@@ -24,10 +24,22 @@ class TokenValidationError(Exception):
def _normalize_issuer(value: str | None) -> str | None:
if not value:
return None
normalized = value.strip().rstrip("/")
normalized = normalized.replace("/application/o/authorize/", "/application/o/")
normalized = normalized.replace("/application/o/authorize", "/application/o")
normalized = normalized.replace("//application", "/application")
parsed = urlparse(value.strip())
path = parsed.path.rstrip("/")
if not path:
return urlunparse((parsed.scheme, parsed.netloc, "", "", "", ""))
segments = [segment for segment in path.split("/") if segment]
if (
len(segments) >= 4
and segments[0] == "application"
and segments[1] == "o"
and segments[2] == "authorize"
):
segments.pop(2)
normalized_path = "/" + "/".join(segments)
normalized = urlunparse(
(parsed.scheme, parsed.netloc, normalized_path.rstrip("/"), "", "", "")
)
return normalized.rstrip("/")