JWT-CPP v0.7.0
A header only library for creating and validating JSON Web Tokens (JWT) in C++
Loading...
Searching...
No Matches
Installation

There's a number of options to choice from.

Overview

It's strongly recommended to use a package manager, as JWT-CPP has dependencies for both cryptography and JSON libraries, having a tool to do the heavily lifting can be ideal. Examples of a C and C++ package manager are Conan and vcpkg. If the version is out of date please check with their respective communities before opening and issue here.

When manually adding this dependency, and the dependencies this has, check the GitHub Actions and Workflows for some inspiration about how to go about it.

Package Manager

Looking for ways to contribute? Help by adding JWT-CPP to your favorite package manager! Nixpkgs for example. Currently many are behind the latest.

Header Only

Simply downloading the include/ directory is possible. Make sure the jwt-cpp/ subdirectories is visible during compilation. This does require correctly linking to OpenSSL or alternative cryptography library.

The minimum is jwt.h but you will need to add the defines:

In addition to providing your own JSON traits implementation, see traits.md for more information.

CMake

Using find_package is recommended. Step you environment by installing OpenSSL. Once complete, configure and install the jwt-cpp target using CMake.

A simple installation of JWT-CPP may look like

cmake .
cmake --build . # Make sure everything compiles and links together
cmake --install .

Then from your own project

find_package(jwt-cpp CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE jwt-cpp::jwt-cpp)

Unsupported Alternatives

There's also the possibility of using FetchContent in pull this this project to your build tree.

include(FetchContent)
fetchcontent_declare(jwt-cpp
GIT_REPOSITORY https://github.com/Thalhammer/jwt-cpp.git
GIT_TAG 08bcf77a687fb06e34138e9e9fa12a4ecbe12332 # v0.7.0 release
)
set(JWT_BUILD_EXAMPLES OFF CACHE BOOL "disable building examples" FORCE)
fetchcontent_makeavailable(jwt-cpp)
target_link_libraries(my_app PRIVATE jwt-cpp::jwt-cpp)

Lastly, you can use add_subdirectory, this is untested but should work.