// HMAC with custom headers
token = jwtNew()
.subject( "alice" )
.claim( "tenant", "acme-corp" )
.expireIn( 900 )
.header( "kid", "signing-key-v2" )
.sign( secret, "HS256" );
// RSA with all standard claims
token = jwtNew()
.subject( "svc-account" )
.issuer( "auth-service" )
.audience( [ "api", "analytics" ] )
.issuedNow()
.expireIn( 3600 )
.jti( createUUID() )
.sign( privateKeyPem, "RS256" );
// JWE encryption
token = jwtNew()
.subject( "patient-456" )
.claim( "phi", { dob: "1990-01-15", ssn: "xxx-xx-1234" } )
.encrypt( secret, "dir", "A256GCM" );
// Re-use an existing payload struct
payload = { sub: "user-1", iss: "my-api", roles: [ "admin" ] };
token = jwtNew().withPayload( payload ).expireIn( 3600 ).sign( secret, "HS256" );