hubvault.server.auth
Token parsing and authorization helpers for hubvault.server.
This module keeps bearer-token parsing and access-level checks independent from the FastAPI app factory so the authorization policy can be tested without API extras installed.
The module contains:
AuthContext- Resolved token identity for one requestTokenAuthorizer- Read/write token resolverparse_request_token()- Header parser for supported token inputs
AuthContext
- class hubvault.server.auth.AuthContext(access: str, token: str)[source]
Resolved token identity for one request.
- Parameters:
access (str) – Access level string, currently
"ro"or"rw"token (str) – Original bearer token text
- property can_write: bool
Whether the token grants write access.
- Returns:
Truewhen the token carries read-write permissions- Return type:
bool
parse_request_token
- hubvault.server.auth.parse_request_token(authorization: str | None = None, x_hubvault_token: str | None = None, query_token: str | None = None) str | None[source]
Extract a token from supported request inputs.
X-HubVault-Tokentakes precedence overAuthorization, and the optional query-string token acts as a final read-only fallback for browser resource URLs that cannot attach authorization headers.- Parameters:
authorization (Optional[str]) – Raw
Authorizationheader valuex_hubvault_token (Optional[str]) – Raw
X-HubVault-Tokenheader valuequery_token (Optional[str]) – Raw
tokenquery-string value
- Returns:
Normalized token string or
Nonewhen no supported token is present- Return type:
Optional[str]
build_read_auth_dependency
- hubvault.server.auth.build_read_auth_dependency(authorizer: TokenAuthorizer)[source]
Create a FastAPI dependency that enforces read access.
- Parameters:
authorizer (TokenAuthorizer) – Token authorizer shared by the server app
- Returns:
FastAPI dependency callable that returns
AuthContext- Return type:
Callable[…, Awaitable[AuthContext]]
- Raises:
hubvault.optional.MissingOptionalDependencyError – Raised when the API extra is not installed.
build_write_auth_dependency
- hubvault.server.auth.build_write_auth_dependency(authorizer: TokenAuthorizer)[source]
Create a FastAPI dependency that enforces write access.
- Parameters:
authorizer (TokenAuthorizer) – Token authorizer shared by the server app
- Returns:
FastAPI dependency callable that returns
AuthContext- Return type:
Callable[…, Awaitable[AuthContext]]
- Raises:
hubvault.optional.MissingOptionalDependencyError – Raised when the API extra is not installed.