Builder

Builder for constructing a JwtPayload with standard and custom claims.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

The audience (aud) claim identifying the recipients that the token is intended for.

Link copied to clipboard

The expiration time (exp) claim, expressed as an epoch-seconds timestamp.

Link copied to clipboard
var id: String?

The JWT ID (jti) claim providing a unique identifier for this token.

Link copied to clipboard

The issued-at (iat) claim identifying the time at which the token was issued.

Link copied to clipboard

The issuer (iss) claim identifying the principal that issued the token.

Link copied to clipboard

The not-before (nbf) claim; the token must not be accepted before this time.

Link copied to clipboard

The subject (sub) claim identifying the principal that is the subject of the token.

Functions

Link copied to clipboard
inline fun <T> claim(name: String, value: T)

Sets a typed claim, inferring the serializer from the reified type T.

fun claim(name: String, value: JsonElement?)

Sets a raw claim using a pre-built JsonElement, or removes it if value is null.

fun <T> claim(name: String, serializer: SerializationStrategy<T>, value: T?, jsonInstance: Json = Jwt.defaultJsonParser)

Sets a typed claim using an explicit SerializationStrategy.

Link copied to clipboard
fun expiresIn(duration: Duration)

Sets the expiration time (exp) claim relative to the current time.

Link copied to clipboard
fun issuedNow()

Sets the issued-at (iat) claim to the current time.

Link copied to clipboard

Sets the not-before (nbf) claim to the current time.

Link copied to clipboard

Sets the JWT ID (jti) claim to a randomly generated UUID.

Link copied to clipboard
inline fun <T> takeFrom(value: T)

Merges all fields from value into this builder, inferring the serializer from the reified type T.

fun <T> takeFrom(serializer: SerializationStrategy<T>, value: T, jsonInstance: Json = Jwt.defaultJsonParser)

Merges all fields from value into this builder, encoded using serializer.