Skip to content

Commit 32d599e

Browse files
committed
Lots of docs updated...about ready for a v3.0.0 release
Signed-off-by: Ben Collins <bcollins@libjwt.io>
1 parent da7dc6b commit 32d599e

File tree

2 files changed

+124
-10
lines changed

2 files changed

+124
-10
lines changed

include/jwt.h

Lines changed: 123 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ typedef enum {
152152
JWT_VALUE_INT, /**< Integer */
153153
JWT_VALUE_STR, /**< String */
154154
JWT_VALUE_BOOL, /**< Boolean */
155-
JWT_VALUE_JSON, /**< JSON String (object format ``{}``) */
155+
JWT_VALUE_JSON, /**< JSON String (``{..}`` or ``[..]``) */
156156
JWT_VALUE_INVALID, /**< Invalid (used internally) */
157157
} jwt_value_type_t;
158158

@@ -825,28 +825,106 @@ int jwt_checker_verify(jwt_checker_t *checker, const char *token);
825825
/**
826826
* @defgroup jwt_claims_builder_grp Builder Functions
827827
*
828-
* @todo document these
828+
* For the builder function, you can create a set of values in the header and
829+
* payload that will be copied verbatim to any token generated from it. The
830+
* special claims, ``nbf`` and ``exp``, can be handled more dynamically by
831+
* LibJWT, if they are enabled (see jwt_builder_time_offset).
832+
*
833+
* For any claims that you want to handle on a per token basis (e.g. you may
834+
* want a different ``sub`` depending on the user context), this can be done in
835+
* a callback on the jwt_t object.
836+
*
837+
* These functions rely on the @ref jwt_helpers_set_grp macros to better handle
838+
* the data being passed to them.
839+
*
829840
* @{
830841
*/
842+
843+
/**
844+
* @brief Set a header in a builder object
845+
*
846+
* @param builder Pointer to a builder object
847+
* @param value Pointer to a jwt_value_t object representing the value to set
848+
* @return JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return
849+
* on error.
850+
*/
831851
JWT_EXPORT
832852
jwt_value_error_t jwt_builder_header_set(jwt_builder_t *builder, jwt_value_t
833853
*value);
854+
855+
/**
856+
* @brief Get a header from a builder object
857+
*
858+
* @param builder Pointer to a builder object
859+
* @param value Pointer to a jwt_value_t object representing the value to get
860+
* @return JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return
861+
* on error. Also, the relevant value.*_val will be set on success.
862+
*/
834863
JWT_EXPORT
835864
jwt_value_error_t jwt_builder_header_get(jwt_builder_t *builder, jwt_value_t
836865
*value);
866+
867+
/**
868+
* @brief Delete a header from a builder object
869+
*
870+
* @param builder Pointer to a builder object
871+
* @param header Name of the header delete
872+
* @return JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return
873+
* on error.
874+
*/
837875
JWT_EXPORT
838876
jwt_value_error_t jwt_builder_header_del(jwt_builder_t *builder, const char
839877
*header);
878+
879+
/**
880+
* @brief Set a claim in a builder object
881+
*
882+
* @param builder Pointer to a builder object
883+
* @param value Pointer to a jwt_value_t object representing the value to set
884+
* @return JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return
885+
* on error.
886+
*/
840887
JWT_EXPORT
841888
jwt_value_error_t jwt_builder_claim_set(jwt_builder_t *builder, jwt_value_t
842889
*value);
890+
891+
/**
892+
* @brief Get a claim from a builder object
893+
*
894+
* @param builder Pointer to a builder object
895+
* @param value Pointer to a jwt_value_t object representing the value to get
896+
* @return JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return
897+
* on error. Also, the relevant value.*_val will be set on success.
898+
*/
843899
JWT_EXPORT
844900
jwt_value_error_t jwt_builder_claim_get(jwt_builder_t *builder, jwt_value_t
845901
*value);
902+
903+
/**
904+
* @brief Delete a header from a builder object
905+
*
906+
* @param builder Pointer to a builder object
907+
* @param claim Name of the claim delete
908+
* @return JWT_VALUE_ERR_NONE on success, one of the jwt_value_error_t return
909+
* on error.
910+
*/
846911
JWT_EXPORT
847912
jwt_value_error_t jwt_builder_claim_del(jwt_builder_t *builder, const char
848913
*claim);
849914

915+
/**
916+
* @brief Disable, or enable and set the ``nbf`` or ``exp`` time offsets
917+
*
918+
* The time offset is in seconds and will be added to ``now`` when a token is
919+
* created. Negative values are not allowed. Setting the secs to 0 or less will
920+
* disable adding the specified claim to the token.
921+
*
922+
* @param builder Pointer to a builder object
923+
* @param claim One of JWT_CLAIM_NBF or JWT_CLAIM_EXP
924+
* @param secs Seconds of offset to add to ``now`` when generating the
925+
* specified claim
926+
* @return 0 on success, any other value for an error
927+
*/
850928
JWT_EXPORT
851929
int jwt_builder_time_offset(jwt_builder_t *builder, jwt_claims_t claim,
852930
time_t secs);
@@ -881,19 +959,54 @@ int jwt_builder_time_offset(jwt_builder_t *builder, jwt_claims_t claim,
881959
* the exception of the ``alg`` element when validating a token. Anything you
882960
* need to do there can be done in a callback with the jwt_t.
883961
*
884-
* @todo Document all of these
885962
* @{
886963
*/
964+
965+
/**
966+
* @brief Get the value of a validation claim
967+
*
968+
* @param checker Pointer to a checker object
969+
* @param type One of JWT_CLAIM_ISS, JWT_CLAIM_AUD, or JWT_CLAIM_SUB
970+
* @return A string representation of the claim, or NULL if it isn't set
971+
*/
887972
JWT_EXPORT
888973
const char *jwt_checker_claim_get(jwt_checker_t *checker, jwt_claims_t type);
889974

975+
/**
976+
* @brief Set the value of a validation claim
977+
*
978+
* @param checker Pointer to a checker object
979+
* @param type One of JWT_CLAIM_ISS, JWT_CLAIM_AUD, or JWT_CLAIM_SUB
980+
* @param value A string to set as the new value of the validation
981+
* @return 0 on success, any other value is an error
982+
*/
890983
JWT_EXPORT
891984
int jwt_checker_claim_set(jwt_checker_t *checker, jwt_claims_t type,
892985
const char *value);
893986

987+
/**
988+
* @brief Delete the value of a validation claim
989+
*
990+
* @param checker Pointer to a checker object
991+
* @param type One of JWT_CLAIM_ISS, JWT_CLAIM_AUD, or JWT_CLAIM_SUB
992+
* @return 0 on success, any other value is an error
993+
*/
894994
JWT_EXPORT
895995
int jwt_checker_claim_del(jwt_checker_t *checker, jwt_claims_t type);
896996

997+
/**
998+
* @brief Setup the exp or nbf claim leeway values
999+
*
1000+
* This allows you to set a leeway for exp and nbf claims to account for any
1001+
* skew. The value is in seconds.
1002+
*
1003+
* To disable either one, set the secs to -1.
1004+
*
1005+
* @param checker Pointer to a checker object
1006+
* @param claim One of JWT_CLAIM_NBF or JWT_CLAIM_EXP
1007+
* @param secs The number of seconds of leeway to account for being valid
1008+
* @return 0 on success, any other value is an error
1009+
*/
8971010
JWT_EXPORT
8981011
int jwt_checker_time_leeway(jwt_checker_t *checker, jwt_claims_t claim,
8991012
time_t secs);
@@ -904,7 +1017,7 @@ int jwt_checker_time_leeway(jwt_checker_t *checker, jwt_claims_t claim,
9041017
*/
9051018

9061019
/**
907-
* @defgroup jwt_object_grp JWT Claims and Headers
1020+
* @defgroup jwt_object_grp JWT Functions
9081021
*
9091022
* For most usage, setting values in the builder object is enough to provide
9101023
* all the information you would like set in a JWT token. However, if some
@@ -1023,7 +1136,7 @@ const char *jwt_alg_str(jwt_alg_t alg);
10231136
* @returns Returns a @ref jwt_alg_t matching the string
10241137
* or @ref JWT_ALG_INVAL if no matches were found.
10251138
*
1026-
* Note, this only works for algorithms that LibJWT supports or knows about.
1139+
* @note This only works for algorithms that LibJWT supports or knows about.
10271140
*/
10281141
JWT_EXPORT
10291142
jwt_alg_t jwt_str_alg(const char *alg);
@@ -1189,8 +1302,9 @@ JWT_EXPORT
11891302
int jwks_error_any(jwk_set_t *jwk_set);
11901303

11911304
/**
1192-
* @brief Retrieve an error message from a jwk_set. Note, a zero
1193-
* length string is valid if jwos_error() returns non-zero.
1305+
* @brief Retrieve an error message from a jwk_set
1306+
*
1307+
* @note A zero length string is valid even if jwks_error() returns non-zero.
11941308
*
11951309
* @param jwk_set An existing jwk_set_t
11961310
* @return A string message. The string may be empty.
@@ -1443,8 +1557,8 @@ int jwks_item_free_all(jwk_set_t *jwk_set);
14431557
* any of the parameters or NULL to use the corresponding default
14441558
* allocator function.
14451559
*
1446-
* Note that this function will also set the memory allocator
1447-
* for the Jansson library.
1560+
* @note This function will also set the memory allocator for the Jansson
1561+
* library.
14481562
*
14491563
* @param pmalloc The function to use for allocating memory or
14501564
* NULL to use malloc

tests/jwt_flipflop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ START_TEST(test_alloc_funcs)
6161
ck_assert(r == test_realloc);
6262
ck_assert(f == test_free);
6363

64-
/* XXX Need to do a build/verify to excercise the functions */
64+
/* XXX Need to do a build/verify to exercise the functions */
6565
}
6666
END_TEST
6767

0 commit comments

Comments
 (0)