🧰 Linting and maintenance (#120)

* some manual fixes to obtain

* fairly close enough

* whitespace fixes

* add comment

* adding clang format + applied

* add editorconfig (supported natively by github web editor)

* apply linting to project

* clean up CI workflows

* zap vcpkg folder

actual one is here
https://github.com/microsoft/vcpkg/tree/master/ports/jwt-cpp

* adding a logo

* thin the lines in the pluses

* use logo + more links to spec and examples

* Create lint.yml

* apply linting
This commit is contained in:
Chris Mc
2021-01-11 17:37:14 -05:00
committed by GitHub
parent ac3de9e69b
commit b21d80c22e
45 changed files with 2317 additions and 2423 deletions

22
.clang-format Normal file
View File

@@ -0,0 +1,22 @@
BasedOnStyle: LLVM
BreakBeforeBraces: Attach
ColumnLimit: 120 # Match GitHub UI
UseTab: Always
TabWidth: 4
IndentWidth: 4
AccessModifierOffset: -4
ContinuationIndentWidth: 4
NamespaceIndentation: All
IndentCaseLabels: false
PointerAlignment: Left
AlwaysBreakTemplateDeclarations: Yes
SpaceAfterTemplateKeyword: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortBlocksOnASingleLine: Always
FixNamespaceComments: true
ReflowComments: false

17
.editorconfig Normal file
View File

@@ -0,0 +1,17 @@
root = true
[!*.{h,cpp}]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{h,cpp}]
indent_style = tab
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

View File

@@ -4,7 +4,7 @@ inputs:
version:
description: The desired jsoncons version to install
required: false
default: '0.159.0'
default: "0.159.0"
runs:
using: composite
steps:

View File

@@ -4,7 +4,7 @@ inputs:
version:
description: The desired LibreSSL version to install
required: false
default: '3.3.0'
default: "3.3.0"
runs:
using: composite
steps:

16
.github/logo.svg vendored Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 2450 750" width="2450" height="750" xmlns="http://www.w3.org/2000/svg">
<g style="" transform="matrix(1.01, 0, 0, 1, 550, 140)">
<path d="M -551.881 -175.95 L 1948.119 -175.95 L 1948.119 609.368 L -551.881 609.368 Z" clip-rule="evenodd" fill-rule="evenodd" style=""/>
<path d="M -108.039 81.534 L -108.639 -86.566 L -202.439 -86.566 L -201.839 81.534 L -154.939 145.934 Z M -201.839 369.634 L -201.839 538.334 L -108.039 538.334 L -108.039 369.634 L -154.939 305.234 Z" fill="#fff" clip-rule="evenodd" fill-rule="evenodd"/>
<path d="M -108.039 369.634 L -9.239 505.934 L 66.361 450.934 L -32.439 314.634 L -108.039 290.234 Z M -201.839 81.534 L -301.239 -54.766 L -376.839 0.234 L -278.039 136.434 L -201.839 160.834 Z" clip-rule="evenodd" fill-rule="evenodd" style="fill: rgb(101, 154, 210);"/>
<path d="M -278.039 136.534 L -438.039 84.634 L -466.839 173.334 L -306.839 225.834 L -231.239 200.834 Z M -79.339 250.234 L -32.439 314.634 L 127.561 366.534 L 156.361 277.834 L -3.639 225.934 Z" fill="#00b9f1" clip-rule="evenodd" fill-rule="evenodd"/>
<path d="M -3.739 225.934 L 156.261 173.434 L 127.461 84.734 L -32.539 136.634 L -79.439 201.034 Z M -306.839 225.934 L -466.839 277.834 L -438.039 366.534 L -278.039 314.634 L -231.139 250.234 Z" clip-rule="evenodd" fill-rule="evenodd" style="fill: rgb(0, 89, 156);"/>
<path d="M -278.039 314.634 L -376.839 450.934 L -301.239 505.934 L -201.839 369.634 L -201.839 290.234 Z M -32.439 136.534 L 66.361 0.234 L -9.239 -54.766 L -108.039 81.434 L -108.039 160.834 Z" clip-rule="evenodd" fill-rule="evenodd" style="fill: rgb(0, 68, 130);"/>
<path d="M 343.623 72.734 L 343.623 291.434 C 343.623 339.534 304.223 378.934 256.123 378.934 L 256.123 335.134 C 280.523 335.134 299.923 315.734 299.923 291.334 L 299.923 72.734 Z M 1142.423 116.534 L 1241.123 116.534 L 1241.123 72.834 L 1000.523 72.834 L 1000.523 116.534 L 1098.623 116.534 L 1098.623 379.034 L 1142.423 379.034 Z M 868.623 72.734 L 868.623 291.434 C 868.623 315.834 849.223 335.234 824.823 335.234 C 800.423 335.234 781.023 315.834 781.023 291.434 L 781.023 160.234 C 781.023 112.134 741.623 72.734 693.523 72.734 C 645.423 72.734 606.023 112.134 606.023 160.234 L 606.023 291.534 C 606.023 315.934 586.623 335.334 562.223 335.334 C 537.823 335.334 518.423 315.934 518.423 291.534 L 518.423 72.734 L 474.623 72.734 L 474.623 291.434 C 474.623 339.534 514.023 378.934 562.123 378.934 C 610.223 378.934 649.623 339.534 649.623 291.434 L 649.623 160.234 C 649.623 135.834 669.023 116.434 693.423 116.434 C 717.823 116.434 737.223 135.834 737.223 160.234 L 737.223 291.534 C 737.223 339.634 776.623 379.034 824.723 379.034 C 872.823 379.034 912.223 339.634 912.223 291.534 L 912.223 72.734 Z" fill="#fff" clip-rule="evenodd" fill-rule="evenodd"/>
<g transform="matrix(6.824428, -0.018276, 0.018773, 7.009964, -218.175049, -971.69281)" style="">
<polygon fill="#FFFFFF" points="255 168.508 241.666 168.508 241.666 155.175 234.334 155.175 234.334 168.508 221 168.508 221 175.841 234.334 175.841 234.334 189.175 241.666 189.175 241.666 175.841 255 175.841"/>
<polygon fill="#FFFFFF" points="297.5 168.508 284.166 168.508 284.166 155.175 276.834 155.175 276.834 168.508 263.5 168.508 263.5 175.841 276.834 175.841 276.834 189.175 284.166 189.175 284.166 175.841 297.5 175.841"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@@ -1,15 +1,16 @@
name: CMake Integration CI
name: CMake CI
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
paths:
- 'CMakeLists.txt'
- 'include/jwt-cpp/**'
- 'tests/cmake/**'
- '.github/workflows/cmake.yml'
- "CMakeLists.txt"
- "include/jwt-cpp/**"
- "tests/cmake/**"
- ".github/actions/**"
- ".github/workflows/cmake.yml"
jobs:
min-req:

View File

@@ -2,38 +2,36 @@ name: Coverage CI
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
paths:
- 'CMakeLists.txt'
- 'include/jwt-cpp/**'
- 'tests/*'
- '.github/workflows/coverate.yml'
- "CMakeLists.txt"
- "include/jwt-cpp/**"
- "tests/*"
- ".github/actions/**"
- ".github/workflows/coverate.yml"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: install cmake
uses: lukka/get-cmake@latest
- name: install gtest
uses: ./.github/actions/install/gtest
- uses: lukka/get-cmake@latest
- uses: ./.github/actions/install/gtest
- name: configure
run: |
mkdir build
cd build
cmake .. -DJWT_BUILD_TESTS=ON -DJWT_ENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
cmake .. -DJWT_BUILD_EXAMPLES=OFF -DJWT_BUILD_TESTS=ON -DJWT_ENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
- name: make
run: cd build && make jwt-cpp-test coverage
- name: run
run: |
cd build
make jwt-cpp-test coverage
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v1.1.1
- uses: coverallsapp/github-action@v1.1.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: build/coverage.info

View File

@@ -2,17 +2,15 @@ name: Documentation CI
on:
push:
branches: [ master ]
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: run doxygen
uses: mattnotmitt/doxygen-action@v1
- name: deploy
uses: peaceiris/actions-gh-pages@v3
with:

View File

@@ -2,14 +2,15 @@ name: LibreSSL CI
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
paths:
- 'CMakeLists.txt'
- 'include/jwt-cpp/**'
- 'tests/*'
- '.github/workflows/libressl.yml'
- "CMakeLists.txt"
- "include/jwt-cpp/**"
- "tests/*"
- ".github/actions/**"
- ".github/workflows/libressl.yml"
jobs:
build:
@@ -19,20 +20,16 @@ jobs:
libressl: ["3.3.0", "3.2.2"]
steps:
- uses: actions/checkout@v2
- name: install cmake
uses: lukka/get-cmake@latest
- name: install gtest
uses: ./.github/actions/install/gtest
- name: install libressl
uses: ./.github/actions/install/libressl
- uses: lukka/get-cmake@latest
- uses: ./.github/actions/install/gtest
- uses: ./.github/actions/install/libressl
with:
version: ${{ matrix.libressl }}
- name: configure
run: cmake . -DJWT_BUILD_TESTS=ON -DJWT_SSL_LIBRARY:STRING=LibreSSL
- name: make
run: make
- run: make
- name: test
run: ./tests/jwt-cpp-test
@@ -57,5 +54,5 @@ jobs:
publish_branch: badges
publish_dir: ./badges
keep_files: true
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
user_name: "github-actions[bot]"
user_email: "github-actions[bot]@users.noreply.github.com"

