
Quick Start for libjwt3
To whoever stumbles across this blog post after spending hours wondering how to pull a claim from JWT using this library...fear not. Your journey has come to an end. You have found the promised land. Jokes aside, I spent way too long combing through the docs of this library trying to figure this out. For a C newbie like me, LibJWT's docs aren't the easiest to parse. But to any other C newbies out there, or anyone confused by the docs I hope this helps. #include <jwt.h> struct Payload { char * user_name ; }; char * create_jwt ( struct Payload * payload ) { jwt_builder_t * builder = jwt_builder_new (); if ( builder == NULL ) { printf ( "Failed to create JWT builder \n " ); return NULL ; } jwt_value_t user_name ; jwt_set_SET_STR ( & user_name , "user_name" , payload -> user_name ); jwt_builder_claim_set ( builder , & user_name ); char * token = jwt_builder_generate ( builder ); jwt_builder_free ( builder ); return token ; } static int verify_callback ( jwt_t * jwt , jwt_config_t * config
Continue reading on Dev.to
Opens in a new tab



