mirror of
https://github.com/allankoechke/jwt-cpp.git
synced 2026-11-30 10:18:40 +00:00
🧰 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:
22
.clang-format
Normal file
22
.clang-format
Normal 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
17
.editorconfig
Normal 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
|
||||||
20
.github/actions/install/gtest/action.yml
vendored
20
.github/actions/install/gtest/action.yml
vendored
@@ -3,13 +3,13 @@ description: Install and setup GTest for linking and building test application
|
|||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- run: sudo apt-get install libgtest-dev lcov
|
- run: sudo apt-get install libgtest-dev lcov
|
||||||
shell: bash
|
shell: bash
|
||||||
- run: (cd /usr/src/gtest && sudo `which cmake` .)
|
- run: (cd /usr/src/gtest && sudo `which cmake` .)
|
||||||
shell: bash
|
shell: bash
|
||||||
- run: sudo make -j $(nproc) -C /usr/src/gtest
|
- run: sudo make -j $(nproc) -C /usr/src/gtest
|
||||||
shell: bash
|
shell: bash
|
||||||
- run: sudo ln -s /usr/src/gtest/libgtest.a /usr/lib/libgtest.a
|
- run: sudo ln -s /usr/src/gtest/libgtest.a /usr/lib/libgtest.a
|
||||||
shell: bash
|
shell: bash
|
||||||
- run: sudo ln -s /usr/src/gtest/libgtest_main.a /usr/lib/libgtest_main.a
|
- run: sudo ln -s /usr/src/gtest/libgtest_main.a /usr/lib/libgtest_main.a
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
18
.github/actions/install/jsoncons/action.yml
vendored
18
.github/actions/install/jsoncons/action.yml
vendored
@@ -4,15 +4,15 @@ inputs:
|
|||||||
version:
|
version:
|
||||||
description: The desired jsoncons version to install
|
description: The desired jsoncons version to install
|
||||||
required: false
|
required: false
|
||||||
default: '0.159.0'
|
default: "0.159.0"
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- run: |
|
- run: |
|
||||||
cd /tmp
|
cd /tmp
|
||||||
wget https://github.com/danielaparker/jsoncons/archive/v${{ inputs.version }}.tar.gz
|
wget https://github.com/danielaparker/jsoncons/archive/v${{ inputs.version }}.tar.gz
|
||||||
tar -zvxf /tmp/v${{ inputs.version }}.tar.gz
|
tar -zvxf /tmp/v${{ inputs.version }}.tar.gz
|
||||||
cd jsoncons-${{ inputs.version }}
|
cd jsoncons-${{ inputs.version }}
|
||||||
cmake .
|
cmake .
|
||||||
sudo cmake --install .
|
sudo cmake --install .
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
20
.github/actions/install/libressl/action.yml
vendored
20
.github/actions/install/libressl/action.yml
vendored
@@ -4,16 +4,16 @@ inputs:
|
|||||||
version:
|
version:
|
||||||
description: The desired LibreSSL version to install
|
description: The desired LibreSSL version to install
|
||||||
required: false
|
required: false
|
||||||
default: '3.3.0'
|
default: "3.3.0"
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- run: |
|
- run: |
|
||||||
wget https://raw.githubusercontent.com/libressl-portable/portable/v${{ inputs.version }}/FindLibreSSL.cmake -P cmake/
|
wget https://raw.githubusercontent.com/libressl-portable/portable/v${{ inputs.version }}/FindLibreSSL.cmake -P cmake/
|
||||||
cd /tmp
|
cd /tmp
|
||||||
wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${{ inputs.version }}.tar.gz
|
wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${{ inputs.version }}.tar.gz
|
||||||
tar -zvxf /tmp/libressl-${{ inputs.version }}.tar.gz
|
tar -zvxf /tmp/libressl-${{ inputs.version }}.tar.gz
|
||||||
cd libressl-${{ inputs.version }}
|
cd libressl-${{ inputs.version }}
|
||||||
./configure
|
./configure
|
||||||
sudo make -j $(nproc) install
|
sudo make -j $(nproc) install
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
16
.github/logo.svg
vendored
Normal file
16
.github/logo.svg
vendored
Normal 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 |
167
.github/workflows/cmake.yml
vendored
167
.github/workflows/cmake.yml
vendored
@@ -1,119 +1,120 @@
|
|||||||
name: CMake Integration CI
|
name: CMake CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
paths:
|
paths:
|
||||||
- 'CMakeLists.txt'
|
- "CMakeLists.txt"
|
||||||
- 'include/jwt-cpp/**'
|
- "include/jwt-cpp/**"
|
||||||
- 'tests/cmake/**'
|
- "tests/cmake/**"
|
||||||
- '.github/workflows/cmake.yml'
|
- ".github/actions/**"
|
||||||
|
- ".github/workflows/cmake.yml"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
min-req:
|
min-req:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: install cmake
|
- name: install cmake
|
||||||
run: |
|
run: |
|
||||||
wget https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz
|
wget https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz
|
||||||
tar -zxf cmake-3.8.2.tar.gz
|
tar -zxf cmake-3.8.2.tar.gz
|
||||||
cd cmake-3.8.2
|
cd cmake-3.8.2
|
||||||
./bootstrap && make -j $(nproc) && sudo make install
|
./bootstrap && make -j $(nproc) && sudo make install
|
||||||
|
|
||||||
- name: setup
|
- name: setup
|
||||||
run: |
|
run: |
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake .. -DJWT_BUILD_EXAMPLES=OFF
|
cmake .. -DJWT_BUILD_EXAMPLES=OFF
|
||||||
sudo make install
|
sudo make install
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: |
|
run: |
|
||||||
cd tests/cmake
|
cd tests/cmake
|
||||||
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DTEST:STRING="defaults-enabled"
|
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DTEST:STRING="defaults-enabled"
|
||||||
cmake --build .
|
cmake --build .
|
||||||
|
|
||||||
custom-install:
|
custom-install:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: install cmake
|
- name: install cmake
|
||||||
uses: lukka/get-cmake@latest
|
uses: lukka/get-cmake@latest
|
||||||
|
|
||||||
- name: setup
|
- name: setup
|
||||||
run: |
|
run: |
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake .. -DCMAKE_INSTALL_PREFIX:STRING="/opt/jwt-cpp" -DJWT_BUILD_EXAMPLES=OFF
|
cmake .. -DCMAKE_INSTALL_PREFIX:STRING="/opt/jwt-cpp" -DJWT_BUILD_EXAMPLES=OFF
|
||||||
make install
|
make install
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: |
|
run: |
|
||||||
cd tests/cmake
|
cd tests/cmake
|
||||||
cmake . -DCMAKE_PREFIX_PATH=/opt/jwt-cpp/cmake -DTEST:STRING="defaults-enabled"
|
cmake . -DCMAKE_PREFIX_PATH=/opt/jwt-cpp/cmake -DTEST:STRING="defaults-enabled"
|
||||||
cmake --build .
|
cmake --build .
|
||||||
|
|
||||||
no-pico:
|
no-pico:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: install cmake
|
- name: install cmake
|
||||||
uses: lukka/get-cmake@latest
|
uses: lukka/get-cmake@latest
|
||||||
|
|
||||||
- name: setup
|
- name: setup
|
||||||
run: |
|
run: |
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake .. -DJWT_DISABLE_PICOJSON=ON -DJWT_BUILD_EXAMPLES=OFF
|
cmake .. -DJWT_DISABLE_PICOJSON=ON -DJWT_BUILD_EXAMPLES=OFF
|
||||||
sudo make install
|
sudo make install
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: |
|
run: |
|
||||||
cd tests/cmake
|
cd tests/cmake
|
||||||
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DTEST:STRING="picojson-is-disabled"
|
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DTEST:STRING="picojson-is-disabled"
|
||||||
cmake --build .
|
cmake --build .
|
||||||
|
|
||||||
no-base64:
|
no-base64:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: install cmake
|
- name: install cmake
|
||||||
uses: lukka/get-cmake@latest
|
uses: lukka/get-cmake@latest
|
||||||
|
|
||||||
- name: setup
|
- name: setup
|
||||||
run: |
|
run: |
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake .. -DJWT_DISABLE_BASE64=ON -DJWT_BUILD_EXAMPLES=OFF
|
cmake .. -DJWT_DISABLE_BASE64=ON -DJWT_BUILD_EXAMPLES=OFF
|
||||||
sudo make install
|
sudo make install
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: |
|
run: |
|
||||||
cd tests/cmake
|
cd tests/cmake
|
||||||
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DTEST:STRING="base64-is-disabled"
|
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DTEST:STRING="base64-is-disabled"
|
||||||
cmake --build .
|
cmake --build .
|
||||||
|
|
||||||
with-libressl:
|
with-libressl:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: install cmake
|
- name: install cmake
|
||||||
uses: lukka/get-cmake@latest
|
uses: lukka/get-cmake@latest
|
||||||
- name: install libressl
|
- name: install libressl
|
||||||
uses: ./.github/actions/install/libressl
|
uses: ./.github/actions/install/libressl
|
||||||
|
|
||||||
- name: setup
|
- name: setup
|
||||||
run: |
|
run: |
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake .. -DJWT_SSL_LIBRARY:STRING="LibreSSL" -DJWT_BUILD_EXAMPLES=OFF
|
cmake .. -DJWT_SSL_LIBRARY:STRING="LibreSSL" -DJWT_BUILD_EXAMPLES=OFF
|
||||||
sudo make install
|
sudo make install
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: |
|
run: |
|
||||||
cd tests/cmake
|
cd tests/cmake
|
||||||
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DCMAKE_MODULE_PATH=../../cmake -DTEST:STRING="libressl-is-used"
|
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake -DCMAKE_MODULE_PATH=../../cmake -DTEST:STRING="libressl-is-used"
|
||||||
cmake --build .
|
cmake --build .
|
||||||
|
|||||||
52
.github/workflows/coverage.yml
vendored
52
.github/workflows/coverage.yml
vendored
@@ -2,38 +2,36 @@ name: Coverage CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
paths:
|
paths:
|
||||||
- 'CMakeLists.txt'
|
- "CMakeLists.txt"
|
||||||
- 'include/jwt-cpp/**'
|
- "include/jwt-cpp/**"
|
||||||
- 'tests/*'
|
- "tests/*"
|
||||||
- '.github/workflows/coverate.yml'
|
- ".github/actions/**"
|
||||||
|
- ".github/workflows/coverate.yml"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: install cmake
|
- uses: lukka/get-cmake@latest
|
||||||
uses: lukka/get-cmake@latest
|
- uses: ./.github/actions/install/gtest
|
||||||
- name: install gtest
|
|
||||||
uses: ./.github/actions/install/gtest
|
|
||||||
|
|
||||||
- name: configure
|
- name: configure
|
||||||
run: |
|
run: |
|
||||||
mkdir build
|
mkdir build
|
||||||
cd 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
|
- name: run
|
||||||
run: cd build && make jwt-cpp-test coverage
|
run: |
|
||||||
|
cd build
|
||||||
- name: Coveralls GitHub Action
|
make jwt-cpp-test coverage
|
||||||
uses: coverallsapp/github-action@v1.1.1
|
|
||||||
with:
|
- uses: coverallsapp/github-action@v1.1.1
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
with:
|
||||||
path-to-lcov: build/coverage.info
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
path-to-lcov: build/coverage.info
|
||||||
|
|||||||
22
.github/workflows/documentation.yml
vendored
22
.github/workflows/documentation.yml
vendored
@@ -2,20 +2,18 @@ name: Documentation CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
- name: run doxygen
|
||||||
- name: run doxygen
|
uses: mattnotmitt/doxygen-action@v1
|
||||||
uses: mattnotmitt/doxygen-action@v1
|
- name: deploy
|
||||||
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
- name: deploy
|
with:
|
||||||
uses: peaceiris/actions-gh-pages@v3
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
publish_dir: ./docs/html
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
force_orphan: true
|
||||||
publish_dir: ./docs/html
|
|
||||||
force_orphan: true
|
|
||||||
|
|||||||
79
.github/workflows/libresssl.yml
vendored
79
.github/workflows/libresssl.yml
vendored
@@ -2,14 +2,15 @@ name: LibreSSL CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
paths:
|
paths:
|
||||||
- 'CMakeLists.txt'
|
- "CMakeLists.txt"
|
||||||
- 'include/jwt-cpp/**'
|
- "include/jwt-cpp/**"
|
||||||
- 'tests/*'
|
- "tests/*"
|
||||||
- '.github/workflows/libressl.yml'
|
- ".github/actions/**"
|
||||||
|
- ".github/workflows/libressl.yml"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -18,44 +19,40 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
libressl: ["3.3.0", "3.2.2"]
|
libressl: ["3.3.0", "3.2.2"]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: install cmake
|
- uses: lukka/get-cmake@latest
|
||||||
uses: lukka/get-cmake@latest
|
- uses: ./.github/actions/install/gtest
|
||||||
- name: install gtest
|
- uses: ./.github/actions/install/libressl
|
||||||
uses: ./.github/actions/install/gtest
|
with:
|
||||||
- name: install libressl
|
version: ${{ matrix.libressl }}
|
||||||
uses: ./.github/actions/install/libressl
|
|
||||||
with:
|
|
||||||
version: ${{ matrix.libressl }}
|
|
||||||
|
|
||||||
- name: configure
|
- name: configure
|
||||||
run: cmake . -DJWT_BUILD_TESTS=ON -DJWT_SSL_LIBRARY:STRING=LibreSSL
|
run: cmake . -DJWT_BUILD_TESTS=ON -DJWT_SSL_LIBRARY:STRING=LibreSSL
|
||||||
|
|
||||||
- name: make
|
- run: make
|
||||||
run: make
|
|
||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: ./tests/jwt-cpp-test
|
run: ./tests/jwt-cpp-test
|
||||||
|
|
||||||
- name: badge success
|
- name: badge success
|
||||||
if: github.event_name == 'push' && success()
|
if: github.event_name == 'push' && success()
|
||||||
run: |
|
run: |
|
||||||
mkdir -p badges/libressl/${{ matrix.libressl }}
|
mkdir -p badges/libressl/${{ matrix.libressl }}
|
||||||
echo '{ "schemaVersion": 1, "label": "${{ matrix.libressl }}", "message": "Passing", "color": "brightgreen" }' > badges/libressl/${{ matrix.libressl }}/shields.json
|
echo '{ "schemaVersion": 1, "label": "${{ matrix.libressl }}", "message": "Passing", "color": "brightgreen" }' > badges/libressl/${{ matrix.libressl }}/shields.json
|
||||||
|
|
||||||
- name: badge failure
|
- name: badge failure
|
||||||
if: github.event_name == 'push' && !success()
|
if: github.event_name == 'push' && !success()
|
||||||
run: |
|
run: |
|
||||||
mkdir -p badges/libressl/${{ matrix.libressl }}
|
mkdir -p badges/libressl/${{ matrix.libressl }}
|
||||||
echo '{ "schemaVersion": 1, "label": "${{ matrix.libressl }}", "message": "Failing", "color": "red" }' > badges/libressl/${{ matrix.libressl }}/shields.json
|
echo '{ "schemaVersion": 1, "label": "${{ matrix.libressl }}", "message": "Failing", "color": "red" }' > badges/libressl/${{ matrix.libressl }}/shields.json
|
||||||
|
|
||||||
- name: badge publish
|
- name: badge publish
|
||||||
if: github.event_name == 'push'
|
if: github.event_name == 'push'
|
||||||
uses: peaceiris/actions-gh-pages@v3
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
publish_branch: badges
|
publish_branch: badges
|
||||||
publish_dir: ./badges
|
publish_dir: ./badges
|
||||||
keep_files: true
|
keep_files: true
|
||||||
user_name: 'github-actions[bot]'
|
user_name: "github-actions[bot]"
|
||||||
user_email: 'github-actions[bot]@users.noreply.github.com'
|
user_email: "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|||||||
23
.github/workflows/lint.yml
vendored
Normal file
23
.github/workflows/lint.yml
vendored
Normal 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)
|
||||||
42
.github/workflows/traits.yml
vendored
42
.github/workflows/traits.yml
vendored
@@ -2,29 +2,35 @@ name: Traits CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
|
paths:
|
||||||
|
- "CMakeLists.txt"
|
||||||
|
- "include/jwt-cpp/**"
|
||||||
|
- "tests/jsoncons/**"
|
||||||
|
- ".github/actions/**"
|
||||||
|
- ".github/workflows/traits.yml"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
jsoncons:
|
jsoncons:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: lukka/get-cmake@latest
|
- uses: lukka/get-cmake@latest
|
||||||
- uses: ./.github/actions/install/gtest
|
- uses: ./.github/actions/install/gtest
|
||||||
- uses: ./.github/actions/install/jsoncons
|
- uses: ./.github/actions/install/jsoncons
|
||||||
|
|
||||||
- name: setup
|
- name: setup
|
||||||
run: |
|
run: |
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake .. -DJWT_BUILD_EXAMPLES=OFF
|
cmake .. -DJWT_BUILD_EXAMPLES=OFF
|
||||||
sudo make install
|
sudo make install
|
||||||
|
|
||||||
- name: configure
|
- name: test
|
||||||
run: |
|
run: |
|
||||||
cd tests/jsoncons
|
cd tests/jsoncons
|
||||||
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake
|
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake
|
||||||
cmake --build .
|
cmake --build .
|
||||||
./jsoncons-traits-narrow
|
./jsoncons-traits-narrow
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ set_property(CACHE JWT_SSL_LIBRARY PROPERTY STRINGS ${JWT_SSL_LIBRARY_OPTIONS})
|
|||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||||
|
|
||||||
if(NOT JWT_SSL_LIBRARY IN_LIST JWT_SSL_LIBRARY_OPTIONS)
|
if(NOT JWT_SSL_LIBRARY IN_LIST JWT_SSL_LIBRARY_OPTIONS)
|
||||||
message(FATAL_ERROR "JWT_SSL_LIBRARY must be one of ${JWT_SSL_LIBRARY_OPTIONS}")
|
message(FATAL_ERROR "JWT_SSL_LIBRARY must be one of ${JWT_SSL_LIBRARY_OPTIONS}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(${JWT_SSL_LIBRARY} MATCHES "OpenSSL")
|
if(${JWT_SSL_LIBRARY} MATCHES "OpenSSL")
|
||||||
|
|||||||
20
README.md
20
README.md
@@ -1,4 +1,4 @@
|
|||||||
# jwt-cpp
|
# 
|
||||||
|
|
||||||
[](https://github.com/Thalhammer/jwt-cpp/blob/master/LICENSE)
|
[](https://github.com/Thalhammer/jwt-cpp/blob/master/LICENSE)
|
||||||
[](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)
|
[](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 @@
|
|||||||
[](https://thalhammer.github.io/jwt-cpp/)
|
[](https://thalhammer.github.io/jwt-cpp/)
|
||||||
[](https://github.com/Thalhammer/jwt-cpp/stargazers)
|
[](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
|
## 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.
|
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 the sake of completeness, here is a list of all supported algorithms:
|
|
||||||
|
For completeness, here is a list of all supported algorithms:
|
||||||
|
|
||||||
| HMSC | RSA | ECDSA | PSS | EdDSA |
|
| HMSC | RSA | ECDSA | PSS | EdDSA |
|
||||||
| ----- | ----- | ----- | ----- | ------- |
|
| ----- | ----- | ----- | ----- | ------- |
|
||||||
@@ -22,8 +23,7 @@ For the sake of completeness, here is a list of all supported algorithms:
|
|||||||
|
|
||||||
## SSL Compatability
|
## 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).
|
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:
|
||||||
These are the version which are tested:
|
|
||||||
|
|
||||||
| OpenSSL | LibreSSL |
|
| OpenSSL | LibreSSL |
|
||||||
| -------------- | --------------- |
|
| -------------- | --------------- |
|
||||||
@@ -38,13 +38,13 @@ These are the version which are tested:
|
|||||||
|
|
||||||
## Overview
|
## 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
|
```cpp
|
||||||
jwt::basic_claim<my_favorite_json_library_traits> claim(json::object({{"json", true},{"example", 0}}));
|
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.
|
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
|
### 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
|
```cpp
|
||||||
#include <jwt-cpp/jwt.h>
|
#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.
|
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
|
```cpp
|
||||||
struct my_favorite_json_library_traits {
|
struct my_favorite_json_library_traits {
|
||||||
// Type Specifications
|
// Type Specifications
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
set(COVERAGE_CMAKE "${CMAKE_BINARY_DIR}/cmake/CodeCoverage.cmake")
|
set(COVERAGE_CMAKE "${CMAKE_BINARY_DIR}/cmake/CodeCoverage.cmake")
|
||||||
if(NOT EXISTS ${COVERAGE_CMAKE})
|
if(NOT EXISTS ${COVERAGE_CMAKE})
|
||||||
set(COVERAGE_URL
|
set(COVERAGE_URL "https://raw.githubusercontent.com/bilke/cmake-modules/master/CodeCoverage.cmake")
|
||||||
"https://raw.githubusercontent.com/bilke/cmake-modules/master/CodeCoverage.cmake"
|
|
||||||
)
|
|
||||||
file(DOWNLOAD ${COVERAGE_URL} ${COVERAGE_CMAKE})
|
file(DOWNLOAD ${COVERAGE_URL} ${COVERAGE_CMAKE})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(${COVERAGE_CMAKE})
|
include(${COVERAGE_CMAKE})
|
||||||
|
|
||||||
function(setup_coverage TARGET)
|
function(setup_coverage TARGET)
|
||||||
target_compile_options(${TARGET} PRIVATE -g -O0 -fprofile-arcs
|
target_compile_options(${TARGET} PRIVATE -g -O0 -fprofile-arcs -ftest-coverage)
|
||||||
-ftest-coverage)
|
|
||||||
target_link_libraries(${TARGET} PRIVATE gcov)
|
target_link_libraries(${TARGET} PRIVATE gcov)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|||||||
@@ -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;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,11 +2,11 @@ cmake_minimum_required(VERSION 3.8)
|
|||||||
project(jwt-cpp-examples)
|
project(jwt-cpp-examples)
|
||||||
|
|
||||||
if(NOT TARGET jwt-cpp)
|
if(NOT TARGET jwt-cpp)
|
||||||
find_package(jwt-cpp CONFIG REQUIRED)
|
find_package(jwt-cpp CONFIG REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(JWT_DISABLE_PICOJSON)
|
if(JWT_DISABLE_PICOJSON)
|
||||||
message(FATAL_ERROR "examples require picojson to be available!")
|
message(FATAL_ERROR "examples require picojson to be available!")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(print-claims print-claims.cpp)
|
add_executable(print-claims print-claims.cpp)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
cmake_minimum_required(VERSION 3.8)
|
cmake_minimum_required(VERSION 3.8)
|
||||||
|
|
||||||
project(conan-example)
|
project(conan-example)
|
||||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
|
||||||
conan_basic_setup()
|
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||||
|
conan_basic_setup()
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} main.cpp)
|
add_executable(${PROJECT_NAME} main.cpp)
|
||||||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
|
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
|
||||||
@@ -1,18 +1,17 @@
|
|||||||
Conan example
|
# Conan example
|
||||||
|
|
||||||
|
|
||||||
In the current directory on Linux environment
|
In the current directory on Linux environment
|
||||||
```
|
|
||||||
|
```sh
|
||||||
mkdir build && cd build
|
mkdir build && cd build
|
||||||
conan install .. && cmake ..
|
conan install .. && cmake ..
|
||||||
cmake --build .
|
cmake --build .
|
||||||
```
|
```
|
||||||
|
|
||||||
run executable
|
run executable
|
||||||
```
|
|
||||||
./bin/conan-example
|
```sh
|
||||||
```
|
$ ./bin/conan-example
|
||||||
the output:
|
|
||||||
```
|
|
||||||
sub = "jrocket@example.com"
|
sub = "jrocket@example.com"
|
||||||
iss = "Online JWT Builder"
|
iss = "Online JWT Builder"
|
||||||
exp = 1641559177
|
exp = 1641559177
|
||||||
@@ -22,4 +21,4 @@ Role = ["Manager","Project Administrator"]
|
|||||||
iat = 1610023177
|
iat = 1610023177
|
||||||
GivenName = "Johnny"
|
GivenName = "Johnny"
|
||||||
Email = "jrocket@example.com"
|
Email = "jrocket@example.com"
|
||||||
```
|
```
|
||||||
@@ -2,4 +2,4 @@
|
|||||||
jwt-cpp/0.4.0
|
jwt-cpp/0.4.0
|
||||||
|
|
||||||
[generators]
|
[generators]
|
||||||
cmake
|
cmake
|
||||||
17
example/conan/main.cpp
Normal file
17
example/conan/main.cpp
Normal 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;
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
#include <jwt-cpp/jwt.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <jwt-cpp/jwt.h>
|
||||||
|
|
||||||
int main(int argc, const char** argv) {
|
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);
|
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;
|
std::cout << e.first << " = " << e.second << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,152 +8,140 @@ using sec = std::chrono::seconds;
|
|||||||
using min = std::chrono::minutes;
|
using min = std::chrono::minutes;
|
||||||
|
|
||||||
std::string make_pico_token() {
|
std::string make_pico_token() {
|
||||||
jwt::claim from_raw_json;
|
jwt::claim from_raw_json;
|
||||||
std::istringstream iss{R"##({"api":{"array":[1,2,3],"null":null}})##"};
|
std::istringstream iss{R"##({"api":{"array":[1,2,3],"null":null}})##"};
|
||||||
iss >> from_raw_json;
|
iss >> from_raw_json;
|
||||||
|
|
||||||
jwt::claim::set_t list{"once", "twice"};
|
jwt::claim::set_t list{"once", "twice"};
|
||||||
|
|
||||||
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull,
|
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull, 525936436ull};
|
||||||
525936436ull};
|
|
||||||
|
|
||||||
const auto time = jwt::date::clock::now();
|
const auto time = jwt::date::clock::now();
|
||||||
|
|
||||||
return jwt::create()
|
return jwt::create()
|
||||||
.set_type("JWT")
|
.set_type("JWT")
|
||||||
.set_issuer("auth.mydomain.io")
|
.set_issuer("auth.mydomain.io")
|
||||||
.set_audience("mydomain.io")
|
.set_audience("mydomain.io")
|
||||||
.set_issued_at(time)
|
.set_issued_at(time)
|
||||||
.set_not_before(time + sec{15})
|
.set_not_before(time + sec{15})
|
||||||
.set_expires_at(time + sec{15} + min{2})
|
.set_expires_at(time + sec{15} + min{2})
|
||||||
.set_payload_claim("boolean", picojson::value(true))
|
.set_payload_claim("boolean", picojson::value(true))
|
||||||
.set_payload_claim("integer", picojson::value(int64_t{12345}))
|
.set_payload_claim("integer", picojson::value(int64_t{12345}))
|
||||||
.set_payload_claim("precision", picojson::value(12.345))
|
.set_payload_claim("precision", picojson::value(12.345))
|
||||||
.set_payload_claim("strings", jwt::claim(list))
|
.set_payload_claim("strings", jwt::claim(list))
|
||||||
.set_payload_claim("array",
|
.set_payload_claim("array", jwt::claim(big_numbers.begin(), big_numbers.end()))
|
||||||
jwt::claim(big_numbers.begin(), big_numbers.end()))
|
.set_payload_claim("object", from_raw_json)
|
||||||
.set_payload_claim("object", from_raw_json)
|
.sign(jwt::algorithm::none{});
|
||||||
.sign(jwt::algorithm::none{});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string make_nlohmann_token() {
|
std::string make_nlohmann_token() {
|
||||||
struct nlohmann_traits {
|
struct nlohmann_traits {
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
using value_type = json;
|
using value_type = json;
|
||||||
using object_type = json::object_t;
|
using object_type = json::object_t;
|
||||||
using array_type = json::array_t;
|
using array_type = json::array_t;
|
||||||
using string_type = std::string;
|
using string_type = std::string;
|
||||||
using number_type = json::number_float_t;
|
using number_type = json::number_float_t;
|
||||||
using integer_type = json::number_integer_t;
|
using integer_type = json::number_integer_t;
|
||||||
using boolean_type = json::boolean_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;
|
using jwt::json::type;
|
||||||
|
|
||||||
if (val.type() == json::value_t::boolean)
|
if (val.type() == json::value_t::boolean)
|
||||||
return type::boolean;
|
return type::boolean;
|
||||||
else if (val.type() == json::value_t::number_integer)
|
else if (val.type() == json::value_t::number_integer)
|
||||||
return type::integer;
|
return type::integer;
|
||||||
else if (val.type() == json::value_t::number_unsigned) // nlohmann internally tracks two types of integers
|
else if (val.type() == json::value_t::number_unsigned) // nlohmann internally tracks two types of integers
|
||||||
return type::integer;
|
return type::integer;
|
||||||
else if (val.type() == json::value_t::number_float)
|
else if (val.type() == json::value_t::number_float)
|
||||||
return type::number;
|
return type::number;
|
||||||
else if (val.type() == json::value_t::string)
|
else if (val.type() == json::value_t::string)
|
||||||
return type::string;
|
return type::string;
|
||||||
else if (val.type() == json::value_t::array)
|
else if (val.type() == json::value_t::array)
|
||||||
return type::array;
|
return type::array;
|
||||||
else if (val.type() == json::value_t::object)
|
else if (val.type() == json::value_t::object)
|
||||||
return type::object;
|
return type::object;
|
||||||
else
|
else
|
||||||
throw std::logic_error("invalid type");
|
throw std::logic_error("invalid type");
|
||||||
}
|
}
|
||||||
|
|
||||||
static json::object_t as_object(const json &val) {
|
static json::object_t as_object(const json& val) {
|
||||||
if (val.type() != json::value_t::object)
|
if (val.type() != json::value_t::object) throw std::bad_cast();
|
||||||
throw std::bad_cast();
|
return val.get<json::object_t>();
|
||||||
return val.get<json::object_t>();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static std::string as_string(const json &val) {
|
static std::string as_string(const json& val) {
|
||||||
if (val.type() != json::value_t::string)
|
if (val.type() != json::value_t::string) throw std::bad_cast();
|
||||||
throw std::bad_cast();
|
return val.get<std::string>();
|
||||||
return val.get<std::string>();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static json::array_t as_array(const json &val) {
|
static json::array_t as_array(const json& val) {
|
||||||
if (val.type() != json::value_t::array)
|
if (val.type() != json::value_t::array) throw std::bad_cast();
|
||||||
throw std::bad_cast();
|
return val.get<json::array_t>();
|
||||||
return val.get<json::array_t>();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static int64_t as_int(const json &val) {
|
static int64_t as_int(const json& val) {
|
||||||
switch(val.type())
|
switch (val.type()) {
|
||||||
{
|
case json::value_t::number_integer:
|
||||||
case json::value_t::number_integer:
|
case json::value_t::number_unsigned: return val.get<int64_t>();
|
||||||
case json::value_t::number_unsigned:
|
default: throw std::bad_cast();
|
||||||
return val.get<int64_t>();
|
}
|
||||||
default:
|
}
|
||||||
throw std::bad_cast();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool as_bool(const json &val) {
|
static bool as_bool(const json& val) {
|
||||||
if (val.type() != json::value_t::boolean)
|
if (val.type() != json::value_t::boolean) throw std::bad_cast();
|
||||||
throw std::bad_cast();
|
return val.get<bool>();
|
||||||
return val.get<bool>();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static double as_number(const json &val) {
|
static double as_number(const json& val) {
|
||||||
if (val.type() != json::value_t::number_float)
|
if (val.type() != json::value_t::number_float) throw std::bad_cast();
|
||||||
throw std::bad_cast();
|
return val.get<double>();
|
||||||
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());
|
val = json::parse(str.begin(), str.end());
|
||||||
return true;
|
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>;
|
using claim = jwt::basic_claim<nlohmann_traits>;
|
||||||
|
|
||||||
claim from_raw_json;
|
claim from_raw_json;
|
||||||
std::istringstream iss{R"##({"api":{"array":[1,2,3],"null":null}})##"};
|
std::istringstream iss{R"##({"api":{"array":[1,2,3],"null":null}})##"};
|
||||||
iss >> from_raw_json;
|
iss >> from_raw_json;
|
||||||
|
|
||||||
claim::set_t list{"once", "twice"};
|
claim::set_t list{"once", "twice"};
|
||||||
|
|
||||||
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull,
|
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull, 525936436ull};
|
||||||
525936436ull};
|
|
||||||
|
|
||||||
const auto time = jwt::date::clock::now();
|
const auto time = jwt::date::clock::now();
|
||||||
|
|
||||||
return jwt::create<nlohmann_traits>()
|
return jwt::create<nlohmann_traits>()
|
||||||
.set_type("JWT")
|
.set_type("JWT")
|
||||||
.set_issuer("auth.mydomain.io")
|
.set_issuer("auth.mydomain.io")
|
||||||
.set_audience("mydomain.io")
|
.set_audience("mydomain.io")
|
||||||
.set_issued_at(time)
|
.set_issued_at(time)
|
||||||
.set_not_before(time + sec{15})
|
.set_not_before(time + sec{15})
|
||||||
.set_expires_at(time + sec{15} + min{2})
|
.set_expires_at(time + sec{15} + min{2})
|
||||||
.set_payload_claim("boolean", true)
|
.set_payload_claim("boolean", true)
|
||||||
.set_payload_claim("integer", 12345)
|
.set_payload_claim("integer", 12345)
|
||||||
.set_payload_claim("precision", 12.345)
|
.set_payload_claim("precision", 12.345)
|
||||||
.set_payload_claim("strings", list)
|
.set_payload_claim("strings", list)
|
||||||
.set_payload_claim("array", {big_numbers.begin(), big_numbers.end()})
|
.set_payload_claim("array", {big_numbers.begin(), big_numbers.end()})
|
||||||
.set_payload_claim("object", from_raw_json)
|
.set_payload_claim("object", from_raw_json)
|
||||||
.sign(jwt::algorithm::none{});
|
.sign(jwt::algorithm::none{});
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char **argv) {
|
int main(int argc, const char** argv) {
|
||||||
const auto token = make_pico_token();
|
const auto token = make_pico_token();
|
||||||
auto decoded = jwt::decode(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;
|
std::cout << e.first << " = " << e.second << std::endl;
|
||||||
|
|
||||||
const auto api_array =
|
const auto api_array = decoded.get_payload_claims()["object"].to_json().get("api").get("array");
|
||||||
decoded.get_payload_claims()["object"].to_json().get("api").get("array");
|
std::cout << "api array = " << api_array << std::endl;
|
||||||
std::cout << "api array = " << api_array << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <jwt-cpp/jwt.h>
|
#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-----
|
std::string rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
|
||||||
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
|
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
|
||||||
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
|
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
|
||||||
XYqlET3zfAY+diwCb0HEsVvhisthwMU4gZQu6TYW2s9LnXZB5rVtcBK69hcSlA2k
|
XYqlET3zfAY+diwCb0HEsVvhisthwMU4gZQu6TYW2s9LnXZB5rVtcBK69hcSlA2k
|
||||||
@@ -30,7 +30,7 @@ RultUEe2C0jYMDQx+JYxbPmtcopvZQrFEur3WKVuLy5UAy7EBvwMnZwIG7OOohJb
|
|||||||
vkSpADK6VPn9lbqq7O8cTedEHttm6otmLt8ZyEl3hZMaL3hbuRj6ysjmoFKx6CrX
|
vkSpADK6VPn9lbqq7O8cTedEHttm6otmLt8ZyEl3hZMaL3hbuRj6ysjmoFKx6CrX
|
||||||
rK0/Ikt5ybqUzKCMJZg2VKGTxg==
|
rK0/Ikt5ybqUzKCMJZg2VKGTxg==
|
||||||
-----END PRIVATE KEY-----)";
|
-----END PRIVATE KEY-----)";
|
||||||
std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
|
std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
|
||||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGbXWiK3dQTyCbX5xdE4
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGbXWiK3dQTyCbX5xdE4
|
||||||
yCuYp0AF2d15Qq1JSXT/lx8CEcXb9RbDddl8jGDv+spi5qPa8qEHiK7FwV2KpRE9
|
yCuYp0AF2d15Qq1JSXT/lx8CEcXb9RbDddl8jGDv+spi5qPa8qEHiK7FwV2KpRE9
|
||||||
83wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVs
|
83wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVs
|
||||||
@@ -40,15 +40,14 @@ AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0
|
|||||||
YwIDAQAB
|
YwIDAQAB
|
||||||
-----END PUBLIC KEY-----)";
|
-----END PUBLIC KEY-----)";
|
||||||
|
|
||||||
auto token =
|
auto token = jwt::create()
|
||||||
jwt::create()
|
.set_issuer("auth0")
|
||||||
.set_issuer("auth0")
|
.set_type("JWT")
|
||||||
.set_type("JWT")
|
.set_id("rsa-create-example")
|
||||||
.set_id("rsa-create-example")
|
.set_issued_at(std::chrono::system_clock::now())
|
||||||
.set_issued_at(std::chrono::system_clock::now())
|
.set_expires_at(std::chrono::system_clock::now() + std::chrono::seconds{36000})
|
||||||
.set_expires_at(std::chrono::system_clock::now() + std::chrono::seconds{36000})
|
.set_payload_claim("sample", jwt::claim(std::string{"test"}))
|
||||||
.set_payload_claim("sample", jwt::claim(std::string{"test"}))
|
.sign(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""));
|
||||||
.sign(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""));
|
|
||||||
|
|
||||||
std::cout << "token:\n" << token << std::endl;
|
std::cout << "token:\n" << token << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <jwt-cpp/jwt.h>
|
#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-----
|
std::string rsa_priv_key = R"(-----BEGIN PRIVATE KEY-----
|
||||||
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
|
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
|
||||||
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
|
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
|
||||||
XYqlET3zfAY+diwCb0HEsVvhisthwMU4gZQu6TYW2s9LnXZB5rVtcBK69hcSlA2k
|
XYqlET3zfAY+diwCb0HEsVvhisthwMU4gZQu6TYW2s9LnXZB5rVtcBK69hcSlA2k
|
||||||
@@ -30,7 +30,7 @@ RultUEe2C0jYMDQx+JYxbPmtcopvZQrFEur3WKVuLy5UAy7EBvwMnZwIG7OOohJb
|
|||||||
vkSpADK6VPn9lbqq7O8cTedEHttm6otmLt8ZyEl3hZMaL3hbuRj6ysjmoFKx6CrX
|
vkSpADK6VPn9lbqq7O8cTedEHttm6otmLt8ZyEl3hZMaL3hbuRj6ysjmoFKx6CrX
|
||||||
rK0/Ikt5ybqUzKCMJZg2VKGTxg==
|
rK0/Ikt5ybqUzKCMJZg2VKGTxg==
|
||||||
-----END PRIVATE KEY-----)";
|
-----END PRIVATE KEY-----)";
|
||||||
std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
|
std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----
|
||||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGbXWiK3dQTyCbX5xdE4
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGbXWiK3dQTyCbX5xdE4
|
||||||
yCuYp0AF2d15Qq1JSXT/lx8CEcXb9RbDddl8jGDv+spi5qPa8qEHiK7FwV2KpRE9
|
yCuYp0AF2d15Qq1JSXT/lx8CEcXb9RbDddl8jGDv+spi5qPa8qEHiK7FwV2KpRE9
|
||||||
83wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVs
|
83wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVs
|
||||||
@@ -40,27 +40,24 @@ AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0
|
|||||||
YwIDAQAB
|
YwIDAQAB
|
||||||
-----END PUBLIC KEY-----)";
|
-----END PUBLIC KEY-----)";
|
||||||
|
|
||||||
std::string token =
|
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9."
|
||||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9."
|
"VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||||
"VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-"
|
||||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-"
|
"GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||||
"GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-"
|
||||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-"
|
"IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||||
"IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-"
|
||||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-"
|
"uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||||
"uc2z5c05CCXqVSpfCjWbh9gQ";
|
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify =
|
||||||
.allow_algorithm(jwt::algorithm::rs256(
|
jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", "")).with_issuer("auth0");
|
||||||
rsa_pub_key, rsa_priv_key, "", ""))
|
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded = jwt::decode(token);
|
auto decoded = jwt::decode(token);
|
||||||
|
|
||||||
verify.verify(decoded);
|
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;
|
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;
|
std::cout << e.first << " = " << e.second.to_json() << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,49 +18,47 @@
|
|||||||
namespace jwt {
|
namespace jwt {
|
||||||
/**
|
/**
|
||||||
* \brief character maps when encoding and decoding
|
* \brief character maps when encoding and decoding
|
||||||
*/
|
*/
|
||||||
namespace alphabet {
|
namespace alphabet {
|
||||||
/**
|
/**
|
||||||
* \brief valid list of characted when working with [Base64](https://tools.ietf.org/html/rfc3548)
|
* \brief valid list of characted when working with [Base64](https://tools.ietf.org/html/rfc3548)
|
||||||
*/
|
*/
|
||||||
struct base64 {
|
struct base64 {
|
||||||
static const std::array<char, 64>& data() {
|
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',
|
{'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',
|
'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',
|
'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;
|
return data;
|
||||||
}
|
}
|
||||||
static const std::string& fill() {
|
static const std::string& fill() {
|
||||||
static std::string fill{ "=" };
|
static std::string fill{"="};
|
||||||
return fill;
|
return fill;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* \brief valid list of characted when working with [Base64URL](https://tools.ietf.org/html/rfc4648)
|
* \brief valid list of characted when working with [Base64URL](https://tools.ietf.org/html/rfc4648)
|
||||||
*/
|
*/
|
||||||
struct base64url {
|
struct base64url {
|
||||||
static const std::array<char, 64>& data() {
|
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',
|
{'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',
|
'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',
|
'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;
|
return data;
|
||||||
}
|
}
|
||||||
static const std::string& fill() {
|
static const std::string& fill() {
|
||||||
static std::string fill{ "%3d" };
|
static std::string fill{"%3d"};
|
||||||
return fill;
|
return fill;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace alphabet
|
} // namespace alphabet
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Alphabet generic methods for working with encoding/decoding the base64 family
|
* \brief Alphabet generic methods for working with encoding/decoding the base64 family
|
||||||
*/
|
*/
|
||||||
class base {
|
class base {
|
||||||
public:
|
public:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -81,7 +79,8 @@ namespace jwt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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();
|
size_t size = bin.size();
|
||||||
std::string res;
|
std::string res;
|
||||||
|
|
||||||
@@ -100,8 +99,7 @@ namespace jwt {
|
|||||||
res += alphabet[(triple >> 0 * 6) & 0x3F];
|
res += alphabet[(triple >> 0 * 6) & 0x3F];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fast_size == size)
|
if (fast_size == size) return res;
|
||||||
return res;
|
|
||||||
|
|
||||||
size_t mod = size % 3;
|
size_t mod = size % 3;
|
||||||
|
|
||||||
@@ -124,14 +122,14 @@ namespace jwt {
|
|||||||
res += alphabet[(triple >> 1 * 6) & 0x3F];
|
res += alphabet[(triple >> 1 * 6) & 0x3F];
|
||||||
res += fill;
|
res += fill;
|
||||||
break;
|
break;
|
||||||
default:
|
default: break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
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 size = base.size();
|
||||||
|
|
||||||
size_t fill_cnt = 0;
|
size_t fill_cnt = 0;
|
||||||
@@ -139,14 +137,12 @@ namespace jwt {
|
|||||||
if (base.substr(size - fill.size(), fill.size()) == fill) {
|
if (base.substr(size - fill.size(), fill.size()) == fill) {
|
||||||
fill_cnt++;
|
fill_cnt++;
|
||||||
size -= fill.size();
|
size -= fill.size();
|
||||||
if(fill_cnt > 2)
|
if (fill_cnt > 2) throw std::runtime_error("Invalid input");
|
||||||
throw std::runtime_error("Invalid input");
|
} else
|
||||||
}
|
break;
|
||||||
else break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((size + fill_cnt) % 4 != 0)
|
if ((size + fill_cnt) % 4 != 0) throw std::runtime_error("Invalid input");
|
||||||
throw std::runtime_error("Invalid input");
|
|
||||||
|
|
||||||
size_t out_size = size / 4 * 3;
|
size_t out_size = size / 4 * 3;
|
||||||
std::string res;
|
std::string res;
|
||||||
@@ -154,8 +150,7 @@ namespace jwt {
|
|||||||
|
|
||||||
auto get_sextet = [&](size_t offset) {
|
auto get_sextet = [&](size_t offset) {
|
||||||
for (size_t i = 0; i < alphabet.size(); i++) {
|
for (size_t i = 0; i < alphabet.size(); i++) {
|
||||||
if (alphabet[i] == base[offset])
|
if (alphabet[i] == base[offset]) return static_cast<uint32_t>(i);
|
||||||
return static_cast<uint32_t>(i);
|
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Invalid input");
|
throw std::runtime_error("Invalid input");
|
||||||
};
|
};
|
||||||
@@ -167,21 +162,16 @@ namespace jwt {
|
|||||||
uint32_t sextet_c = get_sextet(i++);
|
uint32_t sextet_c = get_sextet(i++);
|
||||||
uint32_t sextet_d = get_sextet(i++);
|
uint32_t sextet_d = get_sextet(i++);
|
||||||
|
|
||||||
uint32_t triple = (sextet_a << 3 * 6)
|
uint32_t triple = (sextet_a << 3 * 6) + (sextet_b << 2 * 6) + (sextet_c << 1 * 6) + (sextet_d << 0 * 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 >> 2 * 8) & 0xFFU);
|
||||||
res += static_cast<char>((triple >> 1 * 8) & 0xFFU);
|
res += static_cast<char>((triple >> 1 * 8) & 0xFFU);
|
||||||
res += static_cast<char>((triple >> 0 * 8) & 0xFFU);
|
res += static_cast<char>((triple >> 0 * 8) & 0xFFU);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fill_cnt == 0)
|
if (fill_cnt == 0) return res;
|
||||||
return res;
|
|
||||||
|
|
||||||
uint32_t triple = (get_sextet(fast_size) << 3 * 6)
|
uint32_t triple = (get_sextet(fast_size) << 3 * 6) + (get_sextet(fast_size + 1) << 2 * 6);
|
||||||
+ (get_sextet(fast_size + 1) << 2 * 6);
|
|
||||||
|
|
||||||
switch (fill_cnt) {
|
switch (fill_cnt) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -189,30 +179,20 @@ namespace jwt {
|
|||||||
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
|
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
|
||||||
res += static_cast<char>((triple >> 1 * 8) & 0xFFU);
|
res += static_cast<char>((triple >> 1 * 8) & 0xFFU);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2: res += static_cast<char>((triple >> 2 * 8) & 0xFFU); break;
|
||||||
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
|
default: break;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string pad(const std::string& base, const std::string& fill) {
|
static std::string pad(const std::string& base, const std::string& fill) {
|
||||||
std::string padding;
|
std::string padding;
|
||||||
switch (base.size() % 4) {
|
switch (base.size() % 4) {
|
||||||
case 1:
|
case 1: padding += fill; JWT_FALLTHROUGH;
|
||||||
padding += fill;
|
case 2: padding += fill; JWT_FALLTHROUGH;
|
||||||
JWT_FALLTHROUGH;
|
case 3: padding += fill; JWT_FALLTHROUGH;
|
||||||
case 2:
|
default: break;
|
||||||
padding += fill;
|
|
||||||
JWT_FALLTHROUGH;
|
|
||||||
case 3:
|
|
||||||
padding += fill;
|
|
||||||
JWT_FALLTHROUGH;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return base + padding;
|
return base + padding;
|
||||||
@@ -223,6 +203,6 @@ namespace jwt {
|
|||||||
return base.substr(0, pos);
|
return base.substr(0, pos);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace jwt
|
} // namespace jwt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include "jwt-cpp/base.h"
|
#include "jwt-cpp/base.h"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
TEST(BaseTest, Base64Decode) {
|
TEST(BaseTest, Base64Decode) {
|
||||||
ASSERT_EQ("1", jwt::base::decode<jwt::alphabet::base64>("MQ=="));
|
ASSERT_EQ("1", jwt::base::decode<jwt::alphabet::base64>("MQ=="));
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include "jwt-cpp/jwt.h"
|
#include "jwt-cpp/jwt.h"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
TEST(ClaimTest, AudienceAsString) {
|
TEST(ClaimTest, AudienceAsString) {
|
||||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
std::string token =
|
||||||
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
||||||
auto decoded = jwt::decode(token);
|
auto decoded = jwt::decode(token);
|
||||||
|
|
||||||
ASSERT_TRUE(decoded.has_algorithm());
|
ASSERT_TRUE(decoded.has_algorithm());
|
||||||
@@ -25,11 +26,9 @@ TEST(ClaimTest, AudienceAsString) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(ClaimTest, SetAudienceAsString) {
|
TEST(ClaimTest, SetAudienceAsString) {
|
||||||
auto token = jwt::create()
|
auto token = jwt::create().set_type("JWT").set_audience("test").sign(jwt::algorithm::hs256("test"));
|
||||||
.set_type("JWT")
|
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.ny5Fa0vzAg7tNL95KWg_ecBNd3XP3tdAzq0SFA6diY4",
|
||||||
.set_audience("test")
|
token);
|
||||||
.sign(jwt::algorithm::hs256("test"));
|
|
||||||
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.ny5Fa0vzAg7tNL95KWg_ecBNd3XP3tdAzq0SFA6diY4", token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ClaimTest, AudienceAsSet) {
|
TEST(ClaimTest, AudienceAsSet) {
|
||||||
@@ -58,21 +57,16 @@ TEST(ClaimTest, AudienceAsSet) {
|
|||||||
|
|
||||||
TEST(ClaimTest, SetAudienceAsSet) {
|
TEST(ClaimTest, SetAudienceAsSet) {
|
||||||
auto token = jwt::create()
|
auto token = jwt::create()
|
||||||
.set_type("JWT")
|
.set_type("JWT")
|
||||||
.set_audience({{picojson::value("test"), picojson::value("test2")}})
|
.set_audience({{picojson::value("test"), picojson::value("test2")}})
|
||||||
.sign(jwt::algorithm::none{});
|
.sign(jwt::algorithm::none{});
|
||||||
ASSERT_EQ("eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJhdWQiOlsidGVzdCIsInRlc3QyIl19.", token);
|
ASSERT_EQ("eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJhdWQiOlsidGVzdCIsInRlc3QyIl19.", token);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ClaimTest, SetArray) {
|
TEST(ClaimTest, SetArray) {
|
||||||
std::vector<int64_t> vect = {
|
std::vector<int64_t> vect = {100, 20, 10};
|
||||||
100,
|
auto token =
|
||||||
20,
|
jwt::create().set_payload_claim("test", jwt::claim(vect.begin(), vect.end())).sign(jwt::algorithm::none{});
|
||||||
10
|
|
||||||
};
|
|
||||||
auto token = jwt::create()
|
|
||||||
.set_payload_claim("test", jwt::claim(vect.begin(), vect.end()))
|
|
||||||
.sign(jwt::algorithm::none{});
|
|
||||||
ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0.");
|
ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,18 +74,15 @@ TEST(ClaimTest, SetObject) {
|
|||||||
std::istringstream iss{"{\"api-x\": [1]}"};
|
std::istringstream iss{"{\"api-x\": [1]}"};
|
||||||
jwt::claim object;
|
jwt::claim object;
|
||||||
iss >> 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()
|
auto token = jwt::create().set_payload_claim("namespace", object).sign(jwt::algorithm::hs256("test"));
|
||||||
.set_payload_claim("namespace", object)
|
ASSERT_EQ(token,
|
||||||
.sign(jwt::algorithm::hs256("test"));
|
"eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
||||||
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ClaimTest, SetAlgorithm) {
|
TEST(ClaimTest, SetAlgorithm) {
|
||||||
auto token = jwt::create()
|
auto token = jwt::create().set_algorithm("test").sign(jwt::algorithm::none{});
|
||||||
.set_algorithm("test")
|
|
||||||
.sign(jwt::algorithm::none{});
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
ASSERT_EQ(decoded_token.get_algorithm(), "test");
|
ASSERT_EQ(decoded_token.get_algorithm(), "test");
|
||||||
@@ -133,7 +124,8 @@ TEST(ClaimTest, PicoJSONTraitsAsDouble) {
|
|||||||
TEST(ClaimTest, MapOfClaim) {
|
TEST(ClaimTest, MapOfClaim) {
|
||||||
using map = jwt::details::map_of_claims<jwt::picojson_traits>;
|
using map = jwt::details::map_of_claims<jwt::picojson_traits>;
|
||||||
ASSERT_THROW(map::parse_claims(R"##(__ not json __)##"), jwt::error::invalid_json_exception);
|
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("array"));
|
||||||
ASSERT_TRUE(claims.has_claim("string"));
|
ASSERT_TRUE(claims.has_claim("string"));
|
||||||
|
|||||||
@@ -1,82 +1,88 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include "jwt-cpp/jwt.h"
|
#include "jwt-cpp/jwt.h"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
extern std::string google_cert;
|
extern std::string google_cert;
|
||||||
extern std::string google_cert_base64_der;
|
extern std::string google_cert_base64_der;
|
||||||
extern std::string google_cert_key;
|
extern std::string google_cert_key;
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
TEST(HelperTest, Cert2Pubkey) {
|
TEST(HelperTest, Cert2Pubkey) {
|
||||||
auto key = jwt::helper::extract_pubkey_from_cert(google_cert);
|
auto key = jwt::helper::extract_pubkey_from_cert(google_cert);
|
||||||
ASSERT_EQ(google_cert_key, key);
|
ASSERT_EQ(google_cert_key, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(HelperTest, Base64DER2PemCert) {
|
TEST(HelperTest, Base64DER2PemCert) {
|
||||||
auto cert_pem = jwt::helper::convert_base64_der_to_pem(google_cert_base64_der);
|
auto cert_pem = jwt::helper::convert_base64_der_to_pem(google_cert_base64_der);
|
||||||
ASSERT_EQ(google_cert, cert_pem);
|
ASSERT_EQ(google_cert, cert_pem);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(HelperTest, ErrorCodeMessages) {
|
TEST(HelperTest, ErrorCodeMessages) {
|
||||||
ASSERT_EQ(std::error_code(jwt::error::rsa_error::ok).message(), "no error");
|
ASSERT_EQ(std::error_code(jwt::error::rsa_error::ok).message(), "no error");
|
||||||
ASSERT_EQ(std::error_code(static_cast<jwt::error::rsa_error>(-1)).message(), "unknown RSA error");
|
ASSERT_EQ(std::error_code(static_cast<jwt::error::rsa_error>(-1)).message(), "unknown RSA error");
|
||||||
ASSERT_EQ(std::error_code(jwt::error::rsa_error::ok).category().name(), std::string("rsa_error"));
|
ASSERT_EQ(std::error_code(jwt::error::rsa_error::ok).category().name(), std::string("rsa_error"));
|
||||||
|
|
||||||
ASSERT_EQ(std::error_code(jwt::error::ecdsa_error::ok).message(), "no error");
|
ASSERT_EQ(std::error_code(jwt::error::ecdsa_error::ok).message(), "no error");
|
||||||
ASSERT_EQ(std::error_code(static_cast<jwt::error::ecdsa_error>(-1)).message(), "unknown ECDSA error");
|
ASSERT_EQ(std::error_code(static_cast<jwt::error::ecdsa_error>(-1)).message(), "unknown ECDSA error");
|
||||||
ASSERT_EQ(std::error_code(jwt::error::ecdsa_error::ok).category().name(), std::string("ecdsa_error"));
|
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(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(static_cast<jwt::error::signature_verification_error>(-1)).message(),
|
||||||
ASSERT_EQ(std::error_code(jwt::error::signature_verification_error::ok).category().name(), std::string("signature_verification_error"));
|
"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(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(static_cast<jwt::error::signature_generation_error>(-1)).message(),
|
||||||
ASSERT_EQ(std::error_code(jwt::error::signature_generation_error::ok).category().name(), std::string("signature_generation_error"));
|
"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(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(static_cast<jwt::error::token_verification_error>(-1)).message(),
|
||||||
ASSERT_EQ(std::error_code(jwt::error::token_verification_error::ok).category().name(), std::string("token_verification_error"));
|
"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;
|
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(),
|
ASSERT_NE(std::error_code(static_cast<jwt::error::rsa_error>(i)).message(),
|
||||||
std::error_code(static_cast<jwt::error::rsa_error>(-1)).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(),
|
ASSERT_EQ(std::error_code(static_cast<jwt::error::rsa_error>(i)).message(),
|
||||||
std::error_code(static_cast<jwt::error::rsa_error>(-1)).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(),
|
ASSERT_NE(std::error_code(static_cast<jwt::error::ecdsa_error>(i)).message(),
|
||||||
std::error_code(static_cast<jwt::error::ecdsa_error>(-1)).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(),
|
ASSERT_EQ(std::error_code(static_cast<jwt::error::ecdsa_error>(i)).message(),
|
||||||
std::error_code(static_cast<jwt::error::ecdsa_error>(-1)).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(),
|
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());
|
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(),
|
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());
|
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(),
|
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());
|
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(),
|
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());
|
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(),
|
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());
|
std::error_code(static_cast<jwt::error::token_verification_error>(-1)).message());
|
||||||
}
|
}
|
||||||
ASSERT_EQ(std::error_code(static_cast<jwt::error::token_verification_error>(i)).message(),
|
ASSERT_EQ(std::error_code(static_cast<jwt::error::token_verification_error>(i)).message(),
|
||||||
std::error_code(static_cast<jwt::error::token_verification_error>(-1)).message());
|
std::error_code(static_cast<jwt::error::token_verification_error>(-1)).message());
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::string google_cert = R"(-----BEGIN CERTIFICATE-----
|
std::string google_cert = R"(-----BEGIN CERTIFICATE-----
|
||||||
MIIF8DCCBVmgAwIBAgIKYFOB9QABAACIvTANBgkqhkiG9w0BAQUFADBGMQswCQYD
|
MIIF8DCCBVmgAwIBAgIKYFOB9QABAACIvTANBgkqhkiG9w0BAQUFADBGMQswCQYD
|
||||||
VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu
|
VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu
|
||||||
dGVybmV0IEF1dGhvcml0eTAeFw0xMzA1MjIxNTQ5MDRaFw0xMzEwMzEyMzU5NTla
|
dGVybmV0IEF1dGhvcml0eTAeFw0xMzA1MjIxNTQ5MDRaFw0xMzEwMzEyMzU5NTla
|
||||||
@@ -112,43 +118,42 @@ OpueYUG3NBcHP/5IzhUYIQJbGzlQaUaZBMaQeC8ZslMNLWI2
|
|||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
)";
|
)";
|
||||||
|
|
||||||
std::string google_cert_base64_der =
|
std::string google_cert_base64_der = "MIIF8DCCBVmgAwIBAgIKYFOB9QABAACIvTANBgkqhkiG9w0BAQUFADBGMQswCQYD"
|
||||||
"MIIF8DCCBVmgAwIBAgIKYFOB9QABAACIvTANBgkqhkiG9w0BAQUFADBGMQswCQYD"
|
"VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu"
|
||||||
"VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu"
|
"dGVybmV0IEF1dGhvcml0eTAeFw0xMzA1MjIxNTQ5MDRaFw0xMzEwMzEyMzU5NTla"
|
||||||
"dGVybmV0IEF1dGhvcml0eTAeFw0xMzA1MjIxNTQ5MDRaFw0xMzEwMzEyMzU5NTla"
|
"MGYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N"
|
||||||
"MGYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N"
|
"b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRUwEwYDVQQDFAwqLmdv"
|
||||||
"b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRUwEwYDVQQDFAwqLmdv"
|
"b2dsZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARmSpIUbCqhUBq1UwnR"
|
||||||
"b2dsZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARmSpIUbCqhUBq1UwnR"
|
"Ai7/TNSk6W8JmasR+I0r/NLDYv5yApbAz8HXXN8hDdurMRP6Jy1Q0UIKmyls8HPH"
|
||||||
"Ai7/TNSk6W8JmasR+I0r/NLDYv5yApbAz8HXXN8hDdurMRP6Jy1Q0UIKmyls8HPH"
|
"exoCo4IECjCCBAYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAsGA1Ud"
|
||||||
"exoCo4IECjCCBAYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAsGA1Ud"
|
"DwQEAwIHgDAdBgNVHQ4EFgQUU3jT0NVNRgU5ZinRHGrlyoGEnoYwHwYDVR0jBBgw"
|
||||||
"DwQEAwIHgDAdBgNVHQ4EFgQUU3jT0NVNRgU5ZinRHGrlyoGEnoYwHwYDVR0jBBgw"
|
"FoAUv8Aw6/VDET5nup6R+/xq2uNrEiQwWwYDVR0fBFQwUjBQoE6gTIZKaHR0cDov"
|
||||||
"FoAUv8Aw6/VDET5nup6R+/xq2uNrEiQwWwYDVR0fBFQwUjBQoE6gTIZKaHR0cDov"
|
"L3d3dy5nc3RhdGljLmNvbS9Hb29nbGVJbnRlcm5ldEF1dGhvcml0eS9Hb29nbGVJ"
|
||||||
"L3d3dy5nc3RhdGljLmNvbS9Hb29nbGVJbnRlcm5ldEF1dGhvcml0eS9Hb29nbGVJ"
|
"bnRlcm5ldEF1dGhvcml0eS5jcmwwZgYIKwYBBQUHAQEEWjBYMFYGCCsGAQUFBzAC"
|
||||||
"bnRlcm5ldEF1dGhvcml0eS5jcmwwZgYIKwYBBQUHAQEEWjBYMFYGCCsGAQUFBzAC"
|
"hkpodHRwOi8vd3d3LmdzdGF0aWMuY29tL0dvb2dsZUludGVybmV0QXV0aG9yaXR5"
|
||||||
"hkpodHRwOi8vd3d3LmdzdGF0aWMuY29tL0dvb2dsZUludGVybmV0QXV0aG9yaXR5"
|
"L0dvb2dsZUludGVybmV0QXV0aG9yaXR5LmNydDAMBgNVHRMBAf8EAjAAMIICwwYD"
|
||||||
"L0dvb2dsZUludGVybmV0QXV0aG9yaXR5LmNydDAMBgNVHRMBAf8EAjAAMIICwwYD"
|
"VR0RBIICujCCAraCDCouZ29vZ2xlLmNvbYINKi5hbmRyb2lkLmNvbYIWKi5hcHBl"
|
||||||
"VR0RBIICujCCAraCDCouZ29vZ2xlLmNvbYINKi5hbmRyb2lkLmNvbYIWKi5hcHBl"
|
"bmdpbmUuZ29vZ2xlLmNvbYISKi5jbG91ZC5nb29nbGUuY29tghYqLmdvb2dsZS1h"
|
||||||
"bmdpbmUuZ29vZ2xlLmNvbYISKi5jbG91ZC5nb29nbGUuY29tghYqLmdvb2dsZS1h"
|
"bmFseXRpY3MuY29tggsqLmdvb2dsZS5jYYILKi5nb29nbGUuY2yCDiouZ29vZ2xl"
|
||||||
"bmFseXRpY3MuY29tggsqLmdvb2dsZS5jYYILKi5nb29nbGUuY2yCDiouZ29vZ2xl"
|
"LmNvLmlugg4qLmdvb2dsZS5jby5qcIIOKi5nb29nbGUuY28udWuCDyouZ29vZ2xl"
|
||||||
"LmNvLmlugg4qLmdvb2dsZS5jby5qcIIOKi5nb29nbGUuY28udWuCDyouZ29vZ2xl"
|
"LmNvbS5hcoIPKi5nb29nbGUuY29tLmF1gg8qLmdvb2dsZS5jb20uYnKCDyouZ29v"
|
||||||
"LmNvbS5hcoIPKi5nb29nbGUuY29tLmF1gg8qLmdvb2dsZS5jb20uYnKCDyouZ29v"
|
"Z2xlLmNvbS5jb4IPKi5nb29nbGUuY29tLm14gg8qLmdvb2dsZS5jb20udHKCDyou"
|
||||||
"Z2xlLmNvbS5jb4IPKi5nb29nbGUuY29tLm14gg8qLmdvb2dsZS5jb20udHKCDyou"
|
"Z29vZ2xlLmNvbS52boILKi5nb29nbGUuZGWCCyouZ29vZ2xlLmVzggsqLmdvb2ds"
|
||||||
"Z29vZ2xlLmNvbS52boILKi5nb29nbGUuZGWCCyouZ29vZ2xlLmVzggsqLmdvb2ds"
|
"ZS5mcoILKi5nb29nbGUuaHWCCyouZ29vZ2xlLml0ggsqLmdvb2dsZS5ubIILKi5n"
|
||||||
"ZS5mcoILKi5nb29nbGUuaHWCCyouZ29vZ2xlLml0ggsqLmdvb2dsZS5ubIILKi5n"
|
"b29nbGUucGyCCyouZ29vZ2xlLnB0gg8qLmdvb2dsZWFwaXMuY26CFCouZ29vZ2xl"
|
||||||
"b29nbGUucGyCCyouZ29vZ2xlLnB0gg8qLmdvb2dsZWFwaXMuY26CFCouZ29vZ2xl"
|
"Y29tbWVyY2UuY29tgg0qLmdzdGF0aWMuY29tggwqLnVyY2hpbi5jb22CECoudXJs"
|
||||||
"Y29tbWVyY2UuY29tgg0qLmdzdGF0aWMuY29tggwqLnVyY2hpbi5jb22CECoudXJs"
|
"Lmdvb2dsZS5jb22CFioueW91dHViZS1ub2Nvb2tpZS5jb22CDSoueW91dHViZS5j"
|
||||||
"Lmdvb2dsZS5jb22CFioueW91dHViZS1ub2Nvb2tpZS5jb22CDSoueW91dHViZS5j"
|
"b22CFioueW91dHViZWVkdWNhdGlvbi5jb22CCyoueXRpbWcuY29tggthbmRyb2lk"
|
||||||
"b22CFioueW91dHViZWVkdWNhdGlvbi5jb22CCyoueXRpbWcuY29tggthbmRyb2lk"
|
"LmNvbYIEZy5jb4IGZ29vLmdsghRnb29nbGUtYW5hbHl0aWNzLmNvbYIKZ29vZ2xl"
|
||||||
"LmNvbYIEZy5jb4IGZ29vLmdsghRnb29nbGUtYW5hbHl0aWNzLmNvbYIKZ29vZ2xl"
|
"LmNvbYISZ29vZ2xlY29tbWVyY2UuY29tggp1cmNoaW4uY29tggh5b3V0dS5iZYIL"
|
||||||
"LmNvbYISZ29vZ2xlY29tbWVyY2UuY29tggp1cmNoaW4uY29tggh5b3V0dS5iZYIL"
|
"eW91dHViZS5jb22CFHlvdXR1YmVlZHVjYXRpb24uY29tMA0GCSqGSIb3DQEBBQUA"
|
||||||
"eW91dHViZS5jb22CFHlvdXR1YmVlZHVjYXRpb24uY29tMA0GCSqGSIb3DQEBBQUA"
|
"A4GBAAMn0K3j3yhC+X+uyh6eABa2Eq7xiY5/mUB886Ir19vxluSMNKD6n/iY8vHj"
|
||||||
"A4GBAAMn0K3j3yhC+X+uyh6eABa2Eq7xiY5/mUB886Ir19vxluSMNKD6n/iY8vHj"
|
"trn0BhuW8/vmJyudFkIcEDUYE4ivQMlsfIL7SOGw6OevVLmm02aiRHWj5T20Ds+S"
|
||||||
"trn0BhuW8/vmJyudFkIcEDUYE4ivQMlsfIL7SOGw6OevVLmm02aiRHWj5T20Ds+S"
|
"OpueYUG3NBcHP/5IzhUYIQJbGzlQaUaZBMaQeC8ZslMNLWI2";
|
||||||
"OpueYUG3NBcHP/5IzhUYIQJbGzlQaUaZBMaQeC8ZslMNLWI2";
|
|
||||||
|
|
||||||
std::string google_cert_key = R"(-----BEGIN PUBLIC KEY-----
|
std::string google_cert_key = R"(-----BEGIN PUBLIC KEY-----
|
||||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZkqSFGwqoVAatVMJ0QIu/0zUpOlv
|
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZkqSFGwqoVAatVMJ0QIu/0zUpOlv
|
||||||
CZmrEfiNK/zSw2L+cgKWwM/B11zfIQ3bqzET+ictUNFCCpspbPBzx3saAg==
|
CZmrEfiNK/zSw2L+cgKWwM/B11zfIQ3bqzET+ictUNFCCpspbPBzx3saAg==
|
||||||
-----END PUBLIC KEY-----
|
-----END PUBLIC KEY-----
|
||||||
)";
|
)";
|
||||||
}
|
} // namespace
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ MEMwBQYDK2VxAzoAQomzAH8FXc0rhznaLR9DYwe5+DNhP0UwpZzS5y6iJ/iirrzI
|
|||||||
MEMwBQYDK2VxAzoAQomzAH8FXc0rhznaLR9DYwe5+DNhP0UwpZzS5y6iJ/iirrzI
|
MEMwBQYDK2VxAzoAQomzAH8FXc0rhznaLR9DYwe5+DNhP0UwpZzS5y6iJ/iirrzI
|
||||||
9/Fjbc/UvFxwFKFW7ij8QUwFsE8A
|
9/Fjbc/UvFxwFKFW7ij8QUwFsE8A
|
||||||
-----END PUBLIC KEY-----)";
|
-----END PUBLIC KEY-----)";
|
||||||
std::string sample_cert = R"(-----BEGIN CERTIFICATE-----
|
std::string sample_cert = R"(-----BEGIN CERTIFICATE-----
|
||||||
MIIDHDCCAgSgAwIBAgIIGlbUz5cvweUwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE
|
MIIDHDCCAgSgAwIBAgIIGlbUz5cvweUwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE
|
||||||
AxMmc2VjdXJldG9rZW4uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wHhcNMTkw
|
AxMmc2VjdXJldG9rZW4uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wHhcNMTkw
|
||||||
NDEwMjEyMDUxWhcNMTkwNDI3MDkzNTUxWjAxMS8wLQYDVQQDEyZzZWN1cmV0b2tl
|
NDEwMjEyMDUxWhcNMTkwNDI3MDkzNTUxWjAxMS8wLQYDVQQDEyZzZWN1cmV0b2tl
|
||||||
@@ -190,25 +190,24 @@ ftcs6dibdnbQtbX6o9E+KuvGHoNW5xcSjX8lwXTpopfvufPOLPcnFXi4UoYZ8NZ2
|
|||||||
flE/m/0zymX8I/Xu3+KKLhUnUROGC6zO3OnLHXCnEns=
|
flE/m/0zymX8I/Xu3+KKLhUnUROGC6zO3OnLHXCnEns=
|
||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
)";
|
)";
|
||||||
std::string sample_cert_base64_der =
|
std::string sample_cert_base64_der = "MIIDHDCCAgSgAwIBAgIIGlbUz5cvweUwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE"
|
||||||
"MIIDHDCCAgSgAwIBAgIIGlbUz5cvweUwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE"
|
"AxMmc2VjdXJldG9rZW4uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wHhcNMTkw"
|
||||||
"AxMmc2VjdXJldG9rZW4uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wHhcNMTkw"
|
"NDEwMjEyMDUxWhcNMTkwNDI3MDkzNTUxWjAxMS8wLQYDVQQDEyZzZWN1cmV0b2tl"
|
||||||
"NDEwMjEyMDUxWhcNMTkwNDI3MDkzNTUxWjAxMS8wLQYDVQQDEyZzZWN1cmV0b2tl"
|
"bi5zeXN0ZW0uZ3NlcnZpY2VhY2NvdW50LmNvbTCCASIwDQYJKoZIhvcNAQEBBQAD"
|
||||||
"bi5zeXN0ZW0uZ3NlcnZpY2VhY2NvdW50LmNvbTCCASIwDQYJKoZIhvcNAQEBBQAD"
|
"ggEPADCCAQoCggEBALRPFSsUi/bGcMVkD+XjJ6z/71u+7Wn1C1bRnM9sU3q7+Ere"
|
||||||
"ggEPADCCAQoCggEBALRPFSsUi/bGcMVkD+XjJ6z/71u+7Wn1C1bRnM9sU3q7+Ere"
|
"DV6an+z+YsjblskBX73h1GyYvmtkyuL7Uq0N+y+RTOmd2fwDw48gM5FEq6DNpVVW"
|
||||||
"DV6an+z+YsjblskBX73h1GyYvmtkyuL7Uq0N+y+RTOmd2fwDw48gM5FEq6DNpVVW"
|
"ZRIzzoMSLZCB+tg1eQZdGKtmctdd5Jjhwihf9Aa759fcj60GDG39G6A/w4Jok+J6"
|
||||||
"ZRIzzoMSLZCB+tg1eQZdGKtmctdd5Jjhwihf9Aa759fcj60GDG39G6A/w4Jok+J6"
|
"7sRabxxontJ4Kpo6zmwUKbWF8naJeCRTO0VAYLkJqEWO4VJTIHJeu2WpxM0qzvY9"
|
||||||
"7sRabxxontJ4Kpo6zmwUKbWF8naJeCRTO0VAYLkJqEWO4VJTIHJeu2WpxM0qzvY9"
|
"IY5Yd7Njegu64FoHU55dSfee2KwDa0/bajrknJfxWBN4hk/rqgGjxQmzAYMCB7/p"
|
||||||
"IY5Yd7Njegu64FoHU55dSfee2KwDa0/bajrknJfxWBN4hk/rqgGjxQmzAYMCB7/p"
|
"/9Snfg4NmfX5cJJ01SNzY6Q/mJRjB3iX2PBz+GsCAwEAAaM4MDYwDAYDVR0TAQH/"
|
||||||
"/9Snfg4NmfX5cJJ01SNzY6Q/mJRjB3iX2PBz+GsCAwEAAaM4MDYwDAYDVR0TAQH/"
|
"BAIwADAOBgNVHQ8BAf8EBAMCB4AwFgYDVR0lAQH/BAwwCgYIKwYBBQUHAwIwDQYJ"
|
||||||
"BAIwADAOBgNVHQ8BAf8EBAMCB4AwFgYDVR0lAQH/BAwwCgYIKwYBBQUHAwIwDQYJ"
|
"KoZIhvcNAQEFBQADggEBAKCSq0D+NIAsGULZrhXouurxInxDyq03xLNcxvKDQchc"
|
||||||
"KoZIhvcNAQEFBQADggEBAKCSq0D+NIAsGULZrhXouurxInxDyq03xLNcxvKDQchc"
|
"XfGA1r3eltmlyKQb5TmAsuKwS/LAQ5z8SlRTOmDGVEtDwnw3S83C4ufXbP0eMB6H"
|
||||||
"XfGA1r3eltmlyKQb5TmAsuKwS/LAQ5z8SlRTOmDGVEtDwnw3S83C4ufXbP0eMB6H"
|
"eKf2XCA00T3odUfXmQZme8hG6z7GKVOdn/0oY+vaX38brlCpRXDTm1WldyddUpMz"
|
||||||
"eKf2XCA00T3odUfXmQZme8hG6z7GKVOdn/0oY+vaX38brlCpRXDTm1WldyddUpMz"
|
"ftcs6dibdnbQtbX6o9E+KuvGHoNW5xcSjX8lwXTpopfvufPOLPcnFXi4UoYZ8NZ2"
|
||||||
"ftcs6dibdnbQtbX6o9E+KuvGHoNW5xcSjX8lwXTpopfvufPOLPcnFXi4UoYZ8NZ2"
|
"2mRG78LkOA+SkOMutbt6w7TBDvADmFzuzvAULy4gsfcamOYcQ7uiHnnD+PoNiNbw"
|
||||||
"2mRG78LkOA+SkOMutbt6w7TBDvADmFzuzvAULy4gsfcamOYcQ7uiHnnD+PoNiNbw"
|
"flE/m/0zymX8I/Xu3+KKLhUnUROGC6zO3OnLHXCnEns=";
|
||||||
"flE/m/0zymX8I/Xu3+KKLhUnUROGC6zO3OnLHXCnEns=";
|
std::string sample_cert_pubkey = R"(-----BEGIN PUBLIC KEY-----
|
||||||
std::string sample_cert_pubkey = R"(-----BEGIN PUBLIC KEY-----
|
|
||||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtE8VKxSL9sZwxWQP5eMn
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtE8VKxSL9sZwxWQP5eMn
|
||||||
rP/vW77tafULVtGcz2xTerv4St4NXpqf7P5iyNuWyQFfveHUbJi+a2TK4vtSrQ37
|
rP/vW77tafULVtGcz2xTerv4St4NXpqf7P5iyNuWyQFfveHUbJi+a2TK4vtSrQ37
|
||||||
L5FM6Z3Z/APDjyAzkUSroM2lVVZlEjPOgxItkIH62DV5Bl0Yq2Zy113kmOHCKF/0
|
L5FM6Z3Z/APDjyAzkUSroM2lVVZlEjPOgxItkIH62DV5Bl0Yq2Zy113kmOHCKF/0
|
||||||
@@ -218,4 +217,4 @@ l/FYE3iGT+uqAaPFCbMBgwIHv+n/1Kd+Dg2Z9flwknTVI3NjpD+YlGMHeJfY8HP4
|
|||||||
awIDAQAB
|
awIDAQAB
|
||||||
-----END PUBLIC KEY-----
|
-----END PUBLIC KEY-----
|
||||||
)";
|
)";
|
||||||
}
|
} // namespace test_keys
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#define JWT_DISABLE_PICOJSON // Make sure JWT compiles with this flag
|
#define JWT_DISABLE_PICOJSON // Make sure JWT compiles with this flag
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include "jwt-cpp/jwt.h"
|
#include "jwt-cpp/jwt.h"
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
struct nlohmann_traits {
|
struct nlohmann_traits {
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
@@ -13,77 +13,61 @@ struct nlohmann_traits {
|
|||||||
using number_type = json::number_float_t;
|
using number_type = json::number_float_t;
|
||||||
using integer_type = json::number_integer_t;
|
using integer_type = json::number_integer_t;
|
||||||
using boolean_type = json::boolean_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;
|
using jwt::json::type;
|
||||||
|
|
||||||
if (val.type() == json::value_t::boolean)
|
if (val.type() == json::value_t::boolean) return type::boolean;
|
||||||
return type::boolean;
|
if (val.type() == json::value_t::number_integer) return type::integer;
|
||||||
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
|
if (val.type() == json::value_t::number_unsigned) // nlohmann internally tracks two types of integers
|
||||||
return type::integer;
|
return type::integer;
|
||||||
if (val.type() == json::value_t::number_float)
|
if (val.type() == json::value_t::number_float) return type::number;
|
||||||
return type::number;
|
if (val.type() == json::value_t::string) return type::string;
|
||||||
if (val.type() == json::value_t::string)
|
if (val.type() == json::value_t::array) return type::array;
|
||||||
return type::string;
|
if (val.type() == json::value_t::object) return type::object;
|
||||||
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");
|
throw std::logic_error("invalid type");
|
||||||
}
|
}
|
||||||
|
|
||||||
static json::object_t as_object(const json &val) {
|
static json::object_t as_object(const json& val) {
|
||||||
if (val.type() != json::value_t::object)
|
if (val.type() != json::value_t::object) throw std::bad_cast();
|
||||||
throw std::bad_cast();
|
|
||||||
return val.get<json::object_t>();
|
return val.get<json::object_t>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string as_string(const json &val) {
|
static std::string as_string(const json& val) {
|
||||||
if (val.type() != json::value_t::string)
|
if (val.type() != json::value_t::string) throw std::bad_cast();
|
||||||
throw std::bad_cast();
|
|
||||||
return val.get<std::string>();
|
return val.get<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static json::array_t as_array(const json &val) {
|
static json::array_t as_array(const json& val) {
|
||||||
if (val.type() != json::value_t::array)
|
if (val.type() != json::value_t::array) throw std::bad_cast();
|
||||||
throw std::bad_cast();
|
|
||||||
return val.get<json::array_t>();
|
return val.get<json::array_t>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t as_int(const json &val) {
|
static int64_t as_int(const json& val) {
|
||||||
switch(val.type())
|
switch (val.type()) {
|
||||||
{
|
|
||||||
case json::value_t::number_integer:
|
case json::value_t::number_integer:
|
||||||
case json::value_t::number_unsigned:
|
case json::value_t::number_unsigned: return val.get<int64_t>();
|
||||||
return val.get<int64_t>();
|
default: throw std::bad_cast();
|
||||||
default:
|
|
||||||
throw std::bad_cast();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool as_bool(const json &val) {
|
static bool as_bool(const json& val) {
|
||||||
if (val.type() != json::value_t::boolean)
|
if (val.type() != json::value_t::boolean) throw std::bad_cast();
|
||||||
throw std::bad_cast();
|
|
||||||
return val.get<bool>();
|
return val.get<bool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static double as_number(const json &val) {
|
static double as_number(const json& val) {
|
||||||
if (val.type() != json::value_t::number_float)
|
if (val.type() != json::value_t::number_float) throw std::bad_cast();
|
||||||
throw std::bad_cast();
|
|
||||||
return val.get<double>();
|
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());
|
val = json::parse(str.begin(), str.end());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string serialize(const json &val) {
|
static std::string serialize(const json& val) { return val.dump(); }
|
||||||
return val.dump();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(NlohmannTest, BasicClaims) {
|
TEST(NlohmannTest, BasicClaims) {
|
||||||
@@ -95,9 +79,8 @@ TEST(NlohmannTest, BasicClaims) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(NlohmannTest, AudienceAsString) {
|
TEST(NlohmannTest, AudienceAsString) {
|
||||||
std::string token =
|
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
|
||||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
|
"WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
||||||
"WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
|
||||||
auto decoded = jwt::decode<nlohmann_traits>(token);
|
auto decoded = jwt::decode<nlohmann_traits>(token);
|
||||||
|
|
||||||
ASSERT_TRUE(decoded.has_algorithm());
|
ASSERT_TRUE(decoded.has_algorithm());
|
||||||
@@ -122,14 +105,10 @@ TEST(NlohmannTest, AudienceAsString) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(NlohmannTest, SetArray) {
|
TEST(NlohmannTest, SetArray) {
|
||||||
std::vector<int64_t> vect = {
|
std::vector<int64_t> vect = {100, 20, 10};
|
||||||
100,
|
|
||||||
20,
|
|
||||||
10
|
|
||||||
};
|
|
||||||
auto token = jwt::create<nlohmann_traits>()
|
auto token = jwt::create<nlohmann_traits>()
|
||||||
.set_payload_claim("test", jwt::basic_claim<nlohmann_traits>(vect.begin(), vect.end()))
|
.set_payload_claim("test", jwt::basic_claim<nlohmann_traits>(vect.begin(), vect.end()))
|
||||||
.sign(jwt::algorithm::none{});
|
.sign(jwt::algorithm::none{});
|
||||||
ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0.");
|
ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,50 +116,51 @@ TEST(NlohmannTest, SetObject) {
|
|||||||
std::istringstream iss{"{\"api-x\": [1]}"};
|
std::istringstream iss{"{\"api-x\": [1]}"};
|
||||||
jwt::basic_claim<nlohmann_traits> object;
|
jwt::basic_claim<nlohmann_traits> object;
|
||||||
iss >> 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>()
|
auto token =
|
||||||
.set_payload_claim("namespace", object)
|
jwt::create<nlohmann_traits>().set_payload_claim("namespace", object).sign(jwt::algorithm::hs256("test"));
|
||||||
.sign(jwt::algorithm::hs256("test"));
|
ASSERT_EQ(token,
|
||||||
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
"eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NlohmannTest, VerifyTokenHS256) {
|
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>({})
|
auto verify = jwt::verify<jwt::default_clock, nlohmann_traits>({})
|
||||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
.allow_algorithm(jwt::algorithm::hs256{"secret"})
|
||||||
.with_issuer("auth0");
|
.with_issuer("auth0");
|
||||||
|
|
||||||
auto decoded_token = jwt::decode<nlohmann_traits>(token);
|
auto decoded_token = jwt::decode<nlohmann_traits>(token);
|
||||||
verify.verify(decoded_token);
|
verify.verify(decoded_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NlohmannTest, VerifyTokenExpirationValid) {
|
TEST(NlohmannTest, VerifyTokenExpirationValid) {
|
||||||
const auto token = jwt::create<nlohmann_traits>()
|
const auto token = jwt::create<nlohmann_traits>()
|
||||||
.set_issuer("auth0")
|
.set_issuer("auth0")
|
||||||
.set_issued_at(std::chrono::system_clock::now())
|
.set_issued_at(std::chrono::system_clock::now())
|
||||||
.set_expires_at(std::chrono::system_clock::now() + std::chrono::seconds{3600})
|
.set_expires_at(std::chrono::system_clock::now() + std::chrono::seconds{3600})
|
||||||
.sign(jwt::algorithm::hs256{"secret"});
|
.sign(jwt::algorithm::hs256{"secret"});
|
||||||
|
|
||||||
auto verify = jwt::verify<jwt::default_clock, nlohmann_traits>({})
|
auto verify = jwt::verify<jwt::default_clock, nlohmann_traits>({})
|
||||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
.allow_algorithm(jwt::algorithm::hs256{"secret"})
|
||||||
.with_issuer("auth0");
|
.with_issuer("auth0");
|
||||||
|
|
||||||
auto decoded_token = jwt::decode<nlohmann_traits>(token);
|
auto decoded_token = jwt::decode<nlohmann_traits>(token);
|
||||||
verify.verify(decoded_token);
|
verify.verify(decoded_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NlohmannTest, VerifyTokenExpired) {
|
TEST(NlohmannTest, VerifyTokenExpired) {
|
||||||
const auto token = jwt::create<nlohmann_traits>()
|
const auto token = jwt::create<nlohmann_traits>()
|
||||||
.set_issuer("auth0")
|
.set_issuer("auth0")
|
||||||
.set_issued_at(std::chrono::system_clock::now() - std::chrono::seconds{3601})
|
.set_issued_at(std::chrono::system_clock::now() - std::chrono::seconds{3601})
|
||||||
.set_expires_at(std::chrono::system_clock::now() - std::chrono::seconds{1})
|
.set_expires_at(std::chrono::system_clock::now() - std::chrono::seconds{1})
|
||||||
.sign(jwt::algorithm::hs256{"secret"});
|
.sign(jwt::algorithm::hs256{"secret"});
|
||||||
|
|
||||||
auto verify = jwt::verify<jwt::default_clock, nlohmann_traits>({})
|
auto verify = jwt::verify<jwt::default_clock, nlohmann_traits>({})
|
||||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
.allow_algorithm(jwt::algorithm::hs256{"secret"})
|
||||||
.with_issuer("auth0");
|
.with_issuer("auth0");
|
||||||
|
|
||||||
auto decoded_token = jwt::decode<nlohmann_traits>(token);
|
auto decoded_token = jwt::decode<nlohmann_traits>(token);
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[]) {
|
||||||
{
|
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include "jwt-cpp/jwt.h"
|
#include "jwt-cpp/jwt.h"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
TEST(TokenFormatTest, MissingDot) {
|
TEST(TokenFormatTest, MissingDot) {
|
||||||
ASSERT_THROW(jwt::decode("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9"), std::invalid_argument);
|
ASSERT_THROW(jwt::decode("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9"), std::invalid_argument);
|
||||||
@@ -13,4 +13,4 @@ TEST(TokenFormatTest, InvalidChar) {
|
|||||||
|
|
||||||
TEST(TokenFormatTest, InvalidJSON) {
|
TEST(TokenFormatTest, InvalidJSON) {
|
||||||
ASSERT_THROW(jwt::decode("YXsiYWxnIjoibm9uZSIsInR5cCI6IkpXUyJ9YQ.eyJpc3MiOiJhdXRoMCJ9."), std::runtime_error);
|
ASSERT_THROW(jwt::decode("YXsiYWxnIjoibm9uZSIsInR5cCI6IkpXUyJ9YQ.eyJpc3MiOiJhdXRoMCJ9."), std::runtime_error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include "jwt-cpp/jwt.h"
|
#include "jwt-cpp/jwt.h"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
inline namespace test_keys {
|
inline namespace test_keys {
|
||||||
extern std::string rsa_priv_key;
|
extern std::string rsa_priv_key;
|
||||||
@@ -24,10 +24,11 @@ inline namespace test_keys {
|
|||||||
extern std::string ed448_priv_key;
|
extern std::string ed448_priv_key;
|
||||||
extern std::string ed448_pub_key;
|
extern std::string ed448_pub_key;
|
||||||
extern std::string ed448_pub_key_invalid;
|
extern std::string ed448_pub_key_invalid;
|
||||||
}
|
} // namespace test_keys
|
||||||
|
|
||||||
TEST(TokenTest, DecodeToken) {
|
TEST(TokenTest, DecodeToken) {
|
||||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
std::string token =
|
||||||
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||||
auto decoded = jwt::decode(token);
|
auto decoded = jwt::decode(token);
|
||||||
|
|
||||||
ASSERT_TRUE(decoded.has_algorithm());
|
ASSERT_TRUE(decoded.has_algorithm());
|
||||||
@@ -48,182 +49,168 @@ TEST(TokenTest, DecodeToken) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateToken) {
|
TEST(TokenTest, CreateToken) {
|
||||||
auto token = jwt::create()
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::none{});
|
||||||
.set_issuer("auth0")
|
|
||||||
.set_type("JWS")
|
|
||||||
.sign(jwt::algorithm::none{});
|
|
||||||
ASSERT_EQ("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9.", token);
|
ASSERT_EQ("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9.", token);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenHS256) {
|
TEST(TokenTest, CreateTokenHS256) {
|
||||||
auto token = jwt::create()
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::hs256{"secret"});
|
||||||
.set_issuer("auth0")
|
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE",
|
||||||
.set_type("JWS")
|
token);
|
||||||
.sign(jwt::algorithm::hs256{"secret"});
|
|
||||||
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE", token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenRS256) {
|
TEST(TokenTest, CreateTokenRS256) {
|
||||||
auto token = jwt::create()
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||||
.set_issuer("auth0")
|
jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""));
|
||||||
.set_type("JWS")
|
|
||||||
.sign(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""));
|
|
||||||
|
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ", token);
|
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ",
|
||||||
|
token);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenRS512) {
|
TEST(TokenTest, CreateTokenRS512) {
|
||||||
auto token = jwt::create()
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||||
.set_issuer("auth0")
|
jwt::algorithm::rs512(rsa512_pub_key, rsa512_priv_key, "", ""));
|
||||||
.set_type("JWS")
|
|
||||||
.sign(jwt::algorithm::rs512(rsa512_pub_key, rsa512_priv_key, "", ""));
|
|
||||||
|
|
||||||
ASSERT_EQ(
|
ASSERT_EQ("eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZSSQyLKvI0"
|
||||||
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZSSQyLKvI0"
|
"TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4GB"
|
||||||
"TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4GB"
|
"hfGgejPBCBlGrQtqFGFdHHOjNHY",
|
||||||
"hfGgejPBCBlGrQtqFGFdHHOjNHY", token);
|
token);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenPS256) {
|
TEST(TokenTest, CreateTokenPS256) {
|
||||||
auto token = jwt::create()
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||||
.set_issuer("auth0")
|
jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", ""));
|
||||||
.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
|
// TODO: Find a better way to check if generated signature is valid
|
||||||
// Can't do simple check for equal since pss adds random salt.
|
// Can't do simple check for equal since pss adds random salt.
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenPS384) {
|
TEST(TokenTest, CreateTokenPS384) {
|
||||||
auto token = jwt::create()
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||||
.set_issuer("auth0")
|
jwt::algorithm::ps384(rsa_pub_key, rsa_priv_key, "", ""));
|
||||||
.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
|
// TODO: Find a better way to check if generated signature is valid
|
||||||
// Can't do simple check for equal since pss adds random salt.
|
// Can't do simple check for equal since pss adds random salt.
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenPS512) {
|
TEST(TokenTest, CreateTokenPS512) {
|
||||||
auto token = jwt::create()
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||||
.set_issuer("auth0")
|
jwt::algorithm::ps512(rsa_pub_key, rsa_priv_key, "", ""));
|
||||||
.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
|
// TODO: Find a better way to check if generated signature is valid
|
||||||
// Can't do simple check for equal since pss adds random salt.
|
// Can't do simple check for equal since pss adds random salt.
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenES256) {
|
TEST(TokenTest, CreateTokenES256) {
|
||||||
|
|
||||||
auto token = jwt::create()
|
auto token =
|
||||||
.set_issuer("auth0")
|
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::es256("", ecdsa256_priv_key, "", ""));
|
||||||
.set_type("JWS")
|
|
||||||
.sign(jwt::algorithm::es256("", ecdsa256_priv_key, "", ""));
|
|
||||||
|
|
||||||
auto decoded = jwt::decode(token);
|
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));
|
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key, "", "", "")).verify(decoded));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenES256NoPrivate) {
|
TEST(TokenTest, CreateTokenES256NoPrivate) {
|
||||||
|
|
||||||
ASSERT_THROW([](){
|
ASSERT_THROW(
|
||||||
auto token = jwt::create()
|
[]() {
|
||||||
.set_issuer("auth0")
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||||
.set_type("JWS")
|
jwt::algorithm::es256(ecdsa256_pub_key, "", "", ""));
|
||||||
.sign(jwt::algorithm::es256(ecdsa256_pub_key, "", "", ""));
|
}(),
|
||||||
}(), jwt::signature_generation_exception);
|
jwt::signature_generation_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenES384) {
|
TEST(TokenTest, CreateTokenES384) {
|
||||||
|
|
||||||
auto token = jwt::create()
|
auto token =
|
||||||
.set_issuer("auth0")
|
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::es384("", ecdsa384_priv_key, "", ""));
|
||||||
.set_type("JWS")
|
|
||||||
.sign(jwt::algorithm::es384("", ecdsa384_priv_key, "", ""));
|
|
||||||
|
|
||||||
auto decoded = jwt::decode(token);
|
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));
|
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key, "", "", "")).verify(decoded));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenES384NoPrivate) {
|
TEST(TokenTest, CreateTokenES384NoPrivate) {
|
||||||
|
|
||||||
ASSERT_THROW([](){
|
ASSERT_THROW(
|
||||||
auto token = jwt::create()
|
[]() {
|
||||||
.set_issuer("auth0")
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||||
.set_type("JWS")
|
jwt::algorithm::es384(ecdsa384_pub_key, "", "", ""));
|
||||||
.sign(jwt::algorithm::es384(ecdsa384_pub_key, "", "", ""));
|
}(),
|
||||||
}(), jwt::signature_generation_exception);
|
jwt::signature_generation_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenES512) {
|
TEST(TokenTest, CreateTokenES512) {
|
||||||
|
|
||||||
auto token = jwt::create()
|
auto token =
|
||||||
.set_issuer("auth0")
|
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::es512("", ecdsa521_priv_key, "", ""));
|
||||||
.set_type("JWS")
|
|
||||||
.sign(jwt::algorithm::es512("", ecdsa521_priv_key, "", ""));
|
|
||||||
|
|
||||||
auto decoded = jwt::decode(token);
|
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));
|
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key, "", "", "")).verify(decoded));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, CreateTokenES512NoPrivate) {
|
TEST(TokenTest, CreateTokenES512NoPrivate) {
|
||||||
|
|
||||||
ASSERT_THROW([](){
|
ASSERT_THROW(
|
||||||
auto token = jwt::create()
|
[]() {
|
||||||
.set_issuer("auth0")
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||||
.set_type("JWS")
|
jwt::algorithm::es512(ecdsa521_pub_key, "", "", ""));
|
||||||
.sign(jwt::algorithm::es512(ecdsa521_pub_key, "", "", ""));
|
}(),
|
||||||
}(), jwt::signature_generation_exception);
|
jwt::signature_generation_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OPENSSL110
|
#ifndef OPENSSL110
|
||||||
TEST(TokenTest, CreateTokenEd25519) {
|
TEST(TokenTest, CreateTokenEd25519) {
|
||||||
|
|
||||||
auto token = jwt::create()
|
auto token =
|
||||||
.set_issuer("auth0")
|
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::ed25519("", ed25519_priv_key, "", ""));
|
||||||
.set_type("JWS")
|
|
||||||
.sign(jwt::algorithm::ed25519("", ed25519_priv_key, "", ""));
|
|
||||||
|
|
||||||
auto decoded = jwt::decode(token);
|
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_THROW(
|
||||||
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key, "", "", "")).verify(decoded));
|
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) {
|
TEST(TokenTest, CreateTokenEd448) {
|
||||||
|
|
||||||
auto token = jwt::create()
|
auto token =
|
||||||
.set_issuer("auth0")
|
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::ed448("", ed448_priv_key, "", ""));
|
||||||
.set_type("JWS")
|
|
||||||
.sign(jwt::algorithm::ed448("", ed448_priv_key, "", ""));
|
|
||||||
|
|
||||||
auto decoded = jwt::decode(token);
|
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));
|
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key, "", "", "")).verify(decoded));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenWrongAlgorithm) {
|
TEST(TokenTest, VerifyTokenWrongAlgorithm) {
|
||||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
std::string token =
|
||||||
|
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth0");
|
||||||
.allow_algorithm(jwt::algorithm::none{})
|
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -234,8 +221,7 @@ TEST(TokenTest, VerifyTokenNoneFail) {
|
|||||||
// None algorithm should not have a signature
|
// None algorithm should not have a signature
|
||||||
std::string token = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpYXQiOjE1OTUyNjc1MTZ9.cmFuZG9tc2ln";
|
std::string token = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpYXQiOjE1OTUyNjc1MTZ9.cmFuZG9tc2ln";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::none{});
|
||||||
.allow_algorithm(jwt::algorithm::none{});
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -243,22 +229,22 @@ TEST(TokenTest, VerifyTokenNoneFail) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenRS256FailNoKey) {
|
TEST(TokenTest, VerifyTokenRS256FailNoKey) {
|
||||||
ASSERT_THROW([](){
|
ASSERT_THROW(
|
||||||
auto verify = jwt::verify()
|
[]() {
|
||||||
.allow_algorithm(jwt::algorithm::rs256("", "", "", ""))
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs256("", "", "", "")).with_issuer("auth0");
|
||||||
.with_issuer("auth0");
|
}(),
|
||||||
}(), jwt::rsa_exception);
|
jwt::rsa_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenRS256) {
|
TEST(TokenTest, VerifyTokenRS256) {
|
||||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
std::string token =
|
||||||
|
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify =
|
||||||
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""))
|
jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", "")).with_issuer("auth0");
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -266,14 +252,13 @@ TEST(TokenTest, VerifyTokenRS256) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenRS256PublicOnly) {
|
TEST(TokenTest, VerifyTokenRS256PublicOnly) {
|
||||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
std::string token =
|
||||||
|
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, "", "", "")).with_issuer("auth0");
|
||||||
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, "", "", ""))
|
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -281,14 +266,13 @@ TEST(TokenTest, VerifyTokenRS256PublicOnly) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenRS256PrivateOnly) {
|
TEST(TokenTest, VerifyTokenRS256PrivateOnly) {
|
||||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
std::string token =
|
||||||
|
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs256("", rsa_priv_key, "", "")).with_issuer("auth0");
|
||||||
.allow_algorithm(jwt::algorithm::rs256("", rsa_priv_key, "", ""))
|
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -296,14 +280,14 @@ TEST(TokenTest, VerifyTokenRS256PrivateOnly) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenRS256Fail) {
|
TEST(TokenTest, VerifyTokenRS256Fail) {
|
||||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
std::string token =
|
||||||
|
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify =
|
||||||
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key_invalid, "", "", ""))
|
jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key_invalid, "", "", "")).with_issuer("auth0");
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -311,13 +295,14 @@ TEST(TokenTest, VerifyTokenRS256Fail) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenRS512) {
|
TEST(TokenTest, VerifyTokenRS512) {
|
||||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
std::string token =
|
||||||
|
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify()
|
||||||
.allow_algorithm(jwt::algorithm::rs512(rsa512_pub_key, rsa512_priv_key, "", ""))
|
.allow_algorithm(jwt::algorithm::rs512(rsa512_pub_key, rsa512_priv_key, "", ""))
|
||||||
.with_issuer("auth0");
|
.with_issuer("auth0");
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -325,13 +310,12 @@ TEST(TokenTest, VerifyTokenRS512) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenRS512PublicOnly) {
|
TEST(TokenTest, VerifyTokenRS512PublicOnly) {
|
||||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
std::string token =
|
||||||
|
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs512(rsa512_pub_key, "", "", "")).with_issuer("auth0");
|
||||||
.allow_algorithm(jwt::algorithm::rs512(rsa512_pub_key, "", "", ""))
|
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -339,13 +323,13 @@ TEST(TokenTest, VerifyTokenRS512PublicOnly) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenRS512PrivateOnly) {
|
TEST(TokenTest, VerifyTokenRS512PrivateOnly) {
|
||||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
std::string token =
|
||||||
|
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify =
|
||||||
.allow_algorithm(jwt::algorithm::rs512("", rsa512_priv_key, "", ""))
|
jwt::verify().allow_algorithm(jwt::algorithm::rs512("", rsa512_priv_key, "", "")).with_issuer("auth0");
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -353,13 +337,13 @@ TEST(TokenTest, VerifyTokenRS512PrivateOnly) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenRS512Fail) {
|
TEST(TokenTest, VerifyTokenRS512Fail) {
|
||||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
std::string token =
|
||||||
|
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify =
|
||||||
.allow_algorithm(jwt::algorithm::rs512(rsa_pub_key_invalid, "", "", ""))
|
jwt::verify().allow_algorithm(jwt::algorithm::rs512(rsa_pub_key_invalid, "", "", "")).with_issuer("auth0");
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -367,33 +351,30 @@ TEST(TokenTest, VerifyTokenRS512Fail) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenHS256) {
|
TEST(TokenTest, VerifyTokenHS256) {
|
||||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
std::string token =
|
||||||
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"secret"}).with_issuer("auth0");
|
||||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
verify.verify(decoded_token);
|
verify.verify(decoded_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenHS256Fail) {
|
TEST(TokenTest, VerifyTokenHS256Fail) {
|
||||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
std::string token =
|
||||||
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"wrongsecret"}).with_issuer("auth0");
|
||||||
.allow_algorithm(jwt::algorithm::hs256{ "wrongsecret" })
|
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenHS256FailSignatureLength) {
|
TEST(TokenTest, VerifyTokenHS256FailSignatureLength) {
|
||||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkA";
|
std::string token =
|
||||||
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkA";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"secret"}).with_issuer("auth0");
|
||||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||||
@@ -402,96 +383,86 @@ TEST(TokenTest, VerifyTokenHS256FailSignatureLength) {
|
|||||||
TEST(TokenTest, VerifyFail) {
|
TEST(TokenTest, VerifyFail) {
|
||||||
{
|
{
|
||||||
auto token = jwt::create()
|
auto token = jwt::create()
|
||||||
.set_issuer("auth0")
|
.set_issuer("auth0")
|
||||||
.set_type("JWS")
|
.set_type("JWS")
|
||||||
.set_audience("random")
|
.set_audience("random")
|
||||||
.set_payload_claim("typetest", picojson::value(10.0))
|
.set_payload_claim("typetest", picojson::value(10.0))
|
||||||
.sign(jwt::algorithm::none{});
|
.sign(jwt::algorithm::none{});
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
{
|
{
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth");
|
||||||
.allow_algorithm(jwt::algorithm::none{})
|
|
||||||
.with_issuer("auth");
|
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify()
|
||||||
.allow_algorithm(jwt::algorithm::none{})
|
.allow_algorithm(jwt::algorithm::none{})
|
||||||
.with_issuer("auth0")
|
.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");
|
||||||
|
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");
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify()
|
||||||
.allow_algorithm(jwt::algorithm::none{})
|
.allow_algorithm(jwt::algorithm::none{})
|
||||||
.with_issuer("auth0")
|
.with_issuer("auth0")
|
||||||
.with_audience("test");
|
.with_claim("myclaim", jwt::claim(std::string("test")));
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify()
|
||||||
.allow_algorithm(jwt::algorithm::none{})
|
.allow_algorithm(jwt::algorithm::none{})
|
||||||
.with_issuer("auth0")
|
.with_issuer("auth0")
|
||||||
.with_subject("test");
|
.with_claim("typetest", jwt::claim(picojson::value(true)));
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
auto verify = jwt::verify()
|
|
||||||
.allow_algorithm(jwt::algorithm::none{})
|
|
||||||
.with_issuer("auth0")
|
|
||||||
.with_claim("myclaim", jwt::claim(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_claim("typetest", jwt::claim(picojson::value(true)));
|
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
jwt::claim object;
|
jwt::claim object;
|
||||||
std::istringstream iss{ R"({ "test": null })" };
|
std::istringstream iss{R"({ "test": null })"};
|
||||||
iss >> object;
|
iss >> object;
|
||||||
ASSERT_EQ(object.get_type(), jwt::json::type::object);
|
ASSERT_EQ(object.get_type(), jwt::json::type::object);
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify()
|
||||||
.allow_algorithm(jwt::algorithm::none{})
|
.allow_algorithm(jwt::algorithm::none{})
|
||||||
.with_issuer("auth0")
|
.with_issuer("auth0")
|
||||||
.with_claim("myclaim", object);
|
.with_claim("myclaim", object);
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto token = jwt::create()
|
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::none{});
|
||||||
.set_issuer("auth0")
|
|
||||||
.set_type("JWS")
|
|
||||||
.sign(jwt::algorithm::none{});
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
{
|
{
|
||||||
auto verify = jwt::verify()
|
auto verify =
|
||||||
.allow_algorithm(jwt::algorithm::none{})
|
jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth0").with_audience("test");
|
||||||
.with_issuer("auth0")
|
|
||||||
.with_audience("test");
|
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenES256FailNoKey) {
|
TEST(TokenTest, VerifyTokenES256FailNoKey) {
|
||||||
ASSERT_THROW([](){
|
ASSERT_THROW(
|
||||||
auto verify = jwt::verify()
|
[]() {
|
||||||
.allow_algorithm(jwt::algorithm::es256("", "", "", ""))
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es256("", "", "", "")).with_issuer("auth0");
|
||||||
.with_issuer("auth0");
|
}(),
|
||||||
}(), jwt::ecdsa_exception);
|
jwt::ecdsa_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenES256) {
|
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 verify = jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key, "", "", ""));
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
@@ -500,17 +471,19 @@ TEST(TokenTest, VerifyTokenES256) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenES256Fail) {
|
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()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key_invalid, "", "", ""));
|
||||||
.allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key_invalid, "", "", ""));
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenES384) {
|
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 verify = jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key, "", "", ""));
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
@@ -519,17 +492,21 @@ TEST(TokenTest, VerifyTokenES384) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenES384Fail) {
|
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()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key_invalid, "", "", ""));
|
||||||
.allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key_invalid, "", "", ""));
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenES521) {
|
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 verify = jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key, "", "", ""));
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
@@ -538,24 +515,26 @@ TEST(TokenTest, VerifyTokenES521) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenES521Fail) {
|
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()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key_invalid, "", "", ""));
|
||||||
.allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key_invalid, "", "", ""));
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenPS256) {
|
TEST(TokenTest, VerifyTokenPS256) {
|
||||||
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
std::string token =
|
||||||
|
"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||||
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
||||||
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
||||||
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify =
|
||||||
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", ""))
|
jwt::verify().allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", "")).with_issuer("auth0");
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -563,14 +542,13 @@ TEST(TokenTest, VerifyTokenPS256) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenPS256PublicOnly) {
|
TEST(TokenTest, VerifyTokenPS256PublicOnly) {
|
||||||
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
std::string token =
|
||||||
|
"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||||
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
||||||
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
||||||
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, "", "", "")).with_issuer("auth0");
|
||||||
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, "", "", ""))
|
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -578,14 +556,14 @@ TEST(TokenTest, VerifyTokenPS256PublicOnly) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenPS256Fail) {
|
TEST(TokenTest, VerifyTokenPS256Fail) {
|
||||||
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
std::string token =
|
||||||
|
"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||||
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
||||||
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
||||||
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify =
|
||||||
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key_invalid, "", "", ""))
|
jwt::verify().allow_algorithm(jwt::algorithm::ps256(rsa_pub_key_invalid, "", "", "")).with_issuer("auth0");
|
||||||
.with_issuer("auth0");
|
|
||||||
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
@@ -593,16 +571,17 @@ TEST(TokenTest, VerifyTokenPS256Fail) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenPS256FailNoKey) {
|
TEST(TokenTest, VerifyTokenPS256FailNoKey) {
|
||||||
ASSERT_THROW([](){
|
ASSERT_THROW(
|
||||||
auto verify = jwt::verify()
|
[]() {
|
||||||
.allow_algorithm(jwt::algorithm::ps256("", "", "", ""))
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ps256("", "", "", "")).with_issuer("auth0");
|
||||||
.with_issuer("auth0");
|
}(),
|
||||||
}(), jwt::rsa_exception);
|
jwt::rsa_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OPENSSL110
|
#ifndef OPENSSL110
|
||||||
TEST(TokenTest, VerifyTokenEd25519) {
|
TEST(TokenTest, VerifyTokenEd25519) {
|
||||||
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
|
const std::string token =
|
||||||
|
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
|
||||||
"DOnKiNmc0O2AnvQlzr-9cgI4QGQzeC6gz_fgLoesADg";
|
"DOnKiNmc0O2AnvQlzr-9cgI4QGQzeC6gz_fgLoesADg";
|
||||||
|
|
||||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key, "", "", ""));
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key, "", "", ""));
|
||||||
@@ -612,18 +591,19 @@ TEST(TokenTest, VerifyTokenEd25519) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenEd25519Fail) {
|
TEST(TokenTest, VerifyTokenEd25519Fail) {
|
||||||
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
|
const std::string token =
|
||||||
|
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
|
||||||
"DOnKiNmc0O2AnvQlzr-9cgI4QGQzeC6gz_fgLoesADg";
|
"DOnKiNmc0O2AnvQlzr-9cgI4QGQzeC6gz_fgLoesADg";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key_invalid, "", "", ""));
|
||||||
.allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key_invalid, "", "", ""));
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenEd448) {
|
TEST(TokenTest, VerifyTokenEd448) {
|
||||||
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
|
const std::string token =
|
||||||
|
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
|
||||||
"Bsw_3MHs8HtgKeXbqKFYWpHOCtmZJcH-AWMvoY6FCNdQqbESGTkv58O6tFbXDD_nLejWNAOuvcO2LPMySmkVNQUopmQf_HO62Mug1ngepUDE"
|
"Bsw_3MHs8HtgKeXbqKFYWpHOCtmZJcH-AWMvoY6FCNdQqbESGTkv58O6tFbXDD_nLejWNAOuvcO2LPMySmkVNQUopmQf_HO62Mug1ngepUDE"
|
||||||
"A";
|
"A";
|
||||||
|
|
||||||
@@ -634,12 +614,12 @@ TEST(TokenTest, VerifyTokenEd448) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenEd448Fail) {
|
TEST(TokenTest, VerifyTokenEd448Fail) {
|
||||||
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
|
const std::string token =
|
||||||
|
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
|
||||||
"Bsw_3MHs8HtgKeXbqKFYWpHOCtmZJcH-AWMvoY6FCNdQqbESGTkv58O6tFbXDD_nLejWNAOuvcO2LPMySmkVNQUopmQf_HO62Mug1ngepUDE"
|
"Bsw_3MHs8HtgKeXbqKFYWpHOCtmZJcH-AWMvoY6FCNdQqbESGTkv58O6tFbXDD_nLejWNAOuvcO2LPMySmkVNQUopmQf_HO62Mug1ngepUDE"
|
||||||
"A";
|
"A";
|
||||||
|
|
||||||
auto verify = jwt::verify()
|
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key_invalid, "", "", ""));
|
||||||
.allow_algorithm(jwt::algorithm::ed448(ed448_pub_key_invalid, "", "", ""));
|
|
||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||||
@@ -648,9 +628,7 @@ TEST(TokenTest, VerifyTokenEd448Fail) {
|
|||||||
|
|
||||||
struct test_clock {
|
struct test_clock {
|
||||||
jwt::date n;
|
jwt::date n;
|
||||||
jwt::date now() const {
|
jwt::date now() const { return n; }
|
||||||
return n;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(TokenTest, VerifyTokenExpireFail) {
|
TEST(TokenTest, VerifyTokenExpireFail) {
|
||||||
@@ -658,7 +636,7 @@ TEST(TokenTest, VerifyTokenExpireFail) {
|
|||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(110)})
|
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(110)})
|
||||||
.allow_algorithm(jwt::algorithm::none{});
|
.allow_algorithm(jwt::algorithm::none{});
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
||||||
@@ -672,7 +650,7 @@ TEST(TokenTest, VerifyTokenExpire) {
|
|||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(90)})
|
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(90)})
|
||||||
.allow_algorithm(jwt::algorithm::none{});
|
.allow_algorithm(jwt::algorithm::none{});
|
||||||
ASSERT_NO_THROW(verify.verify(decoded_token));
|
ASSERT_NO_THROW(verify.verify(decoded_token));
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
||||||
@@ -685,7 +663,7 @@ TEST(TokenTest, VerifyTokenNBFFail) {
|
|||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(90)})
|
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(90)})
|
||||||
.allow_algorithm(jwt::algorithm::none{});
|
.allow_algorithm(jwt::algorithm::none{});
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
||||||
@@ -699,7 +677,7 @@ TEST(TokenTest, VerifyTokenNBF) {
|
|||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(110)})
|
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(110)})
|
||||||
.allow_algorithm(jwt::algorithm::none{});
|
.allow_algorithm(jwt::algorithm::none{});
|
||||||
ASSERT_NO_THROW(verify.verify(decoded_token));
|
ASSERT_NO_THROW(verify.verify(decoded_token));
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
||||||
@@ -712,7 +690,7 @@ TEST(TokenTest, VerifyTokenIATFail) {
|
|||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(90)})
|
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(90)})
|
||||||
.allow_algorithm(jwt::algorithm::none{});
|
.allow_algorithm(jwt::algorithm::none{});
|
||||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
||||||
@@ -726,7 +704,7 @@ TEST(TokenTest, VerifyTokenIAT) {
|
|||||||
auto decoded_token = jwt::decode(token);
|
auto decoded_token = jwt::decode(token);
|
||||||
|
|
||||||
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(110)})
|
auto verify = jwt::verify<test_clock, jwt::picojson_traits>({std::chrono::system_clock::from_time_t(110)})
|
||||||
.allow_algorithm(jwt::algorithm::none{});
|
.allow_algorithm(jwt::algorithm::none{});
|
||||||
ASSERT_NO_THROW(verify.verify(decoded_token));
|
ASSERT_NO_THROW(verify.verify(decoded_token));
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
ASSERT_NO_THROW(verify.verify(decoded_token, ec));
|
||||||
@@ -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(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::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_pub_key, ""), jwt::ecdsa_exception);
|
||||||
ASSERT_THROW(jwt::algorithm::es384("", ecdsa256_priv_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);
|
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(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::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_pub_key, ""), jwt::ecdsa_exception);
|
||||||
ASSERT_THROW(jwt::algorithm::es512("", ecdsa256_priv_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);
|
ASSERT_THROW(jwt::algorithm::es512(ecdsa256_pub_key, ecdsa256_priv_key), jwt::ecdsa_exception);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef JWT_DISABLE_BASE64
|
#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
|
#endif
|
||||||
|
|
||||||
#include "jwt-cpp/jwt.h"
|
#include "jwt-cpp/jwt.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
jwt::date date;
|
jwt::date date;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "jwt-cpp/jwt.h"
|
#include "jwt-cpp/jwt.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
jwt::claim claim;
|
jwt::claim claim;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#if !__has_include(<tls.h>)
|
#if !__has_include(<tls.h>)
|
||||||
#error "missing LibreSSL's TLS header!
|
#error "missing LibreSSL's TLS header!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <tls.h>
|
#include <tls.h>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "jwt-cpp/jwt.h"
|
#include "jwt-cpp/jwt.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
tls_init();
|
tls_init();
|
||||||
jwt::date date;
|
jwt::date date;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#ifndef JWT_DISABLE_PICOJSON
|
#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
|
#endif
|
||||||
|
|
||||||
#include "jwt-cpp/jwt.h"
|
#include "jwt-cpp/jwt.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
jwt::date date;
|
jwt::date date;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.8)
|
|||||||
project(jwt-cpp-jsoncons-tests)
|
project(jwt-cpp-jsoncons-tests)
|
||||||
|
|
||||||
if(NOT TARGET jwt-cpp)
|
if(NOT TARGET jwt-cpp)
|
||||||
find_package(jwt-cpp CONFIG REQUIRED)
|
find_package(jwt-cpp CONFIG REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(GTest REQUIRED)
|
find_package(GTest REQUIRED)
|
||||||
|
|||||||
@@ -8,64 +8,51 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
struct jsoncons_traits
|
struct jsoncons_traits {
|
||||||
{
|
|
||||||
using json = jsoncons::json;
|
using json = jsoncons::json;
|
||||||
using value_type = json;
|
using value_type = json;
|
||||||
struct object_type : json::object
|
struct object_type : json::object {
|
||||||
{
|
|
||||||
using value_type = key_value_type;
|
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() = default;
|
||||||
object_type(const object_type &) = default;
|
object_type(const object_type&) = default;
|
||||||
object_type(const json::object &o) : json::object(o) {}
|
object_type(const json::object& o) : json::object(o) {}
|
||||||
object_type(object_type &&) = default;
|
object_type(object_type&&) = default;
|
||||||
object_type(json::object &&o) : json::object(o) {}
|
object_type(json::object&& o) : json::object(o) {}
|
||||||
object_type &operator=(const object_type &o)
|
object_type& operator=(const object_type& o) {
|
||||||
{
|
|
||||||
// avoid private deleted copy operator= https://github.com/danielaparker/jsoncons/pull/298
|
// 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);
|
(*this) = std::move(t);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
object_type &operator=(object_type &&o) noexcept
|
object_type& operator=(object_type&& o) noexcept {
|
||||||
{
|
|
||||||
swap(o);
|
swap(o);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapped_type &operator[](const key_type &key)
|
mapped_type& operator[](const key_type& key) {
|
||||||
{
|
auto ret = try_emplace(
|
||||||
auto ret = try_emplace(key); // https://github.com/microsoft/STL/blob/2914b4301c59dc7ffc09d16ac6f7979fde2b7f2c/stl/inc/map#L325
|
key); // https://github.com/microsoft/STL/blob/2914b4301c59dc7ffc09d16ac6f7979fde2b7f2c/stl/inc/map#L325
|
||||||
return ret.first->value();
|
return ret.first->value();
|
||||||
}
|
}
|
||||||
mapped_type &operator[](key_type &&key)
|
mapped_type& operator[](key_type&& key) {
|
||||||
{
|
|
||||||
auto ret = try_emplace(key);
|
auto ret = try_emplace(key);
|
||||||
return ret.first->value();
|
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);
|
auto target = find(key);
|
||||||
if (target != end())
|
if (target != end()) { return target->value(); }
|
||||||
{
|
|
||||||
return target->value();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::out_of_range("invalid key");
|
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;
|
size_t ret = 0;
|
||||||
for (const_iterator first = begin(); first != end(); ++first)
|
for (const_iterator first = begin(); first != end(); ++first) {
|
||||||
{
|
if (first->key() == key) { ++ret; }
|
||||||
if (first->key() == key)
|
|
||||||
{
|
|
||||||
++ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -76,88 +63,64 @@ struct jsoncons_traits
|
|||||||
using integer_type = int64_t;
|
using integer_type = int64_t;
|
||||||
using boolean_type = bool;
|
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;
|
using jwt::json::type;
|
||||||
|
|
||||||
if (val.type() == jsoncons::json_type::bool_value)
|
if (val.type() == jsoncons::json_type::bool_value) return type::boolean;
|
||||||
return type::boolean;
|
if (val.type() == jsoncons::json_type::int64_value) return type::integer;
|
||||||
if (val.type() == jsoncons::json_type::int64_value)
|
if (val.type() == jsoncons::json_type::uint64_value) return type::integer;
|
||||||
return type::integer;
|
if (val.type() == jsoncons::json_type::half_value) return type::number;
|
||||||
if (val.type() == jsoncons::json_type::uint64_value)
|
if (val.type() == jsoncons::json_type::double_value) return type::number;
|
||||||
return type::integer;
|
if (val.type() == jsoncons::json_type::string_value) return type::string;
|
||||||
if (val.type() == jsoncons::json_type::half_value)
|
if (val.type() == jsoncons::json_type::array_value) return type::array;
|
||||||
return type::number;
|
if (val.type() == jsoncons::json_type::object_value) return type::object;
|
||||||
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");
|
throw std::logic_error("invalid type");
|
||||||
}
|
}
|
||||||
|
|
||||||
static object_type as_object(const json &val)
|
static object_type as_object(const json& val) {
|
||||||
{
|
if (val.type() != jsoncons::json_type::object_value) throw std::bad_cast();
|
||||||
if (val.type() != jsoncons::json_type::object_value)
|
|
||||||
throw std::bad_cast();
|
|
||||||
return object_type(val.object_value());
|
return object_type(val.object_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
static array_type as_array(const json &val)
|
static array_type as_array(const json& val) {
|
||||||
{
|
if (val.type() != jsoncons::json_type::array_value) throw std::bad_cast();
|
||||||
if (val.type() != jsoncons::json_type::array_value)
|
|
||||||
throw std::bad_cast();
|
|
||||||
return val.array_value();
|
return val.array_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
static string_type as_string(const json &val)
|
static string_type as_string(const json& val) {
|
||||||
{
|
if (val.type() != jsoncons::json_type::string_value) throw std::bad_cast();
|
||||||
if (val.type() != jsoncons::json_type::string_value)
|
|
||||||
throw std::bad_cast();
|
|
||||||
return val.as_string();
|
return val.as_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
static number_type as_number(const json &val)
|
static number_type as_number(const json& val) {
|
||||||
{
|
if (get_type(val) != jwt::json::type::number) throw std::bad_cast();
|
||||||
if (get_type(val) != jwt::json::type::number)
|
|
||||||
throw std::bad_cast();
|
|
||||||
return val.as_double();
|
return val.as_double();
|
||||||
}
|
}
|
||||||
|
|
||||||
static integer_type as_int(const json &val)
|
static integer_type as_int(const json& val) {
|
||||||
{
|
if (get_type(val) != jwt::json::type::integer) throw std::bad_cast();
|
||||||
if (get_type(val) != jwt::json::type::integer)
|
|
||||||
throw std::bad_cast();
|
|
||||||
return val.as<integer_type>();
|
return val.as<integer_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean_type as_bool(const json &val)
|
static boolean_type as_bool(const json& val) {
|
||||||
{
|
if (val.type() != jsoncons::json_type::bool_value) throw std::bad_cast();
|
||||||
if (val.type() != jsoncons::json_type::bool_value)
|
|
||||||
throw std::bad_cast();
|
|
||||||
return val.as_bool();
|
return val.as_bool();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parse(json &val, std::string str)
|
static bool parse(json& val, std::string str) {
|
||||||
{
|
|
||||||
val = json::parse(str);
|
val = json::parse(str);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string serialize(const json &val)
|
static std::string serialize(const json& val) {
|
||||||
{
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << jsoncons::print(val);
|
os << jsoncons::print(val);
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(JsonconsTest, BasicClaims)
|
TEST(JsonconsTest, BasicClaims) {
|
||||||
{
|
|
||||||
using jsoncons_claim = jwt::basic_claim<jsoncons_traits>;
|
using jsoncons_claim = jwt::basic_claim<jsoncons_traits>;
|
||||||
|
|
||||||
const auto string = jsoncons_claim(std::string("string"));
|
const auto string = jsoncons_claim(std::string("string"));
|
||||||
@@ -165,12 +128,10 @@ TEST(JsonconsTest, BasicClaims)
|
|||||||
const auto integer = jsoncons_claim(159816816);
|
const auto integer = jsoncons_claim(159816816);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(JsonconsTest, AudienceAsString)
|
TEST(JsonconsTest, AudienceAsString) {
|
||||||
{
|
|
||||||
|
|
||||||
std::string token =
|
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
|
||||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
|
"WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
||||||
"WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
|
||||||
auto decoded = jwt::decode<jsoncons_traits>(token);
|
auto decoded = jwt::decode<jsoncons_traits>(token);
|
||||||
|
|
||||||
ASSERT_TRUE(decoded.has_algorithm());
|
ASSERT_TRUE(decoded.has_algorithm());
|
||||||
@@ -192,34 +153,29 @@ TEST(JsonconsTest, AudienceAsString)
|
|||||||
ASSERT_EQ("test", *aud.begin());
|
ASSERT_EQ("test", *aud.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(JsonconsTest, SetArray)
|
TEST(JsonconsTest, SetArray) {
|
||||||
{
|
std::vector<int64_t> vect = {100, 20, 10};
|
||||||
std::vector<int64_t> vect = {
|
|
||||||
100,
|
|
||||||
20,
|
|
||||||
10};
|
|
||||||
auto token = jwt::create<jsoncons_traits>()
|
auto token = jwt::create<jsoncons_traits>()
|
||||||
.set_payload_claim("test", jwt::basic_claim<jsoncons_traits>(vect.begin(), vect.end()))
|
.set_payload_claim("test", jwt::basic_claim<jsoncons_traits>(vect.begin(), vect.end()))
|
||||||
.sign(jwt::algorithm::none{});
|
.sign(jwt::algorithm::none{});
|
||||||
ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0.");
|
ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0.");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(JsonconsTest, SetObject)
|
TEST(JsonconsTest, SetObject) {
|
||||||
{
|
|
||||||
std::istringstream iss{"{\"api-x\": [1]}"};
|
std::istringstream iss{"{\"api-x\": [1]}"};
|
||||||
jwt::basic_claim<jsoncons_traits> object;
|
jwt::basic_claim<jsoncons_traits> object;
|
||||||
iss >> 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<jsoncons_traits>()
|
auto token =
|
||||||
.set_payload_claim("namespace", object)
|
jwt::create<jsoncons_traits>().set_payload_claim("namespace", object).sign(jwt::algorithm::hs256("test"));
|
||||||
.sign(jwt::algorithm::hs256("test"));
|
ASSERT_EQ(token,
|
||||||
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
"eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(JsonconsTest, VerifyTokenHS256)
|
TEST(JsonconsTest, VerifyTokenHS256) {
|
||||||
{
|
std::string token =
|
||||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||||
|
|
||||||
auto verify = jwt::verify<jwt::default_clock, jsoncons_traits>({})
|
auto verify = jwt::verify<jwt::default_clock, jsoncons_traits>({})
|
||||||
.allow_algorithm(jwt::algorithm::hs256{"secret"})
|
.allow_algorithm(jwt::algorithm::hs256{"secret"})
|
||||||
@@ -229,8 +185,7 @@ TEST(JsonconsTest, VerifyTokenHS256)
|
|||||||
verify.verify(decoded_token);
|
verify.verify(decoded_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(JsonconsTest, VerifyTokenExpirationValid)
|
TEST(JsonconsTest, VerifyTokenExpirationValid) {
|
||||||
{
|
|
||||||
const auto token = jwt::create<jsoncons_traits>()
|
const auto token = jwt::create<jsoncons_traits>()
|
||||||
.set_issuer("auth0")
|
.set_issuer("auth0")
|
||||||
.set_issued_at(std::chrono::system_clock::now())
|
.set_issued_at(std::chrono::system_clock::now())
|
||||||
@@ -245,8 +200,7 @@ TEST(JsonconsTest, VerifyTokenExpirationValid)
|
|||||||
verify.verify(decoded_token);
|
verify.verify(decoded_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(JsonconsTest, VerifyTokenExpired)
|
TEST(JsonconsTest, VerifyTokenExpired) {
|
||||||
{
|
|
||||||
const auto token = jwt::create<jsoncons_traits>()
|
const auto token = jwt::create<jsoncons_traits>()
|
||||||
.set_issuer("auth0")
|
.set_issuer("auth0")
|
||||||
.set_issued_at(std::chrono::system_clock::now() - std::chrono::seconds{3601})
|
.set_issued_at(std::chrono::system_clock::now() - std::chrono::seconds{3601})
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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)
|
|
||||||
Reference in New Issue
Block a user