Create registration links on the same host (subdomain) that is being used by the one who creates it.

This commit is contained in:
Leo Vasanko
2025-10-02 12:30:50 -06:00
parent eb38995cca
commit fbfd0bbb47
3 changed files with 34 additions and 6 deletions
+24
View File
@@ -0,0 +1,24 @@
"""Utilities for host validation and origin determination."""
from ..globals import passkey as global_passkey
def effective_origin(scheme: str, host: str | None, rp_id: str) -> str:
"""Determine the effective origin for a request.
Uses the provided host if it's compatible with the relying party ID,
otherwise falls back to the configured origin.
Args:
scheme: The URL scheme (e.g. "https")
host: The host header value (e.g. "example.com" or "sub.example.com:8080")
rp_id: The relying party ID (e.g. "example.com")
Returns:
The effective origin URL to use
"""
if host:
hostname = host.split(":")[0] # Remove port if present
if hostname == rp_id or hostname.endswith(f".{rp_id}"):
return f"{scheme}://{host}"
return global_passkey.instance.origin