LibJWT: Builder Functions

| LibJWT 3.3.2 The C JSON Web Token Library +JWK +JWKS

Builder Functions
JSON Web Token » Claims and Headers
Collaboration diagram for Builder Functions:

## Functions
jwt_value_error_t | jwt_builder_header_set (jwt_builder_t *builder, jwt_value_t *value)
| Set a header in a builder object.
jwt_value_error_t | jwt_builder_header_get (jwt_builder_t *builder, jwt_value_t *value)
| Get a header from a builder object.
jwt_value_error_t | jwt_builder_header_del (jwt_builder_t *builder, const char *header)
| Delete a header from a builder object.
jwt_value_error_t | jwt_builder_claim_set (jwt_builder_t *builder, jwt_value_t *value)
| Set a claim in a builder object.
jwt_value_error_t | jwt_builder_claim_get (jwt_builder_t *builder, jwt_value_t *value)
| Get a claim from a builder object.
jwt_value_error_t | jwt_builder_claim_del (jwt_builder_t *builder, const char *claim)
| Delete a header from a builder object.
int | jwt_builder_time_offset (jwt_builder_t *builder, jwt_claims_t claim, time_t secs)
| Disable, or enable and set the nbf or exp time offsets.

## Detailed Description

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.

## Function Documentation

## ◆ jwt_builder_claim_del()

jwt_value_error_t jwt_builder_claim_del | ( | jwt_builder_t * | builder,
|  | const char * | claim )

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()

jwt_value_error_t jwt_builder_claim_get | ( | jwt_builder_t * | builder,
|  | jwt_value_t * | value )

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()

jwt_value_error_t jwt_builder_claim_set | ( | jwt_builder_t * | builder,
|  | jwt_value_t * | value )

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()

jwt_value_error_t jwt_builder_header_del | ( | jwt_builder_t * | builder,
|  | const char * | header )

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()

jwt_value_error_t jwt_builder_header_get | ( | jwt_builder_t * | builder,
|  | jwt_value_t * | value )

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()

jwt_value_error_t jwt_builder_header_set | ( | jwt_builder_t * | builder,
|  | jwt_value_t * | value )

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()

int jwt_builder_time_offset | ( | jwt_builder_t * | builder,
|  | jwt_claims_t | claim,
|  | time_t | secs )

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