What it does
The vault stores a user’s third-party OAuth connection encrypted at rest. An agent asks for a token at the moment it needs one. The vault checks that the agent may use the provider, that the user consented to the scopes, and that the connection holds them, then returns an access token and writes an audit row. The refresh token never leaves the vault.Set it up
node -e "console.log(require('crypto').randomBytes(32).toString('base64url'))".
Connect, consent, read
- The signed-in user calls
POST /auth/vault/connect/startwith{ "provider": "github" }and redirects the browser to the returnedurl. The provider sends them back toGET /auth/vault/callback/github, which stores the encrypted connection. - The user grants an agent access:
POST /auth/vault/consentswith{ agentId, provider, scopes }. Only the agent’s owner can do this. PassdelegationChainIdto tie the consent to a delegation chain. - The agent needs a permission on the resource
vault:githubwith actionuse, either its own or delegated.
{ success: false, error: { code } }. Codes: VAULT_AGENT_INACTIVE, VAULT_PERMISSION_DENIED, VAULT_CONSENT_REQUIRED, VAULT_NOT_CONNECTED, VAULT_REAUTH_REQUIRED, VAULT_SCOPE_NOT_GRANTED, VAULT_REFRESH_FAILED, VAULT_DECRYPT_FAILED.
Security model
- Tokens are sealed with AES-256-GCM. Each envelope is bound to its row and column through authenticated data, so a ciphertext copied to another user’s row does not decrypt.
- The tenant is taken from the agent, not the caller. An agent in tenant A cannot reach a connection stored for tenant B or for no tenant.
- Scopes only narrow. A request must be a subset of both the consent and the connection. The provider token itself still carries the connection’s full scope: the vault enforces the narrowing, the provider does not.
- Every read, allowed or denied, is an audit row (
vault.read) holding the provider and scopes, never a token. If the audit write fails, no token is returned. - Revoking a delegation with
theauth.delegation.revoke()revokes consents tied to that chain. Reads also re-check that the chain is active, so cascaded child chains stop working too. - Refresh uses a lock in
secondaryStorageso concurrent reads trigger one refresh. Stores that cannot increment atomically (Workers KV) reduce this to best effort. - Provider error bodies are never logged or returned.
Rotate the encryption key
Add a new key, make it active, keep the old one, then re-encrypt:rotateKeys() reports zero on a second run, drop k1 from the config.
Provider presets
Notion and Atlassian are not preset because their token endpoints are documented with JSON bodies, which the vault refresh does not send.
providerPresets and resolveProviderPreset(id, { clientId, clientSecret }) return the URLs and authStyle; pass authStyle in the provider config to match.
Check a preset against the real provider
Run one refresh grant with your own test credentials to confirm a preset works against the live provider. The script never prints token values.--dry-run to print the request shape (URL, auth style, header names, body keys) with values masked. Nothing is sent.
On success the output shows the HTTP status, whether an access token came back, expires_in, whether the provider rotated the refresh token, and the scope string. On failure it exits 1 and prints error=<code>, the provider’s OAuth error code such as invalid_grant, never the response body.
Run it by hand against a test app. CI never runs it.
Not included
RFC 8693 token exchange and an HTTP endpoint for agents to fetch tokens are not part of this release.getAccessToken is an in-process call. The older theauth_oauth_accounts table stores provider tokens in plaintext and is unchanged.