For the builder function, you can create a set of values in the header and payload that will be copied verbatim to any token generated from it. The special claims, nbf
and exp
, can be handled more dynamically by LibJWT, if they are enabled (see jwt_builder_time_offset).
For any claims that you want to handle on a per token basis (e.g. you may want a different sub
depending on the user context), this can be done in a callback on the jwt_t object.
These functions rely on the Setters macros to better handle the data being passed to them.
◆ jwt_builder_claim_del()
Delete a header from a builder object.
- Parameters
-
builder | Pointer to a builder object |
claim | Name of the claim delete |
- Returns
- JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return on error.
◆ jwt_builder_claim_get()
Get a claim from a builder object.
- Parameters
-
builder | Pointer to a builder object |
value | Pointer to a jwt_value_t object representing the value to get |
- Returns
- JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return on error. Also, the relevant value.*_val will be set on success.
◆ jwt_builder_claim_set()
Set a claim in a builder object.
- Parameters
-
builder | Pointer to a builder object |
value | Pointer to a jwt_value_t object representing the value to set |
- Returns
- JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return on error.
◆ jwt_builder_header_del()
Delete a header from a builder object.
- Parameters
-
builder | Pointer to a builder object |
header | Name of the header delete |
- Returns
- JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return on error.
◆ jwt_builder_header_get()
Get a header from a builder object.
- Parameters
-
builder | Pointer to a builder object |
value | Pointer to a jwt_value_t object representing the value to get |
- Returns
- JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return on error. Also, the relevant value.*_val will be set on success.
◆ jwt_builder_header_set()
Set a header in a builder object.
- Parameters
-
builder | Pointer to a builder object |
value | Pointer to a jwt_value_t object representing the value to set |
- Returns
- JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return on error.
◆ jwt_builder_time_offset()
Disable, or enable and set the nbf
or exp
time offsets.
The time offset is in seconds and will be added to now
when a token is created. Negative values are not allowed. Setting the secs to 0 or less will disable adding the specified claim to the token.
- Parameters
-
builder | Pointer to a builder object |
claim | One of JWT_CLAIM_NBF or JWT_CLAIM_EXP |
secs | Seconds of offset to add to now when generating the specified claim |
- Returns
- 0 on success, any other value for an error