s365b.api.deps¶
Shared FastAPI dependencies: services, the signed-in user, roles and CSRF.
Attributes¶
Classes¶
The signed-in user for the current request. |
Functions¶
|
Return the services created at application startup. |
|
Return the client's IP address (Caddy's |
|
Return the signed-in user, enforcing CSRF on state-changing requests. |
|
Build a dependency that allows only the given roles (admins always pass). |
Module Contents¶
- s365b.api.deps.get_services(request: fastapi.Request) s365b.core.services.Services[source]¶
Return the services created at application startup.
- Parameters:
request – Current request.
- Returns:
The services.
- s365b.api.deps.client_ip(request: fastapi.Request) str | None[source]¶
Return the client’s IP address (Caddy’s
X-Forwarded-Foris honoured by uvicorn).- Parameters:
request – Current request.
- Returns:
The address, if known.
- class s365b.api.deps.Principal[source]¶
The signed-in user for the current request.
- Variables:
user_id – User ID.
username – Username (UPN for Entra users).
display_name – Display name.
role – Role for this session.
method – How they signed in.
csrf_token – Token state-changing requests must send back.
- async s365b.api.deps.current_principal(request: fastapi.Request, services: ServicesDep) Principal[source]¶
Return the signed-in user, enforcing CSRF on state-changing requests.
- Parameters:
request – Current request.
services – Process services.
- Returns:
The principal.
- Raises:
HTTPException – 401 if not signed in, 403 if the CSRF token is missing or wrong.
- s365b.api.deps.require_roles(*roles: s365b.db.models.UserRole) collections.abc.Callable[[Principal], collections.abc.Awaitable[Principal]][source]¶
Build a dependency that allows only the given roles (admins always pass).
- Parameters:
*roles – Roles allowed in addition to admin.
- Returns:
A FastAPI dependency returning the principal.