- Establish typed Identity domain model with origin integrity validation - Define AuthPort protocol establishing current_identity, login, and logout contracts - Add unit tests verifying AuthPort protocol conformance and Identity domain invariants
33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
from typing import Optional, Protocol, runtime_checkable
|
|
|
|
from fastapi import Request, Response
|
|
|
|
from .identity import Identity
|
|
|
|
|
|
@runtime_checkable
|
|
class AuthPort(Protocol):
|
|
"""Hexagonal Port for Authentication and Identity Management.
|
|
|
|
Establishes the boundary between application domain logic and concrete authentication
|
|
mechanisms (such as OIDC, OAuth, ForwardAuth, or session providers).
|
|
"""
|
|
|
|
def current_identity(self, request: Request) -> Optional[Identity]:
|
|
"""Resolve the validated identity associated with the incoming request.
|
|
|
|
Returns None if the request is unauthenticated or credentials/session are invalid.
|
|
"""
|
|
...
|
|
|
|
def login(self, request: Request) -> Response:
|
|
"""Initiate the login flow (e.g. redirect to identity provider or challenge response)."""
|
|
...
|
|
|
|
def logout(self, request: Request) -> Response:
|
|
"""Terminate the session or logout flow (e.g. invalidate session cookie or IdP logout redirect)."""
|
|
...
|
|
|
|
|
|
__all__ = ["AuthPort", "Identity"]
|