Secure Messaging
Secure messaging is the SPAPS surface for practitioner and patient messaging workflows that should travel through the shared backend instead of app-local ad hoc endpoints. The reusable package includes a gateway abstraction, while the SPAPS app mounts the concrete secure_messages domain router.
Mental Model
Gateway Responsibilities
| Piece | Location | Purpose |
|---|---|---|
SecureMessagingGateway | secure_messaging.py | Validates context, builds client calls, and normalizes errors |
build_secure_messaging_gateway | secure_messaging.py | Constructs a gateway from settings and optional client injection |
secure_messages_router | domains/secure_messages/router.py | Exposes the concrete SPAPS API endpoints |
CurrentUser route dependency | domains/secure_messages/router.py | Unconditionally requires authenticated user identity |
Example Dependency Shape
from spaps_server_quickstart.secure_messaging import build_secure_messaging_gateway
# `settings` comes from the service settings dependency; `user` is the
# authenticated user dependency and must not be replaced by app identity.
gateway = build_secure_messaging_gateway(settings=settings, user=user)Common Mistakes
Secure-message routes unconditionally require CurrentUser. The similarly named
secure_messages_require_jwt settings projection is compatibility metadata, not a router bypass.
Do not treat it as an authorization control.
- Treating API-key application identity as a substitute for user identity.
- Returning raw client exceptions instead of normalized gateway errors.
- Testing against a real messaging backend instead of injecting a fake client.