Skip to Content
🎉 BSH Engine v0.0.7 is out with new features and improvements. See what's new →

Rotate Signing Key

Replace the active signing key now. Optionally, expire the previous keys at the same time, for example when a key has leaked.

POST /api/auth/signing-keys/rotate

Request Body

The body is optional. Without it, the previous key stays valid.

{ "expire": "previous", "reason": "Key exposed in application logs" }
FieldTypeRequiredDescription
expirestringnoKeys to expire right away: none, previous or all.
reasonstringwhen expire isn’t noneWhy the key is rotated.
expireEffect
noneThe previous key becomes Retired and keeps verifying its tokens. No one is logged out.
previousThe key that was active becomes Expired. Every user holding tokens signed by it is logged out.
allEvery retired key becomes Expired. Every user holding tokens signed by them is logged out.

Response

Success Response (200 OK):

{ "code": 200, "message": "JWT signing key rotated", "data": [ { "active": { "kid": "bb06fe1b-...", "status": "Active", ... }, "previous": { "kid": "a82791af-...", ... "status": "Expired", "reason": "Key exposed in application logs" }, "expired": ["a82791af-..."], "sessionReissued": true } ], "meta": { "type": "Signing Key Rotation" } }
FieldDescription
activeThe new active key
previousThe key that was active before, if any
expiredIDs of the keys expired by this rotation
sessionReissuedtrue when your own tokens were signed by an expired key and were re-issued

When sessionReissued is true, the new tokens are delivered like a refresh: in the auth cookies, and in meta.accessToken / meta.refreshToken for JSON clients. Clients that store tokens themselves must save them.

Error Responses

409 Conflict - Another manual rotation happened less than 60 seconds ago:

{ "code": 409, "error": "The JWT signing key was manually rotated less than 60 seconds ago", "meta": { "type": "Signing Key Rotation" } }
  • Expiring keys cannot be undone. Users holding tokens signed by them have to log in again.
  • API keys are not JWTs: they keep working after any rotation.
  • Scheduled rotation still happens every auth.config.secretTtl days, counted from the new key’s activation.
Last updated on