-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
611 additions
and
101 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
.github/actions/install/open-source-parsers-jsoncpp/action.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Install open-source-parsers/jsoncpp | ||
description: Install open-source-parsers/jsoncpp for building test application | ||
inputs: | ||
version: | ||
description: The desired open-source-parsers/jsoncpp version to install | ||
required: false | ||
default: "1.9.5" | ||
runs: | ||
using: composite | ||
steps: | ||
- run: | | ||
cd /tmp | ||
wget https://github.com/open-source-parsers/jsoncpp/archive/${{ inputs.version }}.tar.gz | ||
tar -zxf /tmp/${{ inputs.version }}.tar.gz | ||
cd jsoncpp-${{ inputs.version }} | ||
# https://github.com/open-source-parsers/jsoncpp/blob/69098a18b9af0c47549d9a271c054d13ca92b006/include/PreventInSourceBuilds.cmake#L8 | ||
mkdir build | ||
cd build | ||
cmake .. -DJSONCPP_WITH_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DBUILD_OBJECT_LIBS=OFF | ||
cmake --build . | ||
sudo cmake --install . | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "jwt-cpp/traits/open-source-parsers-jsoncpp/traits.h" | ||
|
||
#include <iostream> | ||
#include <sstream> | ||
|
||
int main() { | ||
using sec = std::chrono::seconds; | ||
using min = std::chrono::minutes; | ||
using traits = jwt::traits::open_source_parsers_jsoncpp; | ||
using claim = jwt::basic_claim<traits>; | ||
|
||
claim from_raw_json; | ||
std::istringstream iss{R"##({"api":{"array":[1,2,3],"null":null}})##"}; | ||
iss >> from_raw_json; | ||
|
||
claim::set_t list{"once", "twice"}; | ||
std::vector<int64_t> big_numbers{727663072ULL, 770979831ULL, 427239169ULL, 525936436ULL}; | ||
|
||
const auto time = jwt::date::clock::now(); | ||
const auto token = jwt::create<traits>() | ||
.set_type("JWT") | ||
.set_issuer("auth.mydomain.io") | ||
.set_audience("mydomain.io") | ||
.set_issued_at(time) | ||
.set_not_before(time) | ||
.set_expires_at(time + min{2} + sec{15}) | ||
.set_payload_claim("boolean", true) | ||
.set_payload_claim("integer", 12345) | ||
.set_payload_claim("precision", 12.3456789) | ||
.set_payload_claim("strings", claim(list)) | ||
.set_payload_claim("array", {big_numbers.begin(), big_numbers.end()}) | ||
.set_payload_claim("object", from_raw_json) | ||
.sign(jwt::algorithm::none{}); | ||
const auto decoded = jwt::decode<traits>(token); | ||
|
||
const auto array = traits::as_array(decoded.get_payload_claim("object").to_json()["api"]["array"]); | ||
std::cout << "payload /object/api/array = " << array << std::endl; | ||
|
||
jwt::verify<traits>() | ||
.allow_algorithm(jwt::algorithm::none{}) | ||
.with_issuer("auth.mydomain.io") | ||
.with_audience("mydomain.io") | ||
.with_claim("object", from_raw_json) | ||
.verify(decoded); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.