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๏
set_algorithm(alg: String) |
|
set_audience(aud: String) |
|
set_expiration(seconds_from_now: float) |
|
set_issuer(iss: String) |
|
set_jwt_id(jti: String) |
|
set_subject(sub: String) |
|
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.