Token VaultDocs
Reference

Token Refresh

How OAuth tokens stay fresh, covering webhook-autonomous refresh, the notify call Token Vault sends, the manual refresh endpoint and its errors, and the pause that stops a loop nobody can fix.

OAuth tokens expire. Your webhook refreshes them: it holds the refresh token and the OAuth client credentials, and it calls the provider. Your webhook must refresh on its own timer. Token Vault sends a notification only when someone presses Refresh. This page is the single home for how refresh works.

On every current path, no credential material crosses Token Vault during refresh. The one exception is the legacy tv-refresh capability, used only for tokens from Token Vault's old built-in OAuth apps.

Loading diagram...

What Token Vault sends

POST /v1/refresh-notify, signed with the webhook's HMAC secret. Wire-level schema: webhook endpoints.

FieldTypeNotes
servicestringThe credential name
reasonstringmanual_request when you press Refresh. (token_expiring is defined in the protocol but Token Vault does not currently send it)
expiresAtISO 8601Optional
refreshHintobjectOptional: {provider, tokenUrl, clientId}. Never a secret
requestIdstringCorrelation id

The webhook answers with a status: refreshed (done, with newExpiresAt), acknowledged, no_token, no_refresh_token, refresh_failed or error. Only refreshed counts as success. acknowledged means your webhook has no OAuth client for that provider, so it did nothing, and Token Vault says so (see the errors table under the refresh endpoint below). A refresh_failed reply can carry a short error and reconnectRequired: true when the provider revoked the grant (spec 2.8.0).

The webhook should send its client secret only to a token URL from its own configuration or a built-in table. The hint's tokenUrl is a cross-check, not an instruction.

Who supplies the client credentials

You do. There are two ways to get an OAuth token onto the webhook:

  • Your own OAuth app (OAuth apps): the provider redirects to your webhook, which stores the token and a non-secret oauth hint {provider, tokenUrl, clientId}. Refresh then works under any credential name. The client secret lives only in the webhook's OAUTH_PROVIDERS_JSON.
  • Paste a token with its refresh token (credential type JWT). Your webhook needs the provider's client credentials configured to refresh it.

Connecting through Token Vault's own OAuth app is turned off. POST /api/oauth/{google|github|spotify}/exchange returns 410 OAUTH_CONNECT_DISABLED, because it put your tokens in Token Vault. See the OAuth apps API.

Credentials with no refresh path (API keys, personal access tokens) are rotated at the provider and updated with Rotate in the web app or tvault set. The value goes from the browser or CLI to your webhook directly.

When refresh runs

  • Autonomous (the normal path). Your webhook refreshes tokens on its own timer, with the client credentials it holds. A token connected with your own OAuth app is also refreshed when it is fetched within about 5 minutes of expiry. Token Vault does not refresh these tokens; its hourly sweep only reads the failure markers (below).
  • On demand. Pressing Refresh now in the web app, or calling the API below, sends /v1/refresh-notify with reason: manual_request. The notification is a hint, not a command. The button shows on any credential that has a refresh token, or that your webhook refreshes with your own OAuth app, not only on Token Vault's old built-in connections.
  • Legacy sweep. The hourly sweep acts only on legacy tv-refresh tokens, refreshing those that expire within 75 minutes.

POST /api/tokens/{service}/refresh

Refresh one credential now. Scope: tokens:update. Needs the kill switch off. Limited to 10 per hour per credential.

curl -s -X POST "https://api.tokenvault.uk/api/tokens/github/refresh" \
  -H "Authorization: Bearer $TVKEY"
200 OK
{ "success": true, "serviceName": "github", "refreshMode": "webhook_delegated" }

Add ?recheck=true to try again even while the service is marked reconnect-required.

