Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

JSON Web Token C++ lib

branch: master
Octocat-spinner-32 src Yeah. signing works! February 02, 2012
Octocat-spinner-32 Makefile import some code January 31, 2012
Octocat-spinner-32 README.rst README formatting January 31, 2012
Octocat-spinner-32 TODO Yeah. signing works! February 02, 2012
README.rst

JSON Web Tokens C++ lib

Warning

This library is a work in progress. It's not ready for production yet.

This lib exposes a simple class to work with signed JSON Web Tokens (JWT). It had been developped by Mozilla while making a C++ implementation of BrowserID.

JSON Web Tokens (JWT) are described in this document

Installation

Running make and make install should do the trick.

Dependencies

You need to have the following library installed on your system:

  • cryptopp for the crypto related stuff
  • jansson to deal with json

How to use it?

Once installed, jwtcpp provides a bunch of functions and methods so you can extract information about the JSON Web Tokens.

Here is an example application showing how you can use the library:

# include "jwtcpp.h"

using namespace std;

// It is possible to create a JWT from a string and to interact with it

JWT* jwt = JWT::fromString();
cout << jwt->algorithm << endl;
cout << jwt->signature << endl;
cout << jwt->signed_data << endl;

json_t* payload = jwt->payload;

// It is also possible to create a JWT programatically and then serialize
// it as a string
string serialized = jwt->generate(key);

// There is also a static method available if you want to directly
// serialize a mapping
Jwt* jwt = JWT::generate(mapping, key);

jwtcpp also provides a cli application able to generate and decode JWT. You can invoke it like this:

$ jwtcpp --generate --key=path/to/key.crt --data="{'json data': true}"
XXX the output here

$ jwtcpp --extract | cat token.jwt
XXX output

$ jwtcpp --extract --data "yourcontenthere"
XXX output
Something went wrong with that request. Please try again.