libjwt-2.1.0
JWT Grant Manipulation

These functions allow you to add, remove and retrieve grants from a JWT object. More...

Functions

const char * jwt_get_grant (jwt_t *jwt, const char *grant)
 Return the value of a string grant.
 
long jwt_get_grant_int (jwt_t *jwt, const char *grant)
 Return the value of an integer grant.
 
int jwt_get_grant_bool (jwt_t *jwt, const char *grant)
 Return the value of an boolean grant.
 
char * jwt_get_grants_json (jwt_t *jwt, const char *grant)
 Return the value of a grant as JSON encoded object string.
 
int jwt_add_grant (jwt_t *jwt, const char *grant, const char *val)
 Add a new string grant to this JWT object.
 
int jwt_add_grant_int (jwt_t *jwt, const char *grant, long val)
 Add a new integer grant to this JWT object.
 
int jwt_add_grant_bool (jwt_t *jwt, const char *grant, int val)
 Add a new boolean grant to this JWT object.
 
int jwt_add_grants_json (jwt_t *jwt, const char *json)
 Add grants from a JSON encoded object string.
 
int jwt_del_grants (jwt_t *jwt, const char *grant)
 Delete a grant from this JWT object.
 

Detailed Description

These functions allow you to add, remove and retrieve grants from a JWT object.

Function Documentation

◆ jwt_add_grant()

int jwt_add_grant ( jwt_t * jwt,
const char * grant,
const char * val )

Add a new string grant to this JWT object.

Creates a new grant for this object. The string for grant and val are copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a grant that already exists.

Parameters
jwtPointer to a JWT object.
grantString containing the name of the grant to add.
valString containing the value to be saved for grant. Can be an empty string, but cannot be NULL.
Returns
Returns 0 on success, valid errno otherwise.

Note, this only allows for string based grants. If you wish to add integer grants, then use jwt_add_grant_int(). If you wish to add more complex grants (e.g. an array), then use jwt_add_grants_json().

◆ jwt_add_grant_bool()

int jwt_add_grant_bool ( jwt_t * jwt,
const char * grant,
int val )

Add a new boolean grant to this JWT object.

Creates a new grant for this object. The string for grant is copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a grant that already exists.

Parameters
jwtPointer to a JWT object.
grantString containing the name of the grant to add.
valboolean containing the value to be saved for grant.
Returns
Returns 0 on success, valid errno otherwise.

Note, this only allows for boolean based grants. If you wish to add string grants, then use jwt_add_grant(). If you wish to add more complex grants (e.g. an array), then use jwt_add_grants_json().

◆ jwt_add_grant_int()

int jwt_add_grant_int ( jwt_t * jwt,
const char * grant,
long val )

Add a new integer grant to this JWT object.

Creates a new grant for this object. The string for grant is copied internally, so do not require that the pointer or string remain valid for the lifetime of this object. It is an error if you try to add a grant that already exists.

Parameters
jwtPointer to a JWT object.
grantString containing the name of the grant to add.
valint containing the value to be saved for grant.
Returns
Returns 0 on success, valid errno otherwise.

Note, this only allows for integer based grants. If you wish to add string grants, then use jwt_add_grant(). If you wish to add more complex grants (e.g. an array), then use jwt_add_grants_json().

◆ jwt_add_grants_json()

int jwt_add_grants_json ( jwt_t * jwt,
const char * json )

Add grants from a JSON encoded object string.

Loads a grant from an existing JSON encoded object string. Overwrites existing grant. If grant is NULL, then the JSON encoded string is assumed to be a JSON hash of all grants being added and will be merged into the grant listing.

Parameters
jwtPointer to a JWT object.
jsonString containing a JSON encoded object of grants.
Returns
Returns 0 on success, valid errno otherwise.

◆ jwt_del_grants()

int jwt_del_grants ( jwt_t * jwt,
const char * grant )

Delete a grant from this JWT object.

Deletes the named grant from this object. It is not an error if there is no grant matching the passed name. If grant is NULL, then all grants are deleted from this JWT.

Parameters
jwtPointer to a JWT object.
grantString containing the name of the grant to delete. If this is NULL, then all grants are deleted.
Returns
Returns 0 on success, valid errno otherwise.

◆ jwt_get_grant()

const char * jwt_get_grant ( jwt_t * jwt,
const char * grant )

Return the value of a string grant.

Returns the string value for a grant (e.g. "iss"). If it does not exist, NULL will be returned.

Parameters
jwtPointer to a JWT object.
grantString containing the name of the grant to return a value for.
Returns
Returns a string for the value, or NULL when not found.

Note, this will only return grants with JSON string values. Use jwt_get_grants_json() to get the JSON representation of more complex values (e.g. arrays) or use jwt_get_grant_int() to get simple integer values.

◆ jwt_get_grant_bool()

int jwt_get_grant_bool ( jwt_t * jwt,
const char * grant )

Return the value of an boolean grant.

Returns the int value for a grant (e.g. "exp"). If it does not exist, 0 will be returned.

Parameters
jwtPointer to a JWT object.
grantString containing the name of the grant to return a value for.
Returns
Returns a boolean for the value. Sets errno to ENOENT when not found.

Note, this will only return grants with JSON boolean values. Use jwt_get_grants_json() to get the JSON representation of more complex values (e.g. arrays) or use jwt_get_grant() to get string values.

◆ jwt_get_grant_int()

long jwt_get_grant_int ( jwt_t * jwt,
const char * grant )

Return the value of an integer grant.

Returns the int value for a grant (e.g. "exp"). If it does not exist, 0 will be returned.

Parameters
jwtPointer to a JWT object.
grantString containing the name of the grant to return a value for.
Returns
Returns an int for the value. Sets errno to ENOENT when not found.

Note, this will only return grants with JSON integer values. Use jwt_get_grants_json() to get the JSON representation of more complex values (e.g. arrays) or use jwt_get_grant() to get string values.

◆ jwt_get_grants_json()

char * jwt_get_grants_json ( jwt_t * jwt,
const char * grant )

Return the value of a grant as JSON encoded object string.

Returns the JSON encoded string value for a grant (e.g. "iss"). If it does not exist, NULL will be returned.

Parameters
jwtPointer to a JWT object.
grantString containing the name of the grant to return a value for. If this is NULL, all grants will be returned as a JSON encoded hash.
Returns
Returns a string for the value, or NULL when not found. The returned string must be freed by the caller.