Setting an expiration date
Pass anexpires_at field in ISO 8601 format when creating a token. Tooken enforces this deadline precisely: requests authenticated with the token after this timestamp are rejected immediately.
expires_at, the token never expires automatically. In most cases you should set an expiration — see the best practices section below.
What happens when a token expires
Whenexpires_at passes, Tooken transitions the token’s status to expired. Any request that presents this token receives a 401 Unauthorized response:
401 response
Rotating a token
Rotation generates a new secret for an existing token while preserving its ID, name, and scopes. Use rotation on a regular schedule so you replace credentials before they grow stale, without changing anything in your infrastructure that references the token ID. CallPOST /tokens/:id/rotate with your API key:
rotation response
Rotate vs. revoke: choosing the right action
| Situation | Action |
|---|---|
| Scheduled credential refresh | Rotate |
| Suspected or confirmed compromise | Revoke |
| Service is being decommissioned | Revoke |
| Scope change required | Revoke and re-create |
| Secret has aged past your policy limit | Rotate |
Rotation best practices
Define a rotation schedule before deploying
Decide how long each token type should live before its first rotation. Match the schedule to the token’s risk profile and access level.
Automate rotation for CI/CD pipelines
Short-lived tokens in CI environments — 24 to 72 hours — reduce the window of exposure from build log leaks. Trigger rotation at the start of each deployment pipeline using a provisioner token that holds the
tokens:rotate scope.Update secrets atomically
Fetch the new token value from the rotation response and write it to your secrets manager in the same step. Avoid any gap where the old secret is invalidated but the new one has not been deployed.
Expiration policy recommendations
CI/CD and automation
Set
expires_at to 24–72 hours. Rotate at the start of every pipeline run. These tokens are most exposed to log and environment leaks.Stable service integrations
Set
expires_at to 90 days and rotate on a scheduled basis (monthly or quarterly). Monitor last_used_at to detect stale tokens.Human-issued tokens
Set
expires_at to 30 days maximum. Require explicit renewal so unused tokens expire naturally rather than accumulating.Internal tooling
Treat like stable integrations. 90-day expiration with quarterly rotation, audited against the Tooken dashboard.
Frequently asked questions
What happens to requests made with an expired token?
What happens to requests made with an expired token?
Tooken rejects the request immediately and returns
401 Unauthorized with the message "Token has expired". The request does not reach any downstream system. Your service will need to catch this error and surface it — either by alerting an operator or by triggering an automated re-provisioning flow if your architecture supports it.Can I extend a token's expiration without rotating it?
Can I extend a token's expiration without rotating it?
No. Tooken does not support updating
expires_at on an existing token. To extend the credential’s lifetime, revoke the current token and create a new one with the desired expiration date and the same scopes. This intentional constraint keeps your audit log accurate — every token’s history is immutable once created.How do I get notified before a token expires?
How do I get notified before a token expires?
Configure a webhook on the
token.expiring event from the Tooken dashboard. Tooken fires this event 7 days and 1 day before a token’s expires_at timestamp. Your webhook receiver can trigger an alert, open a ticket, or kick off an automated rotation workflow. See the webhooks documentation for event payload details.