luckfox-pico-sdk/project/app/ipcweb/ipcweb-backend/thirdparty/jwt-cpp
luckfox-eng29 8f34c2760d project:build.sh: Added fastboot support; custom modifications to U-Boot and kernel implemented using patches.
project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between
the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door
for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more
usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp:
Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for
compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem.
sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device
tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately.
sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick
boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades.
sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for
fastboot.

Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
2024-10-14 09:47:04 +08:00
..
debian creat: first commit 2023-08-08 20:36:47 +08:00
include/jwt-cpp project:build.sh: Added fastboot support; custom modifications to U-Boot and kernel implemented using patches. 2024-10-14 09:47:04 +08:00
vcpkg creat: first commit 2023-08-08 20:36:47 +08:00
.gitattributes creat: first commit 2023-08-08 20:36:47 +08:00
.gitignore creat: first commit 2023-08-08 20:36:47 +08:00
BaseTest.cpp creat: first commit 2023-08-08 20:36:47 +08:00
ClaimTest.cpp creat: first commit 2023-08-08 20:36:47 +08:00
Doxyfile creat: first commit 2023-08-08 20:36:47 +08:00
HelperTest.cpp creat: first commit 2023-08-08 20:36:47 +08:00
jwt-cpp.sln creat: first commit 2023-08-08 20:36:47 +08:00
jwt-cpp.vcxproj creat: first commit 2023-08-08 20:36:47 +08:00
jwt-cpp.vcxproj.filters creat: first commit 2023-08-08 20:36:47 +08:00
LICENSE creat: first commit 2023-08-08 20:36:47 +08:00
Makefile creat: first commit 2023-08-08 20:36:47 +08:00
README.md creat: first commit 2023-08-08 20:36:47 +08:00
TestMain.cpp creat: first commit 2023-08-08 20:36:47 +08:00
TokenFormatTest.cpp creat: first commit 2023-08-08 20:36:47 +08:00
TokenTest.cpp creat: first commit 2023-08-08 20:36:47 +08:00

jwt-cpp

Codacy Badge

A header only library for creating and validating json web tokens in c++.

Signature algorithms

As of version 0.2.0 jwt-cpp supports all algorithms defined by the spec. The modular design of jwt-cpp allows one to add additional algorithms without any problems. If you need any feel free to open a pull request. For the sake of completeness, here is a list of all supported algorithms:

  • HS256
  • HS384
  • HS512
  • RS256
  • RS384
  • RS512
  • ES256
  • ES384
  • ES512
  • PS256
  • PS384
  • PS512

Examples

Simple example of decoding a token and printing all claims:

#include <jwt-cpp/jwt.h>
#include <iostream>

int main(int argc, const char** argv) {
	std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
	auto decoded = jwt::decode(token);

	for(auto& e : decoded.get_payload_claims())
		std::cout << e.first << " = " << e.second.to_json() << std::endl;
}

In order to verify a token you first build a verifier and use it to verify a decoded token.

auto verifier = jwt::verify()
	.allow_algorithm(jwt::algorithm::hs256{ "secret" })
	.with_issuer("auth0");

verifier.verify(decoded_token);

The created verifier is stateless so you can reuse it for different tokens.

Creating a token (and signing) is equally easy.

auto token = jwt::create()
	.set_issuer("auth0")
	.set_type("JWS")
	.set_payload_claim("sample", std::string("test"))
	.sign(jwt::algorithm::hs256{"secret"});

Here is a simple example of creating a token that will expire in one hour:

auto token = jwt::create()
	.set_issuer("auth0")
	.set_issued_at(std::chrono::system_clock::now())
	.set_expires_at(std::chrono::system_clock::now() + std::chrono::seconds{3600})
	.sign(jwt::algorithm::hs256{"secret"});

Contributing

If you have an improvement or found a bug feel free to open an issue or add the change and create a pull request. If you file a bug please make sure to include as much information about your environment (compiler version, etc.) as possible to help reproduce the issue. If you add a new feature please make sure to also include test cases for it.

Dependencies

In order to use jwt-cpp you need the following tools.

  • libcrypto (openssl or compatible)
  • libssl-dev (for the header files)
  • a compiler supporting at least c++11
  • basic stl support

In order to build the test cases you also need

  • gtest installed in linker path
  • pthread

Troubleshooting

Expired tokens

If you are generating tokens that seem to immediately expire, you are likely not using UTC. Specifically, if you use get_time to get the current time, it likely uses localtime, while this library uses UTC, which may be why your token is immediately expiring. Please see example above on the right way to use current time.

Missing _HMAC amd _EVP_sha256 symbols on Mac

There seems to exists a problem with the included openssl library of MacOS. Make sure you link to one provided by brew. See here for more details.

Building on windows fails with syntax errors

The header "Windows.h", which is often included in windowsprojects, defines macros for MIN and MAX which screw up std::numeric_limits. See here for more details. To fix this do one of the following things:

  • define NOMINMAX, which suppresses this behaviour
  • include this library before you include windows.h
  • place #undef max and #undef min before you include this library