Token Storage
Grant tokens are RS256 JWTs. Where you store them depends on your threat model:| Strategy | When to use | Notes |
|---|---|---|
| In-memory | Short-lived agent tasks (minutes) | Token is lost on process restart — safest default |
| Encrypted session store | Multi-step workflows across requests | Use AES-256-GCM; never store tokens in plaintext |
| Encrypted cache (Redis) | High-throughput services sharing tokens | Set TTL to match token expiry; use TLS in transit |
Refresh Token Storage
Refresh tokens have a 30-day TTL and are single-use. Store them with the same care as API keys:- Encrypt at rest (e.g., envelope encryption with a KMS)
- Restrict access to the service that performs token refresh
- Never log refresh tokens — redact them in your logging pipeline
Scope Design
Design scopes using theresource:action pattern with least privilege:
- Request only what you need — agents should declare the minimum scopes required for their task
- Prefer read over write — if the agent only needs to read data, don’t request write access
- Use parameterized scopes —
payments:initiate:max_500is safer thanpayments:initiate - Review scope requests in the consent UI — users see exactly what the agent is requesting
Revocation Handling
Tokens can be revoked at any time by the user or developer. Your agent should handle revocation gracefully:- Listen for the
grant.revokedwebhook event to react in real time - On 401, do not retry — the token has been permanently invalidated
- Clean up any cached tokens after revocation
Delegation Security
When delegating grants to sub-agents (SPEC §9):- Minimize delegation depth — each layer adds risk. Keep
delegationDepthas low as possible - Always narrow scopes — the sub-agent should have fewer scopes than the parent
- Verify the chain — use
verifyGrantToken()to inspectparentAgentDidanddelegationDepthclaims - Set short expiry — delegated grants should expire before the parent grant
PKCE
Always use PKCE (Proof Key for Code Exchange) with S256 in production:Audit Trail Best Practices
The audit log is your forensic record. Use it proactively:- Log every sensitive action — file access, payment initiation, data deletion
- Include metadata — resource IDs, amounts, user-facing descriptions
- Use appropriate status values —
success,failure, orblocked - Query audit entries regularly — detect anomalies before they become incidents
- Enable the anomaly detection worker — it flags rate spikes, high failure rates, and off-hours activity automatically
Key Rotation
- Rotate your Grantex API key periodically using
POST /v1/me/rotate-key - After rotation, update all services that use the old key
- The old key is immediately invalidated — plan for a brief deployment window
Summary Checklist
Store tokens in memory or encrypted server-side stores
Use
resource:action scope format with least privilegeHandle 401 gracefully — never retry revoked tokens
Minimize delegation depth and always narrow scopes
Always use PKCE S256 in production
Log all sensitive agent actions to the audit trail
Enable webhooks for
grant.revoked eventsRotate API keys periodically