23
.github/workflows/lint.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: Lint CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
paths:
- 'include/jwt-cpp/**.h'
- 'tests/**.cpp'
- '.github/workflows/lint.yml'
jobs:
cpp:
runs-on: ubuntu-20.04
strategy:
matrix:
files: ["include/jwt-cpp/*.h", "tests/**.cpp"]
steps:
- run: sudo apt-get install clang-format-10
- uses: actions/checkout@v2
- run: clang-format-10 -i ${{ matrix.files }}
- run: exit $(git status -s | wc -l)

View File

@@ -2,9 +2,15 @@ name: Traits CI
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
paths:
- "CMakeLists.txt"
- "include/jwt-cpp/**"
- "tests/jsoncons/**"
- ".github/actions/**"
- ".github/workflows/traits.yml"
jobs:
jsoncons:
@@ -22,7 +28,7 @@ jobs:
cmake .. -DJWT_BUILD_EXAMPLES=OFF
sudo make install
- name: configure
- name: test
run: |
cd tests/jsoncons
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake

View File

@@ -1,4 +1,4 @@
# jwt-cpp
# ![logo](https://raw.githubusercontent.com/prince-chrismc/jwt-cpp/linting-and-maintance/.github/logo.svg)
[![License Badge](https://img.shields.io/github/license/Thalhammer/jwt-cpp)](https://github.com/Thalhammer/jwt-cpp/blob/master/LICENSE)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5f7055e294744901991fd0a1620b231d)](https://app.codacy.com/app/Thalhammer/jwt-cpp?utm_source=github.com&utm_medium=referral&utm_content=Thalhammer/jwt-cpp&utm_campaign=Badge_Grade_Settings)
@@ -7,12 +7,13 @@
[![Documentation Badge](https://img.shields.io/badge/Documentation-master-blue)](https://thalhammer.github.io/jwt-cpp/)
[![Stars Badge](https://img.shields.io/github/stars/Thalhammer/jwt-cpp)](https://github.com/Thalhammer/jwt-cpp/stargazers)
A header only library for creating and validating [JSON Web Tokens](https://tools.ietf.org/html/rfc7519) in C++11. For a great introduction, [read this](https://jwt.io/introduction/)
A header only library for creating and validating [JSON Web Tokens](https://tools.ietf.org/html/rfc7519) in C++11. For a great introduction, [read this](https://jwt.io/introduction/).
## Signature algorithms
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:
jwt-cpp supports all the algorithms defined by the specifications. The modular design allows to easily add additional algorithms without any problems. If you need any feel free to create a pull request or [open an issue](https://github.com/Thalhammer/jwt-cpp/issues/new).
For completeness, here is a list of all supported algorithms:
| HMSC | RSA | ECDSA | PSS | EdDSA |
| ----- | ----- | ----- | ----- | ------- |
@@ -22,8 +23,7 @@ For the sake of completeness, here is a list of all supported algorithms:
## SSL Compatability
In the name of flexibility and extensibility, jwt-cpp supports both [OpenSSL](https://github.com/openssl/openssl) and [LibreSSL](https://github.com/libressl-portable/portable).
These are the version which are tested:
In the name of flexibility and extensibility, jwt-cpp supports both [OpenSSL](https://github.com/openssl/openssl) and [LibreSSL](https://github.com/libressl-portable/portable). These are the version which are, or have been, tested:
| OpenSSL | LibreSSL |
| -------------- | --------------- |
@@ -38,13 +38,13 @@ These are the version which are tested:
## Overview
Since 0.5.0-rc.0, there is no hard dependency on a JSON library; instead there's a generic `jwt::basic_claim` which is templated around the types required.It requires a traits type, which defines types for a value, object, array, string, number, integer and boolean, as well as methods to translate between them.
There is no hard dependency on a JSON library. Instead, there's a generic `jwt::basic_claim` which is templated around type traits, which described the semantic [JSON types](https://json-schema.org/understanding-json-schema/reference/type.html) for a value, object, array, string, number, integer and boolean, as well as methods to translate between them.
```cpp
jwt::basic_claim<my_favorite_json_library_traits> claim(json::object({{"json", true},{"example", 0}}));
```
This allows for complete freedom when picking which libraries you want to use. For more information, [see below](#providing-your-own-json-traits-your-traits)
This allows for complete freedom when picking which libraries you want to use. For more information, [see below](#providing-your-own-json-traits-your-traits).
In order to maintain compatibility, [picojson](https://github.com/kazuho/picojson) is still used to provide a specialized `jwt::claim` along with all helpers. Defining `JWT_DISABLE_PICOJSON` will remove this optional dependency.
@@ -52,7 +52,7 @@ As for the base64 requirements of JWTs, this libary provides `base.h` with all t
### Getting Started
Simple example of decoding a token and printing all claims ([try it out](https://github.com/Thalhammer/jwt-cpp/tree/master/example/print-claims.cpp)):
Simple example of decoding a token and printing all [claims](https://tools.ietf.org/html/rfc7519#section-4) ([try it out](https://github.com/Thalhammer/jwt-cpp/tree/master/example/print-claims.cpp)):
```cpp
#include <jwt-cpp/jwt.h>
@@ -111,6 +111,8 @@ There are several key items that need to be provided to a `jwt::basic_claim` in
If ever you are not sure, the traits are heavily checked against static asserts to make sure you provide everything that's required.
> :warning: Not all JSON libraries are a like, you may need to extent certain types such that it can be used by jwt-cpp. See this [example](https://github.com/Thalhammer/jwt-cpp/blob/ac3de9e69bc698a464dacb256a1b50512843f092/tests/jsoncons/JsonconsTest.cpp).
```cpp
struct my_favorite_json_library_traits {
// Type Specifications

View File

@@ -1,15 +1,12 @@
set(COVERAGE_CMAKE "${CMAKE_BINARY_DIR}/cmake/CodeCoverage.cmake")
if(NOT EXISTS ${COVERAGE_CMAKE})
set(COVERAGE_URL
"https://raw.githubusercontent.com/bilke/cmake-modules/master/CodeCoverage.cmake"
)
set(COVERAGE_URL "https://raw.githubusercontent.com/bilke/cmake-modules/master/CodeCoverage.cmake")
file(DOWNLOAD ${COVERAGE_URL} ${COVERAGE_CMAKE})
endif()
include(${COVERAGE_CMAKE})
function(setup_coverage TARGET)
target_compile_options(${TARGET} PRIVATE -g -O0 -fprofile-arcs
-ftest-coverage)
target_compile_options(${TARGET} PRIVATE -g -O0 -fprofile-arcs -ftest-coverage)
target_link_libraries(${TARGET} PRIVATE gcov)
endfunction()

View File

@@ -1,15 +0,0 @@
#include"jwt-cpp/jwt.h"
#include<iostream>
#include <chrono>
int main() {
std::string token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2MTAwMjMxNzcsImV4cCI6MTY0MTU1OTE3NywiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5hbWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.5EOfHnBmpdPvRHAuVDttgJQvbFuGEF7fC4uBSXAGg6c";
auto decoded = jwt::decode(token);
for(auto& e : decoded.get_payload_claims())
std::cout << e.first << " = " << e.second << std::endl;
}

View File

@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(conan-example)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})

View File

@@ -1,18 +1,17 @@
Conan example
# Conan example
In the current directory on Linux environment
```
```sh
mkdir build && cd build
conan install .. && cmake ..
cmake --build .
```
run executable
```
./bin/conan-example
```
the output:
```
```sh
$ ./bin/conan-example
sub = "jrocket@example.com"
iss = "Online JWT Builder"
exp = 1641559177

17
example/conan/main.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include "jwt-cpp/jwt.h"
#include <chrono>
#include <iostream>
int main() {
std::string token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9."
"eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2MTAwMjMxNzcsImV4cCI6MTY0MTU1OTE3NywiYXVkIjoid3"
"d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5h"
"bWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IE"
"FkbWluaXN0cmF0b3IiXX0.5EOfHnBmpdPvRHAuVDttgJQvbFuGEF7fC4uBSXAGg6c";
auto decoded = jwt::decode(token);
for (auto& e : decoded.get_payload_claims())
std::cout << e.first << " = " << e.second << std::endl;
}

View File

@@ -1,10 +1,11 @@
#include <jwt-cpp/jwt.h>
#include <iostream>
#include <jwt-cpp/jwt.h>
int main(int argc, const char** argv) {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
auto decoded = jwt::decode(token);
for(auto& e : decoded.get_payload_claims())
for (auto& e : decoded.get_payload_claims())
std::cout << e.first << " = " << e.second << std::endl;
}

View File

@@ -14,8 +14,7 @@ std::string make_pico_token() {
jwt::claim::set_t list{"once", "twice"};
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull,
525936436ull};
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull, 525936436ull};
const auto time = jwt::date::clock::now();
@@ -30,8 +29,7 @@ std::string make_pico_token() {
.set_payload_claim("integer", picojson::value(int64_t{12345}))
.set_payload_claim("precision", picojson::value(12.345))
.set_payload_claim("strings", jwt::claim(list))
.set_payload_claim("array",
jwt::claim(big_numbers.begin(), big_numbers.end()))
.set_payload_claim("array", jwt::claim(big_numbers.begin(), big_numbers.end()))
.set_payload_claim("object", from_raw_json)
.sign(jwt::algorithm::none{});
}
@@ -47,7 +45,7 @@ std::string make_nlohmann_token() {
using integer_type = json::number_integer_t;
using boolean_type = json::boolean_t;
static jwt::json::type get_type(const json &val) {
static jwt::json::type get_type(const json& val) {
using jwt::json::type;
if (val.type() == json::value_t::boolean)
@@ -68,53 +66,45 @@ std::string make_nlohmann_token() {
throw std::logic_error("invalid type");
}
static json::object_t as_object(const json &val) {
if (val.type() != json::value_t::object)
throw std::bad_cast();
static json::object_t as_object(const json& val) {
if (val.type() != json::value_t::object) throw std::bad_cast();
return val.get<json::object_t>();
}
static std::string as_string(const json &val) {
if (val.type() != json::value_t::string)
throw std::bad_cast();
static std::string as_string(const json& val) {
if (val.type() != json::value_t::string) throw std::bad_cast();
return val.get<std::string>();
}
static json::array_t as_array(const json &val) {
if (val.type() != json::value_t::array)
throw std::bad_cast();
static json::array_t as_array(const json& val) {
if (val.type() != json::value_t::array) throw std::bad_cast();
return val.get<json::array_t>();
}
static int64_t as_int(const json &val) {
switch(val.type())
{
static int64_t as_int(const json& val) {
switch (val.type()) {
case json::value_t::number_integer:
case json::value_t::number_unsigned:
return val.get<int64_t>();
default:
throw std::bad_cast();
case json::value_t::number_unsigned: return val.get<int64_t>();
default: throw std::bad_cast();
}
}
static bool as_bool(const json &val) {
if (val.type() != json::value_t::boolean)
throw std::bad_cast();
static bool as_bool(const json& val) {
if (val.type() != json::value_t::boolean) throw std::bad_cast();
return val.get<bool>();
}
static double as_number(const json &val) {
if (val.type() != json::value_t::number_float)
throw std::bad_cast();
static double as_number(const json& val) {
if (val.type() != json::value_t::number_float) throw std::bad_cast();
return val.get<double>();
}
static bool parse(json &val, std::string str) {
static bool parse(json& val, std::string str) {
val = json::parse(str.begin(), str.end());
return true;
}
static std::string serialize(const json &val) { return val.dump(); }
static std::string serialize(const json& val) { return val.dump(); }
};
using claim = jwt::basic_claim<nlohmann_traits>;
@@ -125,8 +115,7 @@ std::string make_nlohmann_token() {
claim::set_t list{"once", "twice"};
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull,
525936436ull};
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull, 525936436ull};
const auto time = jwt::date::clock::now();
@@ -146,14 +135,13 @@ std::string make_nlohmann_token() {
.sign(jwt::algorithm::none{});
}
int main(int argc, const char **argv) {
int main(int argc, const char** argv) {
const auto token = make_pico_token();
auto decoded = jwt::decode(token);
for (auto &e : decoded.get_payload_claims())
for (auto& e : decoded.get_payload_claims())
std::cout << e.first << " = " << e.second << std::endl;
const auto api_array =
decoded.get_payload_claims()["object"].to_json().get("api").get("array");
const auto api_array = decoded.get_payload_claims()["object"].to_json().get("api").get("array");
std::cout << "api array = " << api_array << std::endl;
}

View File

@@ -1,7 +1,7 @@
#include <iostream>
#include <jwt-cpp/jwt.h>
int main(int argc, const char **argv) {
int main(int argc, const char** argv) {
std::string rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
@@ -40,8 +40,7 @@ AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0
YwIDAQAB
-----END PUBLIC KEY-----)";
auto token =
jwt::create()
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWT")
.set_id("rsa-create-example")

View File

@@ -1,7 +1,7 @@
#include <iostream>
#include <jwt-cpp/jwt.h>
int main(int argc, const char **argv) {
int main(int argc, const char** argv) {
std::string rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
@@ -40,8 +40,7 @@ AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0
YwIDAQAB
-----END PUBLIC KEY-----)";
std::string token =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9."
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9."
"VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-"
"GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
@@ -50,17 +49,15 @@ YwIDAQAB
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-"
"uc2z5c05CCXqVSpfCjWbh9gQ";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::rs256(
rsa_pub_key, rsa_priv_key, "", ""))
.with_issuer("auth0");
auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", "")).with_issuer("auth0");
auto decoded = jwt::decode(token);
verify.verify(decoded);
for (auto &e : decoded.get_header_claims())
for (auto& e : decoded.get_header_claims())
std::cout << e.first << " = " << e.second.to_json() << std::endl;
for (auto &e : decoded.get_payload_claims())
for (auto& e : decoded.get_payload_claims())
std::cout << e.first << " = " << e.second.to_json() << std::endl;
}

View File

@@ -25,16 +25,15 @@ namespace jwt {
*/
struct base64 {
static const std::array<char, 64>& data() {
static constexpr std::array<char, 64> data {
static constexpr std::array<char, 64> data{
{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}
};
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}};
return data;
}
static const std::string& fill() {
static std::string fill{ "=" };
static std::string fill{"="};
return fill;
}
};
@@ -43,16 +42,15 @@ namespace jwt {
*/
struct base64url {
static const std::array<char, 64>& data() {
static constexpr std::array<char, 64> data {
static constexpr std::array<char, 64> data{
{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'}
};
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'}};
return data;
}
static const std::string& fill() {
static std::string fill{ "%3d" };
static std::string fill{"%3d"};
return fill;
}
};
@@ -81,7 +79,8 @@ namespace jwt {
}
private:
static std::string encode(const std::string& bin, const std::array<char, 64>& alphabet, const std::string& fill) {
static std::string encode(const std::string& bin, const std::array<char, 64>& alphabet,
const std::string& fill) {
size_t size = bin.size();
std::string res;
@@ -100,8 +99,7 @@ namespace jwt {
res += alphabet[(triple >> 0 * 6) & 0x3F];
}
if (fast_size == size)
return res;
if (fast_size == size) return res;
size_t mod = size % 3;
@@ -124,14 +122,14 @@ namespace jwt {
res += alphabet[(triple >> 1 * 6) & 0x3F];
res += fill;
break;
default:
break;
default: break;
}
return res;
}
static std::string decode(const std::string& base, const std::array<char, 64>& alphabet, const std::string& fill) {
static std::string decode(const std::string& base, const std::array<char, 64>& alphabet,
const std::string& fill) {
size_t size = base.size();
size_t fill_cnt = 0;
@@ -139,14 +137,12 @@ namespace jwt {
if (base.substr(size - fill.size(), fill.size()) == fill) {
fill_cnt++;
size -= fill.size();
if(fill_cnt > 2)
throw std::runtime_error("Invalid input");
}
else break;
if (fill_cnt > 2) throw std::runtime_error("Invalid input");
} else
break;
}
if ((size + fill_cnt) % 4 != 0)
throw std::runtime_error("Invalid input");
if ((size + fill_cnt) % 4 != 0) throw std::runtime_error("Invalid input");
size_t out_size = size / 4 * 3;
std::string res;
@@ -154,8 +150,7 @@ namespace jwt {
auto get_sextet = [&](size_t offset) {
for (size_t i = 0; i < alphabet.size(); i++) {
if (alphabet[i] == base[offset])
return static_cast<uint32_t>(i);
if (alphabet[i] == base[offset]) return static_cast<uint32_t>(i);
}
throw std::runtime_error("Invalid input");
};
@@ -167,21 +162,16 @@ namespace jwt {
uint32_t sextet_c = get_sextet(i++);
uint32_t sextet_d = get_sextet(i++);
uint32_t triple = (sextet_a << 3 * 6)
+ (sextet_b << 2 * 6)
+ (sextet_c << 1 * 6)
+ (sextet_d << 0 * 6);
uint32_t triple = (sextet_a << 3 * 6) + (sextet_b << 2 * 6) + (sextet_c << 1 * 6) + (sextet_d << 0 * 6);
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
res += static_cast<char>((triple >> 1 * 8) & 0xFFU);
res += static_cast<char>((triple >> 0 * 8) & 0xFFU);
}
if (fill_cnt == 0)
return res;
if (fill_cnt == 0) return res;
uint32_t triple = (get_sextet(fast_size) << 3 * 6)
+ (get_sextet(fast_size + 1) << 2 * 6);
uint32_t triple = (get_sextet(fast_size) << 3 * 6) + (get_sextet(fast_size + 1) << 2 * 6);
switch (fill_cnt) {
case 1:
@@ -189,11 +179,8 @@ namespace jwt {
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
res += static_cast<char>((triple >> 1 * 8) & 0xFFU);
break;
case 2:
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
break;
default:
break;
case 2: res += static_cast<char>((triple >> 2 * 8) & 0xFFU); break;
default: break;
}
return res;
@@ -202,17 +189,10 @@ namespace jwt {
static std::string pad(const std::string& base, const std::string& fill) {
std::string padding;
switch (base.size() % 4) {
case 1:
padding += fill;
JWT_FALLTHROUGH;
case 2:
padding += fill;
JWT_FALLTHROUGH;
case 3:
padding += fill;
JWT_FALLTHROUGH;
default:
break;
case 1: padding += fill; JWT_FALLTHROUGH;
case 2: padding += fill; JWT_FALLTHROUGH;
case 3: padding += fill; JWT_FALLTHROUGH;
default: break;
}
return base + padding;

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "jwt-cpp/base.h"
#include <gtest/gtest.h>
TEST(BaseTest, Base64Decode) {
ASSERT_EQ("1", jwt::base::decode<jwt::alphabet::base64>("MQ=="));

View File

@@ -1,8 +1,9 @@
#include <gtest/gtest.h>
#include "jwt-cpp/jwt.h"
#include <gtest/gtest.h>
TEST(ClaimTest, AudienceAsString) {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
auto decoded = jwt::decode(token);
ASSERT_TRUE(decoded.has_algorithm());
@@ -25,11 +26,9 @@ TEST(ClaimTest, AudienceAsString) {
}
TEST(ClaimTest, SetAudienceAsString) {
auto token = jwt::create()
.set_type("JWT")
.set_audience("test")
.sign(jwt::algorithm::hs256("test"));
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.ny5Fa0vzAg7tNL95KWg_ecBNd3XP3tdAzq0SFA6diY4", token);
auto token = jwt::create().set_type("JWT").set_audience("test").sign(jwt::algorithm::hs256("test"));
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.ny5Fa0vzAg7tNL95KWg_ecBNd3XP3tdAzq0SFA6diY4",
token);
}
TEST(ClaimTest, AudienceAsSet) {
@@ -65,14 +64,9 @@ TEST(ClaimTest, SetAudienceAsSet) {
}
TEST(ClaimTest, SetArray) {
std::vector<int64_t> vect = {
100,
20,
10
};
auto token = jwt::create()
.set_payload_claim("test", jwt::claim(vect.begin(), vect.end()))
.sign(jwt::algorithm::none{});
std::vector<int64_t> vect = {100, 20, 10};
auto token =
jwt::create().set_payload_claim("test", jwt::claim(vect.begin(), vect.end())).sign(jwt::algorithm::none{});
ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0.");
}
@@ -80,18 +74,15 @@ TEST(ClaimTest, SetObject) {
std::istringstream iss{"{\"api-x\": [1]}"};
jwt::claim object;
iss >> object;
ASSERT_EQ(object.get_type() , jwt::json::type::object);
ASSERT_EQ(object.get_type(), jwt::json::type::object);
auto token = jwt::create()
.set_payload_claim("namespace", object)
.sign(jwt::algorithm::hs256("test"));
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
auto token = jwt::create().set_payload_claim("namespace", object).sign(jwt::algorithm::hs256("test"));
ASSERT_EQ(token,
"eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
}
TEST(ClaimTest, SetAlgorithm) {
auto token = jwt::create()
.set_algorithm("test")
.sign(jwt::algorithm::none{});
auto token = jwt::create().set_algorithm("test").sign(jwt::algorithm::none{});
auto decoded_token = jwt::decode(token);
ASSERT_EQ(decoded_token.get_algorithm(), "test");
@@ -133,7 +124,8 @@ TEST(ClaimTest, PicoJSONTraitsAsDouble) {
TEST(ClaimTest, MapOfClaim) {
using map = jwt::details::map_of_claims<jwt::picojson_traits>;
ASSERT_THROW(map::parse_claims(R"##(__ not json __)##"), jwt::error::invalid_json_exception);
const map claims{ map::parse_claims(R"##({ "array": [1], "string" : "hello world", "number": 9.9, "bool": true})##") };
const map claims{
map::parse_claims(R"##({ "array": [1], "string" : "hello world", "number": 9.9, "bool": true})##")};
ASSERT_TRUE(claims.has_claim("array"));
ASSERT_TRUE(claims.has_claim("string"));

View File

@@ -1,11 +1,11 @@
#include <gtest/gtest.h>
#include "jwt-cpp/jwt.h"
#include <gtest/gtest.h>
namespace {
extern std::string google_cert;
extern std::string google_cert_base64_der;
extern std::string google_cert_key;
}
} // namespace
TEST(HelperTest, Cert2Pubkey) {
auto key = jwt::helper::extract_pubkey_from_cert(google_cert);
@@ -27,47 +27,53 @@ TEST(HelperTest, ErrorCodeMessages) {
ASSERT_EQ(std::error_code(jwt::error::ecdsa_error::ok).category().name(), std::string("ecdsa_error"));
ASSERT_EQ(std::error_code(jwt::error::signature_verification_error::ok).message(), "no error");
ASSERT_EQ(std::error_code(static_cast<jwt::error::signature_verification_error>(-1)).message(), "unknown signature verification error");
ASSERT_EQ(std::error_code(jwt::error::signature_verification_error::ok).category().name(), std::string("signature_verification_error"));
ASSERT_EQ(std::error_code(static_cast<jwt::error::signature_verification_error>(-1)).message(),
"unknown signature verification error");
ASSERT_EQ(std::error_code(jwt::error::signature_verification_error::ok).category().name(),
std::string("signature_verification_error"));
ASSERT_EQ(std::error_code(jwt::error::signature_generation_error::ok).message(), "no error");
ASSERT_EQ(std::error_code(static_cast<jwt::error::signature_generation_error>(-1)).message(), "unknown signature generation error");
ASSERT_EQ(std::error_code(jwt::error::signature_generation_error::ok).category().name(), std::string("signature_generation_error"));
ASSERT_EQ(std::error_code(static_cast<jwt::error::signature_generation_error>(-1)).message(),
"unknown signature generation error");
ASSERT_EQ(std::error_code(jwt::error::signature_generation_error::ok).category().name(),
std::string("signature_generation_error"));
ASSERT_EQ(std::error_code(jwt::error::token_verification_error::ok).message(), "no error");
ASSERT_EQ(std::error_code(static_cast<jwt::error::token_verification_error>(-1)).message(), "unknown token verification error");
ASSERT_EQ(std::error_code(jwt::error::token_verification_error::ok).category().name(), std::string("token_verification_error"));
ASSERT_EQ(std::error_code(static_cast<jwt::error::token_verification_error>(-1)).message(),
"unknown token verification error");
ASSERT_EQ(std::error_code(jwt::error::token_verification_error::ok).category().name(),
std::string("token_verification_error"));
int i = 10;
for(i = 10; i < 19; i++) {
for (i = 10; i < 19; i++) {
ASSERT_NE(std::error_code(static_cast<jwt::error::rsa_error>(i)).message(),
std::error_code(static_cast<jwt::error::rsa_error>(-1)).message());
}
ASSERT_EQ(std::error_code(static_cast<jwt::error::rsa_error>(i)).message(),
std::error_code(static_cast<jwt::error::rsa_error>(-1)).message());
for(i = 10; i < 16; i++) {
for (i = 10; i < 16; i++) {
ASSERT_NE(std::error_code(static_cast<jwt::error::ecdsa_error>(i)).message(),
std::error_code(static_cast<jwt::error::ecdsa_error>(-1)).message());
}
ASSERT_EQ(std::error_code(static_cast<jwt::error::ecdsa_error>(i)).message(),
std::error_code(static_cast<jwt::error::ecdsa_error>(-1)).message());
for(i = 10; i < 16; i++) {
for (i = 10; i < 16; i++) {
ASSERT_NE(std::error_code(static_cast<jwt::error::signature_verification_error>(i)).message(),
std::error_code(static_cast<jwt::error::signature_verification_error>(-1)).message());
}
ASSERT_EQ(std::error_code(static_cast<jwt::error::signature_verification_error>(i)).message(),
std::error_code(static_cast<jwt::error::signature_verification_error>(-1)).message());
for(i = 10; i < 22; i++) {
for (i = 10; i < 22; i++) {
ASSERT_NE(std::error_code(static_cast<jwt::error::signature_generation_error>(i)).message(),
std::error_code(static_cast<jwt::error::signature_generation_error>(-1)).message());
}
ASSERT_EQ(std::error_code(static_cast<jwt::error::signature_generation_error>(i)).message(),
std::error_code(static_cast<jwt::error::signature_generation_error>(-1)).message());
for(i = 10; i < 16; i++) {
for (i = 10; i < 16; i++) {
ASSERT_NE(std::error_code(static_cast<jwt::error::token_verification_error>(i)).message(),
std::error_code(static_cast<jwt::error::token_verification_error>(-1)).message());
}
@@ -112,8 +118,7 @@ OpueYUG3NBcHP/5IzhUYIQJbGzlQaUaZBMaQeC8ZslMNLWI2
-----END CERTIFICATE-----
)";
std::string google_cert_base64_der =
"MIIF8DCCBVmgAwIBAgIKYFOB9QABAACIvTANBgkqhkiG9w0BAQUFADBGMQswCQYD"
std::string google_cert_base64_der = "MIIF8DCCBVmgAwIBAgIKYFOB9QABAACIvTANBgkqhkiG9w0BAQUFADBGMQswCQYD"
"VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu"
"dGVybmV0IEF1dGhvcml0eTAeFw0xMzA1MjIxNTQ5MDRaFw0xMzEwMzEyMzU5NTla"
"MGYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N"
@@ -151,4 +156,4 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZkqSFGwqoVAatVMJ0QIu/0zUpOlv
CZmrEfiNK/zSw2L+cgKWwM/B11zfIQ3bqzET+ictUNFCCpspbPBzx3saAg==
-----END PUBLIC KEY-----
)";
}
} // namespace

View File

@@ -190,8 +190,7 @@ ftcs6dibdnbQtbX6o9E+KuvGHoNW5xcSjX8lwXTpopfvufPOLPcnFXi4UoYZ8NZ2
flE/m/0zymX8I/Xu3+KKLhUnUROGC6zO3OnLHXCnEns=
-----END CERTIFICATE-----
)";
std::string sample_cert_base64_der =
"MIIDHDCCAgSgAwIBAgIIGlbUz5cvweUwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE"
std::string sample_cert_base64_der = "MIIDHDCCAgSgAwIBAgIIGlbUz5cvweUwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE"
"AxMmc2VjdXJldG9rZW4uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wHhcNMTkw"
"NDEwMjEyMDUxWhcNMTkwNDI3MDkzNTUxWjAxMS8wLQYDVQQDEyZzZWN1cmV0b2tl"
"bi5zeXN0ZW0uZ3NlcnZpY2VhY2NvdW50LmNvbTCCASIwDQYJKoZIhvcNAQEBBQAD"
@@ -218,4 +217,4 @@ l/FYE3iGT+uqAaPFCbMBgwIHv+n/1Kd+Dg2Z9flwknTVI3NjpD+YlGMHeJfY8HP4
awIDAQAB
-----END PUBLIC KEY-----
)";
}
} // namespace test_keys

View File

@@ -1,8 +1,8 @@
#define JWT_DISABLE_PICOJSON // Make sure JWT compiles with this flag
#include <gtest/gtest.h>
#include "jwt-cpp/jwt.h"
#include "nlohmann/json.hpp"
#include <gtest/gtest.h>
struct nlohmann_traits {
using json = nlohmann::json;
@@ -14,76 +14,60 @@ struct nlohmann_traits {
using integer_type = json::number_integer_t;
using boolean_type = json::boolean_t;
static jwt::json::type get_type(const json &val) {
static jwt::json::type get_type(const json& val) {
using jwt::json::type;
if (val.type() == json::value_t::boolean)
return type::boolean;
if (val.type() == json::value_t::number_integer)
return type::integer;
if (val.type() == json::value_t::boolean) return type::boolean;
if (val.type() == json::value_t::number_integer) return type::integer;
if (val.type() == json::value_t::number_unsigned) // nlohmann internally tracks two types of integers
return type::integer;
if (val.type() == json::value_t::number_float)
return type::number;
if (val.type() == json::value_t::string)
return type::string;
if (val.type() == json::value_t::array)
return type::array;
if (val.type() == json::value_t::object)
return type::object;
if (val.type() == json::value_t::number_float) return type::number;
if (val.type() == json::value_t::string) return type::string;
if (val.type() == json::value_t::array) return type::array;
if (val.type() == json::value_t::object) return type::object;
throw std::logic_error("invalid type");
}
static json::object_t as_object(const json &val) {
if (val.type() != json::value_t::object)
throw std::bad_cast();
static json::object_t as_object(const json& val) {
if (val.type() != json::value_t::object) throw std::bad_cast();
return val.get<json::object_t>();
}
static std::string as_string(const json &val) {
if (val.type() != json::value_t::string)
throw std::bad_cast();
static std::string as_string(const json& val) {
if (val.type() != json::value_t::string) throw std::bad_cast();
return val.get<std::string>();
}
static json::array_t as_array(const json &val) {
if (val.type() != json::value_t::array)
throw std::bad_cast();
static json::array_t as_array(const json& val) {
if (val.type() != json::value_t::array) throw std::bad_cast();
return val.get<json::array_t>();
}
static int64_t as_int(const json &val) {
switch(val.type())
{
static int64_t as_int(const json& val) {
switch (val.type()) {
case json::value_t::number_integer:
case json::value_t::number_unsigned:
return val.get<int64_t>();
default:
throw std::bad_cast();
case json::value_t::number_unsigned: return val.get<int64_t>();
default: throw std::bad_cast();
}
}
static bool as_bool(const json &val) {
if (val.type() != json::value_t::boolean)
throw std::bad_cast();
static bool as_bool(const json& val) {
if (val.type() != json::value_t::boolean) throw std::bad_cast();
return val.get<bool>();
}
static double as_number(const json &val) {
if (val.type() != json::value_t::number_float)
throw std::bad_cast();
static double as_number(const json& val) {
if (val.type() != json::value_t::number_float) throw std::bad_cast();
return val.get<double>();
}
static bool parse(json &val, std::string str) {
static bool parse(json& val, std::string str) {
val = json::parse(str.begin(), str.end());
return true;
}
static std::string serialize(const json &val) {
return val.dump();
}
static std::string serialize(const json& val) { return val.dump(); }
};
TEST(NlohmannTest, BasicClaims) {
@@ -95,8 +79,7 @@ TEST(NlohmannTest, BasicClaims) {
}
TEST(NlohmannTest, AudienceAsString) {
std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
"WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
auto decoded = jwt::decode<nlohmann_traits>(token);
@@ -122,11 +105,7 @@ TEST(NlohmannTest, AudienceAsString) {
}
TEST(NlohmannTest, SetArray) {
std::vector<int64_t> vect = {
100,
20,
10
};
std::vector<int64_t> vect = {100, 20, 10};
auto token = jwt::create<nlohmann_traits>()
.set_payload_claim("test", jwt::basic_claim<nlohmann_traits>(vect.begin(), vect.end()))
.sign(jwt::algorithm::none{});
@@ -137,19 +116,20 @@ TEST(NlohmannTest, SetObject) {
std::istringstream iss{"{\"api-x\": [1]}"};
jwt::basic_claim<nlohmann_traits> object;
iss >> object;
ASSERT_EQ(object.get_type() , jwt::json::type::object);
ASSERT_EQ(object.get_type(), jwt::json::type::object);
auto token = jwt::create<nlohmann_traits>()
.set_payload_claim("namespace", object)
.sign(jwt::algorithm::hs256("test"));
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
auto token =
jwt::create<nlohmann_traits>().set_payload_claim("namespace", object).sign(jwt::algorithm::hs256("test"));
ASSERT_EQ(token,
"eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
}
TEST(NlohmannTest, VerifyTokenHS256) {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
auto verify = jwt::verify<jwt::default_clock, nlohmann_traits>({})
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
.allow_algorithm(jwt::algorithm::hs256{"secret"})
.with_issuer("auth0");
auto decoded_token = jwt::decode<nlohmann_traits>(token);
@@ -164,7 +144,7 @@ TEST(NlohmannTest, VerifyTokenExpirationValid) {
.sign(jwt::algorithm::hs256{"secret"});
auto verify = jwt::verify<jwt::default_clock, nlohmann_traits>({})
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
.allow_algorithm(jwt::algorithm::hs256{"secret"})
.with_issuer("auth0");
auto decoded_token = jwt::decode<nlohmann_traits>(token);
@@ -179,7 +159,7 @@ TEST(NlohmannTest, VerifyTokenExpired) {
.sign(jwt::algorithm::hs256{"secret"});
auto verify = jwt::verify<jwt::default_clock, nlohmann_traits>({})
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
.allow_algorithm(jwt::algorithm::hs256{"secret"})
.with_issuer("auth0");
auto decoded_token = jwt::decode<nlohmann_traits>(token);

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,6 @@
#include <gtest/gtest.h>
int main(int argc, char *argv[])
{
int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "jwt-cpp/jwt.h"
#include <gtest/gtest.h>
TEST(TokenFormatTest, MissingDot) {
ASSERT_THROW(jwt::decode("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9"), std::invalid_argument);

View File

@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "jwt-cpp/jwt.h"
#include <gtest/gtest.h>
inline namespace test_keys {
extern std::string rsa_priv_key;
@@ -24,10 +24,11 @@ inline namespace test_keys {
extern std::string ed448_priv_key;
extern std::string ed448_pub_key;
extern std::string ed448_pub_key_invalid;
}
} // namespace test_keys
TEST(TokenTest, DecodeToken) {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
auto decoded = jwt::decode(token);
ASSERT_TRUE(decoded.has_algorithm());
@@ -48,71 +49,57 @@ TEST(TokenTest, DecodeToken) {
}
TEST(TokenTest, CreateToken) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::none{});
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::none{});
ASSERT_EQ("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9.", token);
}
TEST(TokenTest, CreateTokenHS256) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::hs256{"secret"});
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE", token);
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::hs256{"secret"});
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE",
token);
}
TEST(TokenTest, CreateTokenRS256) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""));
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""));
ASSERT_EQ(
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ", token);
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ",
token);
}
TEST(TokenTest, CreateTokenRS512) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::rs512(rsa512_pub_key, rsa512_priv_key, "", ""));
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
jwt::algorithm::rs512(rsa512_pub_key, rsa512_priv_key, "", ""));
ASSERT_EQ(
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZSSQyLKvI0"
ASSERT_EQ("eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZSSQyLKvI0"
"TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4GB"
"hfGgejPBCBlGrQtqFGFdHHOjNHY", token);
"hfGgejPBCBlGrQtqFGFdHHOjNHY",
token);
}
TEST(TokenTest, CreateTokenPS256) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", ""));
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", ""));
// TODO: Find a better way to check if generated signature is valid
// Can't do simple check for equal since pss adds random salt.
}
TEST(TokenTest, CreateTokenPS384) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::ps384(rsa_pub_key, rsa_priv_key, "", ""));
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
jwt::algorithm::ps384(rsa_pub_key, rsa_priv_key, "", ""));
// TODO: Find a better way to check if generated signature is valid
// Can't do simple check for equal since pss adds random salt.
}
TEST(TokenTest, CreateTokenPS512) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::ps512(rsa_pub_key, rsa_priv_key, "", ""));
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
jwt::algorithm::ps512(rsa_pub_key, rsa_priv_key, "", ""));
// TODO: Find a better way to check if generated signature is valid
// Can't do simple check for equal since pss adds random salt.
@@ -120,110 +107,110 @@ TEST(TokenTest, CreateTokenPS512) {
TEST(TokenTest, CreateTokenES256) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::es256("", ecdsa256_priv_key, "", ""));
auto token =
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::es256("", ecdsa256_priv_key, "", ""));
auto decoded = jwt::decode(token);
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
ASSERT_THROW(
jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key_invalid, "", "", "")).verify(decoded),
jwt::signature_verification_exception);
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key, "", "", "")).verify(decoded));
}
TEST(TokenTest, CreateTokenES256NoPrivate) {
ASSERT_THROW([](){
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::es256(ecdsa256_pub_key, "", "", ""));
}(), jwt::signature_generation_exception);
ASSERT_THROW(
[]() {
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
jwt::algorithm::es256(ecdsa256_pub_key, "", "", ""));
}(),
jwt::signature_generation_exception);
}
TEST(TokenTest, CreateTokenES384) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::es384("", ecdsa384_priv_key, "", ""));
auto token =
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::es384("", ecdsa384_priv_key, "", ""));
auto decoded = jwt::decode(token);
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
ASSERT_THROW(
jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key_invalid, "", "", "")).verify(decoded),
jwt::signature_verification_exception);
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key, "", "", "")).verify(decoded));
}
TEST(TokenTest, CreateTokenES384NoPrivate) {
ASSERT_THROW([](){
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::es384(ecdsa384_pub_key, "", "", ""));
}(), jwt::signature_generation_exception);
ASSERT_THROW(
[]() {
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
jwt::algorithm::es384(ecdsa384_pub_key, "", "", ""));
}(),
jwt::signature_generation_exception);
}
TEST(TokenTest, CreateTokenES512) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::es512("", ecdsa521_priv_key, "", ""));
auto token =
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::es512("", ecdsa521_priv_key, "", ""));
auto decoded = jwt::decode(token);
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
ASSERT_THROW(
jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key_invalid, "", "", "")).verify(decoded),
jwt::signature_verification_exception);
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key, "", "", "")).verify(decoded));
}
TEST(TokenTest, CreateTokenES512NoPrivate) {
ASSERT_THROW([](){
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::es512(ecdsa521_pub_key, "", "", ""));
}(), jwt::signature_generation_exception);
ASSERT_THROW(
[]() {
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
jwt::algorithm::es512(ecdsa521_pub_key, "", "", ""));
}(),
jwt::signature_generation_exception);
}
#ifndef OPENSSL110
TEST(TokenTest, CreateTokenEd25519) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::ed25519("", ed25519_priv_key, "", ""));
auto token =
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::ed25519("", ed25519_priv_key, "", ""));
auto decoded = jwt::decode(token);
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key, "", "", "")).verify(decoded));
ASSERT_THROW(
jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key_invalid, "", "", "")).verify(decoded),
jwt::signature_verification_exception);
ASSERT_NO_THROW(
jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key, "", "", "")).verify(decoded));
}
TEST(TokenTest, CreateTokenEd448) {
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::ed448("", ed448_priv_key, "", ""));
auto token =
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::ed448("", ed448_priv_key, "", ""));
auto decoded = jwt::decode(token);
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
ASSERT_THROW(
jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key_invalid, "", "", "")).verify(decoded),
jwt::signature_verification_exception);
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key, "", "", "")).verify(decoded));
}
#endif
TEST(TokenTest, VerifyTokenWrongAlgorithm) {
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
std::string token =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::none{})
.with_issuer("auth0");
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -234,8 +221,7 @@ TEST(TokenTest, VerifyTokenNoneFail) {
// None algorithm should not have a signature
std::string token = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpYXQiOjE1OTUyNjc1MTZ9.cmFuZG9tc2ln";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::none{});
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::none{});
auto decoded_token = jwt::decode(token);
@@ -243,22 +229,22 @@ TEST(TokenTest, VerifyTokenNoneFail) {
}
TEST(TokenTest, VerifyTokenRS256FailNoKey) {
ASSERT_THROW([](){
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::rs256("", "", "", ""))
.with_issuer("auth0");
}(), jwt::rsa_exception);
ASSERT_THROW(
[]() {
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs256("", "", "", "")).with_issuer("auth0");
}(),
jwt::rsa_exception);
}
TEST(TokenTest, VerifyTokenRS256) {
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
std::string token =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""))
.with_issuer("auth0");
auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", "")).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -266,14 +252,13 @@ TEST(TokenTest, VerifyTokenRS256) {
}
TEST(TokenTest, VerifyTokenRS256PublicOnly) {
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
std::string token =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, "", "", ""))
.with_issuer("auth0");
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, "", "", "")).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -281,14 +266,13 @@ TEST(TokenTest, VerifyTokenRS256PublicOnly) {
}
TEST(TokenTest, VerifyTokenRS256PrivateOnly) {
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
std::string token =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::rs256("", rsa_priv_key, "", ""))
.with_issuer("auth0");
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs256("", rsa_priv_key, "", "")).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -296,14 +280,14 @@ TEST(TokenTest, VerifyTokenRS256PrivateOnly) {
}
TEST(TokenTest, VerifyTokenRS256Fail) {
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
std::string token =
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key_invalid, "", "", ""))
.with_issuer("auth0");
auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key_invalid, "", "", "")).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -311,7 +295,8 @@ TEST(TokenTest, VerifyTokenRS256Fail) {
}
TEST(TokenTest, VerifyTokenRS512) {
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
std::string token =
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
@@ -325,13 +310,12 @@ TEST(TokenTest, VerifyTokenRS512) {
}
TEST(TokenTest, VerifyTokenRS512PublicOnly) {
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
std::string token =
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::rs512(rsa512_pub_key, "", "", ""))
.with_issuer("auth0");
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs512(rsa512_pub_key, "", "", "")).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -339,13 +323,13 @@ TEST(TokenTest, VerifyTokenRS512PublicOnly) {
}
TEST(TokenTest, VerifyTokenRS512PrivateOnly) {
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
std::string token =
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::rs512("", rsa512_priv_key, "", ""))
.with_issuer("auth0");
auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::rs512("", rsa512_priv_key, "", "")).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -353,13 +337,13 @@ TEST(TokenTest, VerifyTokenRS512PrivateOnly) {
}
TEST(TokenTest, VerifyTokenRS512Fail) {
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
std::string token =
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::rs512(rsa_pub_key_invalid, "", "", ""))
.with_issuer("auth0");
auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::rs512(rsa_pub_key_invalid, "", "", "")).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -367,33 +351,30 @@ TEST(TokenTest, VerifyTokenRS512Fail) {
}
TEST(TokenTest, VerifyTokenHS256) {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
.with_issuer("auth0");
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"secret"}).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
verify.verify(decoded_token);
}
TEST(TokenTest, VerifyTokenHS256Fail) {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::hs256{ "wrongsecret" })
.with_issuer("auth0");
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"wrongsecret"}).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
}
TEST(TokenTest, VerifyTokenHS256FailSignatureLength) {
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkA";
std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkA";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
.with_issuer("auth0");
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"secret"}).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
@@ -411,30 +392,24 @@ TEST(TokenTest, VerifyFail) {
auto decoded_token = jwt::decode(token);
{
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::none{})
.with_issuer("auth");
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth");
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
}
{
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::none{})
.with_issuer("auth0")
.with_audience(std::set<std::string>{ "test" });
.with_audience(std::set<std::string>{"test"});
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
}
{
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::none{})
.with_issuer("auth0")
.with_audience("test");
auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth0").with_audience("test");
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
}
{
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::none{})
.with_issuer("auth0")
.with_subject("test");
auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth0").with_subject("test");
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
}
{
@@ -453,7 +428,7 @@ TEST(TokenTest, VerifyFail) {
}
{
jwt::claim object;
std::istringstream iss{ R"({ "test": null })" };
std::istringstream iss{R"({ "test": null })"};
iss >> object;
ASSERT_EQ(object.get_type(), jwt::json::type::object);
@@ -465,33 +440,29 @@ TEST(TokenTest, VerifyFail) {
}
}
{
auto token = jwt::create()
.set_issuer("auth0")
.set_type("JWS")
.sign(jwt::algorithm::none{});
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::none{});
auto decoded_token = jwt::decode(token);
{
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::none{})
.with_issuer("auth0")
.with_audience("test");
auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth0").with_audience("test");
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
}
}
}
TEST(TokenTest, VerifyTokenES256FailNoKey) {
ASSERT_THROW([](){
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::es256("", "", "", ""))
.with_issuer("auth0");
}(), jwt::ecdsa_exception);
ASSERT_THROW(
[]() {
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es256("", "", "", "")).with_issuer("auth0");
}(),
jwt::ecdsa_exception);
}
TEST(TokenTest, VerifyTokenES256) {
const std::string token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
const std::string token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_"
"4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key, "", "", ""));
auto decoded_token = jwt::decode(token);
@@ -500,17 +471,19 @@ TEST(TokenTest, VerifyTokenES256) {
}
TEST(TokenTest, VerifyTokenES256Fail) {
const std::string token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
const std::string token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_"
"4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key_invalid, "", "", ""));
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key_invalid, "", "", ""));
auto decoded_token = jwt::decode(token);
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
}
TEST(TokenTest, VerifyTokenES384) {
const std::string token = "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.nTUwWanmj_K1VZM5it1ES-1FbnmRDL-lH3V_Fem-AhMur9Q61yZfKIydrpdavkm_SMxEsUGPVoqkpoEsjFjrtzMDs5s9yaFYD_ydiy1dsn9VbcI55voA3XwEcWFiPHri";
const std::string token =
"eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.nTUwWanmj_K1VZM5it1ES-1FbnmRDL-lH3V_Fem-"
"AhMur9Q61yZfKIydrpdavkm_SMxEsUGPVoqkpoEsjFjrtzMDs5s9yaFYD_ydiy1dsn9VbcI55voA3XwEcWFiPHri";
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key, "", "", ""));
auto decoded_token = jwt::decode(token);
@@ -519,17 +492,21 @@ TEST(TokenTest, VerifyTokenES384) {
}
TEST(TokenTest, VerifyTokenES384Fail) {
const std::string token = "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.nTUwWanmj_K1VZM5it1ES-1FbnmRDL-lH3V_Fem-AhMur9Q61yZfKIydrpdavkm_SMxEsUGPVoqkpoEsjFjrtzMDs5s9yaFYD_ydiy1dsn9VbcI55voA3XwEcWFiPHri";
const std::string token =
"eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.nTUwWanmj_K1VZM5it1ES-1FbnmRDL-lH3V_Fem-"
"AhMur9Q61yZfKIydrpdavkm_SMxEsUGPVoqkpoEsjFjrtzMDs5s9yaFYD_ydiy1dsn9VbcI55voA3XwEcWFiPHri";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key_invalid, "", "", ""));
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key_invalid, "", "", ""));
auto decoded_token = jwt::decode(token);
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
}
TEST(TokenTest, VerifyTokenES521) {
const std::string token = "eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.ASF5hh9_Jyujzm3GRBttoth-3I6lCcwqun9Tt7Ekz9_23BN6-BFgwKidECWCNc4VINEqFEFdApC2y3YRdkpKX2etAWI7yYudAlxJ7Z17m6GwAoLOGaeNonsaKOe1UnC5W86eoXrCoPRgzsFTpKIb8NiolcYWjIY-r8gQd7BZ7whaj9Ft";
const std::string token =
"eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.ASF5hh9_Jyujzm3GRBttoth-3I6lCcwqun9Tt7Ekz9_23BN6-"
"BFgwKidECWCNc4VINEqFEFdApC2y3YRdkpKX2etAWI7yYudAlxJ7Z17m6GwAoLOGaeNonsaKOe1UnC5W86eoXrCoPRgzsFTpKIb8NiolcYWjIY"
"-r8gQd7BZ7whaj9Ft";
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key, "", "", ""));
auto decoded_token = jwt::decode(token);
@@ -538,24 +515,26 @@ TEST(TokenTest, VerifyTokenES521) {
}
TEST(TokenTest, VerifyTokenES521Fail) {
const std::string token = "eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.ASF5hh9_Jyujzm3GRBttoth-3I6lCcwqun9Tt7Ekz9_23BN6-BFgwKidECWCNc4VINEqFEFdApC2y3YRdkpKX2etAWI7yYudAlxJ7Z17m6GwAoLOGaeNonsaKOe1UnC5W86eoXrCoPRgzsFTpKIb8NiolcYWjIY-r8gQd7BZ7whaj9Ft";
const std::string token =
"eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.ASF5hh9_Jyujzm3GRBttoth-3I6lCcwqun9Tt7Ekz9_23BN6-"
"BFgwKidECWCNc4VINEqFEFdApC2y3YRdkpKX2etAWI7yYudAlxJ7Z17m6GwAoLOGaeNonsaKOe1UnC5W86eoXrCoPRgzsFTpKIb8NiolcYWjIY"
"-r8gQd7BZ7whaj9Ft";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key_invalid, "", "", ""));
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key_invalid, "", "", ""));
auto decoded_token = jwt::decode(token);
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
}
TEST(TokenTest, VerifyTokenPS256) {
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
std::string token =
"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", ""))
.with_issuer("auth0");
auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", "")).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -563,14 +542,13 @@ TEST(TokenTest, VerifyTokenPS256) {
}
TEST(TokenTest, VerifyTokenPS256PublicOnly) {
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
std::string token =
"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, "", "", ""))
.with_issuer("auth0");
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, "", "", "")).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -578,14 +556,14 @@ TEST(TokenTest, VerifyTokenPS256PublicOnly) {
}
TEST(TokenTest, VerifyTokenPS256Fail) {
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
std::string token =
"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key_invalid, "", "", ""))
.with_issuer("auth0");
auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::ps256(rsa_pub_key_invalid, "", "", "")).with_issuer("auth0");
auto decoded_token = jwt::decode(token);
@@ -593,16 +571,17 @@ TEST(TokenTest, VerifyTokenPS256Fail) {
}
TEST(TokenTest, VerifyTokenPS256FailNoKey) {
ASSERT_THROW([](){
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::ps256("", "", "", ""))
.with_issuer("auth0");
}(), jwt::rsa_exception);
ASSERT_THROW(
[]() {
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ps256("", "", "", "")).with_issuer("auth0");
}(),
jwt::rsa_exception);
}
#ifndef OPENSSL110
TEST(TokenTest, VerifyTokenEd25519) {
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
const std::string token =
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
"DOnKiNmc0O2AnvQlzr-9cgI4QGQzeC6gz_fgLoesADg";
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key, "", "", ""));
@@ -612,18 +591,19 @@ TEST(TokenTest, VerifyTokenEd25519) {
}
TEST(TokenTest, VerifyTokenEd25519Fail) {
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
const std::string token =
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
"DOnKiNmc0O2AnvQlzr-9cgI4QGQzeC6gz_fgLoesADg";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key_invalid, "", "", ""));
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key_invalid, "", "", ""));
auto decoded_token = jwt::decode(token);
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
}
TEST(TokenTest, VerifyTokenEd448) {
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
const std::string token =
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
"Bsw_3MHs8HtgKeXbqKFYWpHOCtmZJcH-AWMvoY6FCNdQqbESGTkv58O6tFbXDD_nLejWNAOuvcO2LPMySmkVNQUopmQf_HO62Mug1ngepUDE"
"A";
@@ -634,12 +614,12 @@ TEST(TokenTest, VerifyTokenEd448) {
}
TEST(TokenTest, VerifyTokenEd448Fail) {
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
const std::string token =
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
"Bsw_3MHs8HtgKeXbqKFYWpHOCtmZJcH-AWMvoY6FCNdQqbESGTkv58O6tFbXDD_nLejWNAOuvcO2LPMySmkVNQUopmQf_HO62Mug1ngepUDE"
"A";
auto verify = jwt::verify()
.allow_algorithm(jwt::algorithm::ed448(ed448_pub_key_invalid, "", "", ""));
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key_invalid, "", "", ""));
auto decoded_token = jwt::decode(token);
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
@@ -648,9 +628,7 @@ TEST(TokenTest, VerifyTokenEd448Fail) {
struct test_clock {
jwt::date n;
jwt::date now() const {
return n;
}
jwt::date now() const { return n; }
};
TEST(TokenTest, VerifyTokenExpireFail) {
@@ -757,7 +735,6 @@ TEST(TokenTest, ThrowInvalidKeyLength) {
ASSERT_THROW(jwt::algorithm::es256(ecdsa384_pub_key, ecdsa256_priv_key), jwt::ecdsa_exception);
ASSERT_THROW(jwt::algorithm::es256(ecdsa521_pub_key, ecdsa256_priv_key), jwt::ecdsa_exception);
ASSERT_THROW(jwt::algorithm::es384(ecdsa256_pub_key, ""), jwt::ecdsa_exception);
ASSERT_THROW(jwt::algorithm::es384("", ecdsa256_priv_key), jwt::ecdsa_exception);
ASSERT_THROW(jwt::algorithm::es384(ecdsa256_pub_key, ecdsa256_priv_key), jwt::ecdsa_exception);
@@ -770,7 +747,6 @@ TEST(TokenTest, ThrowInvalidKeyLength) {
ASSERT_THROW(jwt::algorithm::es384(ecdsa256_pub_key, ecdsa384_priv_key), jwt::ecdsa_exception);
ASSERT_THROW(jwt::algorithm::es384(ecdsa521_pub_key, ecdsa384_priv_key), jwt::ecdsa_exception);
ASSERT_THROW(jwt::algorithm::es512(ecdsa256_pub_key, ""), jwt::ecdsa_exception);
ASSERT_THROW(jwt::algorithm::es512("", ecdsa256_priv_key), jwt::ecdsa_exception);
ASSERT_THROW(jwt::algorithm::es512(ecdsa256_pub_key, ecdsa256_priv_key), jwt::ecdsa_exception);

View File

@@ -1,5 +1,5 @@
#ifndef JWT_DISABLE_BASE64
#error "This test expects 'JWT_DISABLE_BASE64' to be defined!"
#error "This test expects 'JWT_DISABLE_BASE64' to be defined!"
#endif
#include "jwt-cpp/jwt.h"

View File

@@ -1,5 +1,5 @@
#if !__has_include(<tls.h>)
#error "missing LibreSSL's TLS header!
#error "missing LibreSSL's TLS header!
#endif
#include <tls.h>

View File

@@ -1,5 +1,5 @@
#ifndef JWT_DISABLE_PICOJSON
#error "This test expects 'JWT_DISABLE_PICOJSON' to be defined!"
#error "This test expects 'JWT_DISABLE_PICOJSON' to be defined!"
#endif
#include "jwt-cpp/jwt.h"

View File

@@ -8,64 +8,51 @@
#include <sstream>
struct jsoncons_traits
{
struct jsoncons_traits {
using json = jsoncons::json;
using value_type = json;
struct object_type : json::object
{
struct object_type : json::object {
using value_type = key_value_type;
using mapped_type = key_value_type::value_type; // https://github.com/danielaparker/jsoncons/commit/1b1ceeb572f9a2db6d37cff47ac78a4f14e072e2#commitcomment-45391411
using mapped_type = key_value_type::
value_type; // https://github.com/danielaparker/jsoncons/commit/1b1ceeb572f9a2db6d37cff47ac78a4f14e072e2#commitcomment-45391411
object_type() = default;
object_type(const object_type &) = default;
object_type(const json::object &o) : json::object(o) {}
object_type(object_type &&) = default;
object_type(json::object &&o) : json::object(o) {}
object_type &operator=(const object_type &o)
{
object_type(const object_type&) = default;
object_type(const json::object& o) : json::object(o) {}
object_type(object_type&&) = default;
object_type(json::object&& o) : json::object(o) {}
object_type& operator=(const object_type& o) {
// avoid private deleted copy operator= https://github.com/danielaparker/jsoncons/pull/298
object_type t(static_cast<const json::object &>(o));
object_type t(static_cast<const json::object&>(o));
(*this) = std::move(t);
return *this;
}
object_type &operator=(object_type &&o) noexcept
{
object_type& operator=(object_type&& o) noexcept {
swap(o);
return *this;
}
mapped_type &operator[](const key_type &key)
{
auto ret = try_emplace(key); // https://github.com/microsoft/STL/blob/2914b4301c59dc7ffc09d16ac6f7979fde2b7f2c/stl/inc/map#L325
mapped_type& operator[](const key_type& key) {
auto ret = try_emplace(
key); // https://github.com/microsoft/STL/blob/2914b4301c59dc7ffc09d16ac6f7979fde2b7f2c/stl/inc/map#L325
return ret.first->value();
}
mapped_type &operator[](key_type &&key)
{
mapped_type& operator[](key_type&& key) {
auto ret = try_emplace(key);
return ret.first->value();
}
const mapped_type &at(const key_type &key) const
{
const mapped_type& at(const key_type& key) const {
auto target = find(key);
if (target != end())
{
return target->value();
}
if (target != end()) { return target->value(); }
std::out_of_range("invalid key");
}
size_t count(const key_type &key) const
{
size_t count(const key_type& key) const {
size_t ret = 0;
for (const_iterator first = begin(); first != end(); ++first)
{
if (first->key() == key)
{
++ret;
}
for (const_iterator first = begin(); first != end(); ++first) {
if (first->key() == key) { ++ret; }
}
return ret;
}
@@ -76,88 +63,64 @@ struct jsoncons_traits
using integer_type = int64_t;
using boolean_type = bool;
static jwt::json::type get_type(const json &val)
{
static jwt::json::type get_type(const json& val) {
using jwt::json::type;
if (val.type() == jsoncons::json_type::bool_value)
return type::boolean;
if (val.type() == jsoncons::json_type::int64_value)
return type::integer;
if (val.type() == jsoncons::json_type::uint64_value)
return type::integer;
if (val.type() == jsoncons::json_type::half_value)
return type::number;
if (val.type() == jsoncons::json_type::double_value)
return type::number;
if (val.type() == jsoncons::json_type::string_value)
return type::string;
if (val.type() == jsoncons::json_type::array_value)
return type::array;
if (val.type() == jsoncons::json_type::object_value)
return type::object;
if (val.type() == jsoncons::json_type::bool_value) return type::boolean;
if (val.type() == jsoncons::json_type::int64_value) return type::integer;
if (val.type() == jsoncons::json_type::uint64_value) return type::integer;
if (val.type() == jsoncons::json_type::half_value) return type::number;
if (val.type() == jsoncons::json_type::double_value) return type::number;
if (val.type() == jsoncons::json_type::string_value) return type::string;
if (val.type() == jsoncons::json_type::array_value) return type::array;
if (val.type() == jsoncons::json_type::object_value) return type::object;
throw std::logic_error("invalid type");
}
static object_type as_object(const json &val)
{
if (val.type() != jsoncons::json_type::object_value)
throw std::bad_cast();
static object_type as_object(const json& val) {
if (val.type() != jsoncons::json_type::object_value) throw std::bad_cast();
return object_type(val.object_value());
}
static array_type as_array(const json &val)
{
if (val.type() != jsoncons::json_type::array_value)
throw std::bad_cast();
static array_type as_array(const json& val) {
if (val.type() != jsoncons::json_type::array_value) throw std::bad_cast();
return val.array_value();
}
static string_type as_string(const json &val)
{
if (val.type() != jsoncons::json_type::string_value)
throw std::bad_cast();
static string_type as_string(const json& val) {
if (val.type() != jsoncons::json_type::string_value) throw std::bad_cast();
return val.as_string();
}
static number_type as_number(const json &val)
{
if (get_type(val) != jwt::json::type::number)
throw std::bad_cast();
static number_type as_number(const json& val) {
if (get_type(val) != jwt::json::type::number) throw std::bad_cast();
return val.as_double();
}
static integer_type as_int(const json &val)
{
if (get_type(val) != jwt::json::type::integer)
throw std::bad_cast();
static integer_type as_int(const json& val) {
if (get_type(val) != jwt::json::type::integer) throw std::bad_cast();
return val.as<integer_type>();
}
static boolean_type as_bool(const json &val)
{
if (val.type() != jsoncons::json_type::bool_value)
throw std::bad_cast();
static boolean_type as_bool(const json& val) {
if (val.type() != jsoncons::json_type::bool_value) throw std::bad_cast();
return val.as_bool();
}
static bool parse(json &val, std::string str)
{
static bool parse(json& val, std::string str) {
val = json::parse(str);
return true;
}
static std::string serialize(const json &val)
{
static std::string serialize(const json& val) {
std::ostringstream os;
os << jsoncons::print(val);
return os.str();
}
};
TEST(JsonconsTest, BasicClaims)
{
TEST(JsonconsTest, BasicClaims) {
using jsoncons_claim = jwt::basic_claim<jsoncons_traits>;
const auto string = jsoncons_claim(std::string("string"));
@@ -165,11 +128,9 @@ TEST(JsonconsTest, BasicClaims)
const auto integer = jsoncons_claim(159816816);
}
TEST(JsonconsTest, AudienceAsString)
{
TEST(JsonconsTest, AudienceAsString) {
std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
"WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
auto decoded = jwt::decode<jsoncons_traits>(token);
@@ -192,34 +153,29 @@ TEST(JsonconsTest, AudienceAsString)
ASSERT_EQ("test", *aud.begin());
}
TEST(JsonconsTest, SetArray)
{
std::vector<int64_t> vect = {
100,
20,
10};
TEST(JsonconsTest, SetArray) {
std::vector<int64_t> vect = {100, 20, 10};
auto token = jwt::create<jsoncons_traits>()
.set_payload_claim("test", jwt::basic_claim<jsoncons_traits>(vect.begin(), vect.end()))
.sign(jwt::algorithm::none{});
ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0.");
}
TEST(JsonconsTest, SetObject)
{
TEST(JsonconsTest, SetObject) {
std::istringstream iss{"{\"api-x\": [1]}"};
jwt::basic_claim<jsoncons_traits> object;
iss >> object;
ASSERT_EQ(object.get_type(), jwt::json::type::object);
auto token = jwt::create<jsoncons_traits>()
.set_payload_claim("namespace", object)
.sign(jwt::algorithm::hs256("test"));
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
auto token =
jwt::create<jsoncons_traits>().set_payload_claim("namespace", object).sign(jwt::algorithm::hs256("test"));
ASSERT_EQ(token,
"eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
}
TEST(JsonconsTest, VerifyTokenHS256)
{
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
TEST(JsonconsTest, VerifyTokenHS256) {
std::string token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
auto verify = jwt::verify<jwt::default_clock, jsoncons_traits>({})
.allow_algorithm(jwt::algorithm::hs256{"secret"})
@@ -229,8 +185,7 @@ TEST(JsonconsTest, VerifyTokenHS256)
verify.verify(decoded_token);
}
TEST(JsonconsTest, VerifyTokenExpirationValid)
{
TEST(JsonconsTest, VerifyTokenExpirationValid) {
const auto token = jwt::create<jsoncons_traits>()
.set_issuer("auth0")
.set_issued_at(std::chrono::system_clock::now())
@@ -245,8 +200,7 @@ TEST(JsonconsTest, VerifyTokenExpirationValid)
verify.verify(decoded_token);
}
TEST(JsonconsTest, VerifyTokenExpired)
{
TEST(JsonconsTest, VerifyTokenExpired) {
const auto token = jwt::create<jsoncons_traits>()
.set_issuer("auth0")
.set_issued_at(std::chrono::system_clock::now() - std::chrono::seconds{3601})

View File

@@ -1,5 +0,0 @@
Source: jwt-cpp
Version: 2019-04-20
Description: A header only library for creating and validating json web tokens in c++
Build-Depends: openssl
Homepage: https://thalhammer.it/projects/jwt_cpp

View File

@@ -1,31 +0,0 @@
diff --git a/include/jwt-cpp/base.h b/include/jwt-cpp/base.h
index dfca7fc..4d05c0b 100644
--- a/include/jwt-cpp/base.h
+++ b/include/jwt-cpp/base.h
@@ -2,6 +2,10 @@
#include <string>
#include <array>
+#ifdef _MSC_VER
+#pragma warning(disable : 4267)
+#endif
+
namespace jwt {
namespace alphabet {
struct base64 {
diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h
index ec56810..313cef2 100644
--- a/include/jwt-cpp/jwt.h
+++ b/include/jwt-cpp/jwt.h
@@ -12,6 +12,11 @@
#include <openssl/ec.h>
#include <openssl/err.h>
+#ifdef _MSC_VER
+#pragma warning(disable : 4267)
+#pragma warning(disable : 4067)
+#endif
+
//If openssl version less than 1.1
#if OPENSSL_VERSION_NUMBER < 269484032
#define OPENSSL10

View File

@@ -1,23 +0,0 @@
#header-only library
include(vcpkg_common_functions)
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO Thalhammer/jwt-cpp
REF f0e37a79f605312686065405dd720fc197cc3df0
SHA512 ae83c205dbb340dedc58d0d3f0e2453c4edcf5ce43b401f49d02692dc8a2a4b7260f1ced05ddfa7c1d5d6f92446e232629ddbdf67a58a119b50c5c8163591598
PATCHES fix-warning.patch)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}/jwt-cpp
OPTIONS -DBUILD_TESTS=OFF)
# Copy the constexpr header files
vcpkg_install_cmake()
vcpkg_test_cmake(PACKAGE_NAME jwt-cpp)
# Put the licence file where vcpkg expects it
file(COPY ${SOURCE_PATH}/LICENSE
DESTINATION ${CURRENT_PACKAGES_DIR}/share/jwt-cpp)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/jwt-cpp/LICENSE ${CURRENT_PACKAGES_DIR}/share/jwt-cpp/copyright)