JWTBuilder๏ƒ

Inherits: RefCounted < Object

A fluent builder for constructing formatted JSON Web Tokens.

Description๏ƒ

Provides a chained syntax for configuring and signing JWTs, automatically handling UNIX timestamps and claim formatting.

var b = JWTBuilder.new().set_issuer('auth.local').set_subject('admin')
var str = b.sign('my_secret')

Methods๏ƒ

JWTBuilder

add_claim(key: String, val: Variant)

JWTBuilder

set_algorithm(alg: String)

JWTBuilder

set_audience(aud: String)

JWTBuilder

set_expiration(seconds_from_now: float)

JWTBuilder

set_issuer(iss: String)

JWTBuilder

set_jwt_id(jti: String)

JWTBuilder

set_subject(sub: String)

String

sign(key: Variant)


Method Descriptions๏ƒ

JWTBuilder add_claim(key: String, val: Variant) ๐Ÿ”—

Adds a custom key-value claim to the token's payload. Methods can be chained.


JWTBuilder set_algorithm(alg: String) ๐Ÿ”—

Sets the algorithm (alg) in the token's header. Common values are HS256 or RS256.


JWTBuilder set_audience(aud: String) ๐Ÿ”—

Sets the audience (aud) claim in the payload indicating the intended recipients.


JWTBuilder set_expiration(seconds_from_now: float) ๐Ÿ”—

Sets the expiration time (exp) claim in the payload to the specified number of seconds from now.


JWTBuilder set_issuer(iss: String) ๐Ÿ”—

Sets the issuer (iss) claim in the payload identifying the principal that issued the JWT.


JWTBuilder set_jwt_id(jti: String) ๐Ÿ”—

Sets the JWT ID (jti) claim in the payload, which provides a unique identifier for the token.


JWTBuilder set_subject(sub: String) ๐Ÿ”—

Sets the subject (sub) claim in the payload identifying the principal that is the subject of the JWT.


String sign(key: Variant) ๐Ÿ”—

Constructs and signs the JWT using the configured claims and header. Requires a String secret for HS256 or a CryptoKey for RS256.