Skip to main content

require_api_key

Function require_api_key 

Source
pub async fn require_api_key(
    keys: &ApiKeys,
    headers: &HeaderMap,
    scope: &str,
) -> Result<ApiKeyPrincipal, Problem>
Expand description

The per-request gate, the API-key sibling of cratefield_core::require_admin: reads Authorization: Bearer <token>, verifies it against keys, and demands scope. A missing header, malformed token, unknown prefix, revoked key or wrong secret all answer 401 api-key-unauthorized, one uniform problem so a probe cannot tell which held; a valid key without scope answers 403 api-key-forbidden; a store failure answers 503 not-ready (generic detail — the error itself is only logged).

§Errors

The Problem described above; carry it straight into the handler’s Err.