Skip to content

API Reference parrot.services.vault_token_sync

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.services.vault_token_sync

View source

VaultTokenSync — store and retrieve OAuth tokens in the user's navigator Vault using a flat {provider}:{field} key scheme.

Works from non-HTTP contexts (e.g., the Telegram wrapper running under aiogram polling) by instantiating :class:navigator_session.vault.SessionVault directly via its load_for_session classmethod.

Providers served here: fireflies, workiq, entra. o365 is no longer served: O365 3LO and device-code grants share one principal-keyed record (FEAT-777); legacy o365:* keys are only read once for migration.

Jira no longer stores credentials in this vault. Its durable owner is navigator-auth's Identity Vault (auth.user_identities), written by JiraOAuthManager's credential sink, with Redis as the hot cache (FEAT-735). Keys written before that change are inert and were deliberately left in place. Do not add a Jira path back here — see wiki/integrations/auth/jira-credential-ownership.md.

Attribute TokenReadStatus

Class VaultCryptoError

Placeholder when navigator-session vault crypto is unavailable.

Class VaultTokenRead

Typed result of :meth:VaultTokenSync.read_tokens_result.

Parameter Type Default Description
tokens Optional[Dict[str, Any]]
status TokenReadStatus

Fields:

Field Type Default Description
tokens Optional[Dict[str, Any]] Field → value mapping when status == "ok", else None.
status TokenReadStatus ok (readable), missing (no keys stored), unreadable (stored but failed integrity/format checks) or unavailable (vault could not be loaded).

Attributes:

Attribute Type Description
needs_reconnect bool True when the provider must be re-linked (tokens exist but are unusable).

Class VaultTokenSync

Persist OAuth tokens in the encrypted user vault.

Parameter Type Default Description
db_pool Any The authdb asyncpg pool (app["authdb"]).
redis Any The shared Redis client (app["redis"]).
session_ttl int 3600 Vault session TTL in seconds (defaults to 1h).
session_scheme str _DEFAULT_SESSION_SCHEME Session-uuid scheme prefix passed to :func:_synth_session_uuid. Defaults to the legacy Telegram scheme ("telegram-persistent") — existing jira/fireflies/ workiq callers are unaffected. Non-Telegram surfaces (FEAT-266: the O365 device-code CLI resolver) pass a different scheme (e.g. "cli-persistent") so their tokens round-trip under a non-Telegram-namespaced key.

Method VaultTokenSync.store_tokens

Store each tokens[key] at {provider}:{key} in the vault.

Empty / None values are skipped to avoid clobbering existing keys with blanks. expires_at (when present) is written FIRST, so a mid-loop failure either leaves expires_at already correctly persisted, or leaves other fields (e.g. access_token) never written — a subsequent read cannot look "permanently valid" from a partial write (FEAT-267; no bulk/transactional vault write primitive exists, verified against SessionVault's public interface).

A distinguishable warning is logged (in addition to the existing exception log) when the loop does not persist every expected key.

store_tokens(nav_user_id: str, provider: str, tokens: Dict[str, Any]) -> None

Parameter Type Default Description
nav_user_id str
provider str
tokens Dict[str, Any]

Method VaultTokenSync.read_tokens_result

Read all {provider}:* keys, distinguishing absent from unreadable.

read_tokens_result(nav_user_id: str, provider: str) -> VaultTokenRead

Parameter Type Default Description
nav_user_id str Navigator user identifier.
provider str Vault key prefix (provider id).

Returns: VaultTokenRead — class:VaultTokenRead — ok with the tokens, missing when nothing is stored, unreadable when a stored token fails the vault's integrity/format checks (the provider must be re-linked), or unavailable when the vault could not be loaded.

Method VaultTokenSync.read_tokens

Read all {provider}:* keys from the user's vault.

read_tokens(nav_user_id: str, provider: str) -> Optional[Dict[str, Any]]

Parameter Type Default Description
nav_user_id str
provider str

Returns: Optional[Dict[str, Any]] — A dict of {field_name: value} (with provider prefix stripped), or None if the vault is unavailable, unreadable, or no keys exist. Use :meth:read_tokens_result to tell those apart.

Method VaultTokenSync.delete_tokens

Remove every {provider}:* key from the user's vault.

delete_tokens(nav_user_id: str, provider: str) -> None

Parameter Type Default Description
nav_user_id str
provider str

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally