Handler for deriving encryption context from authenticated user info.
Note: Must be an async function as it may involve I/O operations.
The context handler is called once per request in middleware (after auth), allowing encryption context to be derived from JWT claims, user properties, or other auth-derived data instead of requiring a separate X-Encryption-Context header.
The return value becomes ctx.metadata for subsequent encrypt/decrypt operations and is persisted with encrypted data for later decryption.
Note: ctx.model and ctx.field will be None in context handlers since the handler runs once per request before any specific model/field is known.
ContextHandler = Callable[['BaseUser', EncryptionContext], Awaitable[dict[str, typing.Any]]]| Name | Type | Description |
|---|---|---|
user* | unknown | The authenticated user (from Starlette's AuthenticationMiddleware) |
ctx* | unknown | Current encryption context with metadata from X-Encryption-Context header |