HTTPCodeWhen
404REFRESH_NO_TOKENNo token is stored on the webhook for this name
409REFRESH_RECONNECT_REQUIREDThe provider revoked the grant (Token Vault's own check, or your webhook replied reconnectRequired: true). Reconnect, or pass recheck=true
412REFRESH_NO_REFRESH_TOKENThe stored token has no refresh token
412(bare detail)Webhook not configured.
424REFRESH_NO_OAUTH_CLIENTNot refreshed: your webhook has no OAuth client for this provider. Add it to OAUTH_PROVIDERS_JSON on the webhook
424REFRESH_FAILED_AT_WEBHOOKThe webhook answered but the refresh failed. The message includes the webhook's short reason when it gave one. Check the provider connection on the webhook
429WEBHOOK_RATE_LIMITED / RATE_LIMITEDYour webhook, or Token Vault's 10 per hour limit. Retry-After is set
503WEBHOOK_CIRCUIT_OPENThe webhook failed repeatedly and is paused. Retry-After is set
502(bare detail)The notify call failed
tvault tokens refresh github        # CLI

When your webhook's own refresh fails

A webhook that refreshes on its own timer records the outcome in the token's plaintext meta (spec 2.8.0), which Token Vault reads with the credential list. No token is involved.

MarkerMeaningWhere you see it
refreshErrorShort reason of the last failed attemptThe credential page: "Your webhook's last refresh of this credential failed: ..."
refreshFailedAtWhen it failedSame line
refreshReconnectThe provider revoked the grantA Reconnect needed chip on the credential and in the list, at once. The hourly sweep then turns it into an inbox message (with Reconnect and Check again) and an email when email is enabled

A later successful refresh removes the markers. Storing a new token or reconnecting replaces the document, which clears them too. A plain refreshError is a failed attempt your webhook will retry; it does not stop anything and does not page you. Only refreshReconnect needs you.

Reconnect opens the Add credential page for that credential in Connect your OAuth app mode; the new token is written to your webhook directly. The hourly check reads the token list of accounts whose refresh is fully webhook-handled too (one listing call), for these markers only; a webhook that does not answer flags nothing. A reconnect that has started makes the check ignore a marker older than the start, so an old marker cannot re-flag a credential you are already reconnecting. Webhooks older than spec 2.8.0 never write the markers, so a revoked grant there shows up only when you press Refresh now.

When refresh stops

This section applies to the legacy sweep and to on-demand refresh. Retrying cannot fix some failures, so Token Vault pauses and posts a notice in your inbox. Pausing is not permanent and revokes nothing.

SituationWhat pausesWhat clears it
Your webhook is unreachable. 3 consecutive hourly failuresThe whole scheduled run for your accountRe-binding a webhook, any successful manual refresh, or a clean scheduled run
One credential keeps failing while the webhook answersOnly that credential. Others keep refreshingA successful refresh of that credential (including "check again"), a reconnect, or storing a new token for it
The provider revoked the grant (invalid_grant)That credential, at once. On-demand refresh answers 409 REFRESH_RECONNECT_REQUIREDReconnect it, or "check again" in the inbox

Only a success clears a pause, and a success for one credential never clears another.

Legacy: tv-refresh

Tokens that were minted with Token Vault's old built-in OAuth clients (Google, GitHub, Spotify) use a two-phase tv-refresh flow (POST /v1/refresh). Token Vault asks the webhook for the refresh token, calls the provider with its own client secret, and sends the new tokens back, in transit only and never stored. This is the one path where a credential value transits Token Vault.

The reference webhook advertises tv-refresh only when you set TV_REFRESH_ENABLED=true. It is never used for a token stored by ticket or connected with your own OAuth app. A webhook without the tv-refresh capability has no such path.

A reference webhook deployed before this default changed still advertises it. If you still have a token from those old apps, that token stops refreshing when the capability goes away. Before you update, set TV_REFRESH_ENABLED=true, or connect the credential again with your own OAuth app. After you change the variable, press Verify Connection so Token Vault reads the capabilities again.

Ready to try it?

Sign in with Google or email. Your credentials stay on your own webhook, and the quickstart gets Claude Code making its first MCP tool call in about 15 minutes.

On this page