"""Where an app keeps its users: the one surface fleetmesh_auth needs from it.
fleetmesh_auth proves who someone is; the app hosting it decides who its users
are. A `UserDirectory` finds or creates the app's record for a proven pubkey,
names the keys the app itself runs as, and carries sessions into the app's own
session tables when it has any. `HostDirectory` (host_directory.py) adapts a
co-hosted host application engine; an app without users of its own passes
none.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, FrozenSet, List, Optional, Protocol, TypedDict
if TYPE_CHECKING:
from fleetmesh_auth.principal import AuthPrincipal
[docs]class UserRecord(TypedDict):
user_id: str
handle: str
display_name: str
roles: List[str]
[docs]class UserDirectory(Protocol):
[docs] def own_pubkeys(self) -> FrozenSet[str]:
"""Pubkeys the app runs as (operator, node): they sign in as operators."""
...
[docs] def find_user(self, pubkey_hex: str) -> Optional[UserRecord]:
"""The app's user for this pubkey, if it has one."""
...
[docs] def create_user(self, pubkey_hex: str, handle_hint: Optional[str]) -> Optional[UserRecord]:
"""Make a user for a pubkey seen for the first time; None if the app declines."""
...
[docs] def link_session(
self,
token: str,
principal: "AuthPrincipal",
issued_at: int,
expires_at: int,
operator_pubkeys: FrozenSet[str],
) -> None:
"""Make `token` a session in the app's own tables too (no-op if it keeps none)."""
...
[docs] def has_session(self, token: str) -> bool:
...
[docs] def resolve_session(self, token: str, now: int, ttl_sec: int) -> Optional["AuthPrincipal"]:
"""A session (or API key) the app issued itself, as a principal."""
...
[docs] def revoke_session(self, token: str) -> None:
...
[docs] def default_db_path(self) -> Optional[str]:
"""Where fleetmesh_auth's own database should live beside the app's, if anywhere."""
...