OpenProgram Docs

Credential connection unification

One CredentialData replaces six payload classes. One resolve_connection() gives the wire layer everything a request needs, so a key can carry its own base URL. Design source: credential connection unification.

@dataclass
class CredentialData:
    kind: str
    auth_value: str = ""            # what to send
    base_url: str = ""
    headers: dict = field(default_factory=dict)
    data: dict = field(default_factory=dict)   # refresh tokens, file paths, flow ids

@dataclass
class ResolvedConnection:
    kind: str
    auth_value: str
    base_url: str | None
    headers: dict

Stored flat as {kind, auth_value, base_url, headers, data}, with no __type__. _payload_from_dict accepts only this. Credential.metadata and display information stay on Credential.

Resolution

Credentialresolve_connection returns
cli_delegatedReads its external file now, so the token is the freshest on disk
credential_processRuns its helper, cached for cache_seconds; a failing helper raises AuthCredentialProcessError rather than letting another credential stand in
ssoRaises AuthConfigError: no login flow implements it
No auth valueNone, and the caller falls back
Unsupported provider; Anthropic oauth, device_code or cli_delegated; any sk-ant-oat valueNone. Anthropic needs an API key

An empty base_url becomes None, separating "no endpoint" from "this endpoint". acquire_pooled(provider_id, account_id=None) returns (ResolvedConnection, str, str) | None. _extract_token remains as a thin reader over it.

At the wire layer the credential wins and the catalogue fills gaps:

base_url = (conn.base_url if conn and conn.base_url else None) or model.base_url
headers  = {**(opts.headers or {}), **(conn.headers if conn else {})}

OAuth detection reads conn.kind, not the token string.

Stored-credential carry-over

PartRule
WhatEvery old payload (a __type__ class included) becomes the flat shape, and every account file of a provider joins its one list, auth/<provider>/credentials.json
WhenOnce, before the store first reads; no command runs it
FailureThe whole auth folder is copied aside first; a failed step leaves the old files as they were and the next start runs it again
VersionCREDENTIAL_SCHEMA_VERSION is 4
Old class to new shape
Old test or fieldNow
isinstance(payload, ApiKeyPayload)payload.kind == "api_key"
isinstance(payload, OAuthPayload)payload.kind == "oauth"
isinstance(payload, (OAuthPayload, DeviceCodePayload))payload.kind in ("oauth", "device_code")
isinstance(payload, DeviceCodePayload)payload.kind == "device_code"
isinstance(payload, CliDelegatedPayload)payload.kind == "cli_delegated"
isinstance(payload, ExternalProcessPayload)payload.kind == "credential_process"
isinstance(payload, SsoPayload)payload.kind == "sso"
payload.access_token, payload.api_keypayload.auth_value
payload.refresh_tokenpayload.data.get("refresh_token", "")
payload.expires_at_mspayload.data.get("expires_at_ms", 0)
Other fields (store_path, client_id, …)payload.data.get(...)
ConstructorCredentialData
ApiKeyPayload(api_key=K)kind="api_key", auth_value=K
OAuthPayload(access_token=A, …)kind="oauth", auth_value=A; data: refresh_token, expires_at_ms, scope, client_id, token_endpoint, id_token, extra
DeviceCodePayload(access_token=A, …)kind="device_code", auth_value=A; data: refresh_token, expires_at_ms, device_code_flow_id, extra
CliDelegatedPayload(…)kind="cli_delegated"; data: store_path, access_key_path, refresh_key_path, expires_key_path
ExternalProcessPayload(…)kind="credential_process"; data: command, parses, json_key_path, cache_seconds

Implementation status

PartFile
CredentialData, schema versionopenprogram/models/auth/types.py
ResolvedConnection, resolve_connectionopenprogram/models/auth/resolver.py
Payload and layout carry-overopenprogram/models/auth/carry_over.py, run by store.py
CLIopenprogram/interfaces/cli/commands/providers/keys.py

The carry-over was rehearsed on a store with the real store's names and file shapes and placeholder values.

Last updated · 2026-11-25