INNER CODE UNIT · Python
create_auth_ticket
MakazhanAlpamys/Soup · src/soup_cli/ui/app.py:327
def create_auth_ticket() -> str:
"""Create a short-lived (30s) single-use ticket for SSE connection."""
ticket = secrets.token_urlsafe(32)
now = time.time()
with _tickets_lock:
_cleanup_expired_tickets()
_tickets[ticket] = now + 30.0
return ticket
def consume_auth_ticket(ticket: str) -> bool:
"""Consume a single-use ticket if valid and unexpired."""
if not ticket:
return False
now = time.time()
with _tickets_lock:
_cleanup_expired_tickets()
exp = _tickets.pop(ticket, None)