Key Rotation
Rotate JWT signing keys without invalidating in-flight tokens using the kid header.
The Rotation Pattern
// 1. Sign with kid stamped in the header
token = jwtCreate( { sub: "u1" }, "api-signing-v2", "RS256", {
headers: { kid: "v2" }
} );
// or with the fluent builder
token = jwtNew()
.subject( "u1" )
.expireIn( 3600 )
.header( "kid", "v2" )
.sign( "api-signing-v2", "RS256" );// 2 + 3. Verify with the right key per token
function verifyWithKeyRotation( token ) {
var decoded = jwtDecode( token ); // header only — claims NOT trusted yet
var kid = decoded.header.kid ?: "default";
return jwtVerify( token, kid, decoded.header.alg ); // looks up "kid" in the registry
}Registry-Driven Rotation
Verifying Tokens From External Issuers
Runtime Rotation From a KMS
Caveats
Related
Last updated
Was this helpful?
