Skip to main content

Module send_access_token_cache

Module send_access_token_cache 

Source
Expand description

Persistent cache for Send access tokens, so repeat bw receive / bw send receive calls for the same Send within a token’s validity window don’t re-prompt for a password or OTP.

Keyed on (resolved_host, send_id), not send_id alone. resolved_host is whatever receive::resolve_urls decided to talk to for this invocation, so a cached token can never be looked up under a host other than the one it was actually minted against. This is deliberate: legacy’s own cache (default-send-token.service.ts) is keyed on sendId alone with no host component, which is part of what PM-40120 tracks — this cache does not replicate that.

A malformed, unreadable, or unwritable cache file never fails the caller: the cache is an optimization over minting a fresh token, not something bw receive depends on to function.

This module has no notion of trust — it will cache anything a caller asks it to. The restriction to trusted hosts only (matching the corresponding TS client fix) is enforced at the call site in receive::run_receive, gated on the trusted flag resolve_urls returns.

Structs§

CacheFile 🔒
CachedToken 🔒

Constants§

EXPIRY_SLACK_MS 🔒
Milliseconds of slack subtracted from a token’s real expiry before treating a cached entry as usable, so a cache hit doesn’t get used moments before the server would reject it anyway. Mirrors the legacy CLI’s 5-second threshold (SendAccessToken.isExpired).

Functions§

cache_key 🔒
cache_path 🔒
evict 🔒
Evicts a cached entry, e.g. after the server rejects a token the cache believed was still valid (clock skew, or server-side revocation before natural expiry).
get 🔒
Returns a cached, still-valid token for (resolved_host, send_id), if any.
read_cache_from 🔒
set 🔒
Caches token for (resolved_host, send_id), expiring at expires_at (epoch-ms, matching [bitwarden_auth::send_access::SendAccessTokenResponse::expires_at]).
write_cache_to 🔒