neosourceDocs
Search docs

Rotate a personal access token's secret

POST/api/user/tokens/{token_id}/rotate

rotatePersonalAccessToken

Replaces the token's secret in place, keeping its id, label, and grant. The old secret is invalidated immediately; the new raw value is returned once. Expiry is re-stamped to 90 days. Requires sudo-mode unless the account has no step-up credential and therefore cannot acquire sudo.

Requires authentication using a session cookie — see tokens and scopes.

curl

curl -X POST 'https://neosource.dev/api/user/tokens/TOKEN_ID/rotate' \
  -b 'ns_session=$NEOSOURCE_SESSION'

fetch

fetch("https://neosource.dev/api/user/tokens/TOKEN_ID/rotate", {
  method: "POST",
  credentials: "include",
});

neo

neo token rotate TOKEN_ID

Path parameters

token_idrequired

Token ID to revoke.

string

Responses

200Rotated

application/json

RotateTokenResponse

object

Response for `POST /api/user/tokens/{id}/rotate` — a fresh secret plus the (unchanged or re-stamped) expiry. The token id is stable across rotation.

expires_at

integer | nullint64

raw_tokenrequired

string

403Forbidden — one of: forbidden, sudo_required

application/json

one of
  • ErrorForbidden
  • SudoRequiredError

    object

    Wire shape of the 403 a sudo-gated endpoint returns when sudo is missing or expired. `challenge` tells the SPA which sudo-prove endpoint to call.

    challengerequired

    string

    Which sudo-prove endpoint the account should use: `"passkey"` (`/api/auth/sudo/passkey/{start,finish}`), `"password"` (`/api/auth/sudo/password`), or `"totp"` (`/api/auth/sudo/totp`), chosen from the account's registered credentials — passkey first when present, since it is both the strongest credential and the least friction. A hint for which prompt to show first, not an authorization decision: each sudo route verifies its own credential regardless of what was advertised here, so a client may use a different one.

    errorrequired

    string

    Always `sudo_required` — this body exists to carry the extra fields that kind needs.

    "sudo_required"

    messagerequired

    string

Standard errors

Bodies documented once for the whole API — see standard errors.

  • 400Bad Request — one of: invalid_input
  • 401Authentication required
  • 429Rate limited — retry after the `Retry-After` header
  • 500Internal server error
  • 503Service temporarily unavailable / at capacity — retry after the `Retry-After` header
  • 504Gateway timeout — the request exceeded the server's handling budget