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.
What Token Vault sends
POST /v1/refresh-notify, signed with the webhook's HMAC secret. Wire-level schema: webhook endpoints.
| Field | Type | Notes |
|---|---|---|
service | string | The credential name |
reason | string | manual_request when you press Refresh. (token_expiring is defined in the protocol but Token Vault does not currently send it) |
expiresAt | ISO 8601 | Optional |
refreshHint | object | Optional: {provider, tokenUrl, clientId}. Never a secret |
requestId | string | Correlation 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
oauthhint{provider, tokenUrl, clientId}. Refresh then works under any credential name. The client secret lives only in the webhook'sOAUTH_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-notifywithreason: 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-refreshtokens, 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"{ "success": true, "serviceName": "github", "refreshMode": "webhook_delegated" }Add ?recheck=true to try again even while the service is marked reconnect-required.
| HTTP | Code | When |
|---|---|---|
| 404 | REFRESH_NO_TOKEN | No token is stored on the webhook for this name |
| 409 | REFRESH_RECONNECT_REQUIRED | The provider revoked the grant (Token Vault's own check, or your webhook replied reconnectRequired: true). Reconnect, or pass recheck=true |
| 412 | REFRESH_NO_REFRESH_TOKEN | The stored token has no refresh token |
| 412 | (bare detail) | Webhook not configured. |
| 424 | REFRESH_NO_OAUTH_CLIENT | Not refreshed: your webhook has no OAuth client for this provider. Add it to OAUTH_PROVIDERS_JSON on the webhook |
| 424 | REFRESH_FAILED_AT_WEBHOOK | The 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 |
| 429 | WEBHOOK_RATE_LIMITED / RATE_LIMITED | Your webhook, or Token Vault's 10 per hour limit. Retry-After is set |
| 503 | WEBHOOK_CIRCUIT_OPEN | The webhook failed repeatedly and is paused. Retry-After is set |
| 502 | (bare detail) | The notify call failed |
tvault tokens refresh github # CLIWhen 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.
| Marker | Meaning | Where you see it |
|---|---|---|
refreshError | Short reason of the last failed attempt | The credential page: "Your webhook's last refresh of this credential failed: ..." |
refreshFailedAt | When it failed | Same line |
refreshReconnect | The provider revoked the grant | A 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.
| Situation | What pauses | What clears it |
|---|---|---|
| Your webhook is unreachable. 3 consecutive hourly failures | The whole scheduled run for your account | Re-binding a webhook, any successful manual refresh, or a clean scheduled run |
| One credential keeps failing while the webhook answers | Only that credential. Others keep refreshing | A 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_REQUIRED | Reconnect 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.
Rate limits
Every rate limit Token Vault enforces, covering per-entity floors, the account-wide ceiling, per-IP limits, the penalty box and how to back off.
OAuth Endpoint Reference
Every OAuth 2.1 endpoint for MCP clients with request and response shapes, including discovery, registration, authorize, token, refresh, revoke and the resource (audience) rules.