mcpp index

compat.jwt-cpp

#include

jwt-cpp 0.7.2 — header-only JSON Web Token (JWT) library for C++, backed by OpenSSL

#include <jwt-cpp/jwt.h>
mcpp add compat.jwt-cpp@0.7.2

Usage

From this repository's own test project — built and run by CI, not written for the website.

// Behavioral test: HS256 sign -> decode -> verify through compat.openssl.
// The correct key and claim must pass; a wrong key must be rejected. This is
// the end-to-end assertion that the package's OpenSSL wiring actually links
// and computes, not just that headers exist.
#include <jwt-cpp/jwt.h>
#include <chrono>
#include <string>

int main() {
    bool ok = true;

    const auto token = jwt::create()
                           .set_payload_claim("sub", jwt::claim(std::string("alice")))
                           // Boolean claims need the JSON value spelled out: a
                           // bare `jwt::claim(true)` would need TWO user-defined
                           // conversions (bool -> picojson::value -> claim).
                           .set_payload_claim(
                               "admin",
                               jwt::claim(jwt::traits::kazuho_picojson::value_type(true)))
                           .set_expires_at(std::chrono::system_clock::now() +
                                           std::chrono::seconds{3600})
                           .sign(jwt::algorithm::hs256{"secret-key"});
// …

tests/examples/jwt-cpp/tests/jwt.cpp · project tests/examples/jwt-cpp

Build

targets
jwt_cpp (lib)
language
c++20
import std
no
include dirs
*/include

Sources (1)

  • mcpp_generated/jwt_cpp_anchor.cpp

Generated files

  • mcpp_generated/jwt_cpp_anchor.cpp

Versions

VersionPlatforms Mirrorssha256
0.7.2 latest LinuxWindowsmacOS source 6e815d86c168…