JwtBuilder
Fluent builder for creating JWS (signed) and JWE (encrypted) compact tokens.
Example — signed:
val signingKey = SigningAlgorithm.HS256.newKey()
val token = Jwt.builder()
.subject("user123")
.issuer("myapp")
.expiration(Clock.System.now() + 1.hours)
.signWith(signingKey)Example — encrypted:
val encKey = EncryptionAlgorithm.RsaOaep256.newKey()
val token = Jwt.builder()
.subject("user123")
.encryptWith(encKey, EncryptionContentAlgorithm.A256GCM)Functions
Sets the audience (aud) claim.
Builds and returns an unsecured JWS token with alg=none and an empty signature.
Sets a typed claim, inferring the serializer from the reified type T.
Sets a raw claim using a pre-built JsonElement.
Sets a typed claim using an explicit SerializationStrategy.
Configures multiple claims at once using a DSL block applied to JwtPayload.Builder.
Sets the content type (cty) header parameter.
Looks up the public key from registry and builds a JWE compact serialization.
Suspends, encrypts the token using the given JweEncryptor, and returns the JWE compact serialization.
Sets the expiration time (exp) claim.
Sets the expiration time (exp) claim relative to the current time.
Merges all fields from value into the JOSE header, inferring the serializer from the reified type T.
Configures JOSE header fields using a DSL block applied to JwtHeader.Builder.
Sets a typed extra header parameter, inferring the serializer from the reified type T.
Sets a raw extra header parameter using a pre-built JsonElement.
Merges all fields from value into the JOSE header, encoded using serializer.
Sets a typed extra header parameter using an explicit SerializationStrategy.
Sets the JWT ID (jti) claim.
Sets the issued-at (iat) claim.
Sets the issued-at (iat) claim to the current time.
Sets the issuer (iss) claim.
Sets the not-before (nbf) claim.
Sets the not-before (nbf) claim to the current time.
Merges all fields from value into the payload, encoded using serializer.
Sets the JWT ID (jti) claim to a randomly generated UUID.
Suspends, signs the token using the given JwsSigner, and returns the JWS compact serialization.
Looks up the private key from registry and builds a JWS compact serialization.
Sets the subject (sub) claim.
Sets the token type (typ) header parameter.