Debian Codegraph @

include/jwt/test/test_jwt_decode.cc

raw
1 #include <iostream>
2 #include "jwt/jwt.hpp"
3
4 void basic_decode_test()
5 {
6 // Create header
7 jwt::jwt_header hdr;
8 hdr = jwt::jwt_header{jwt::algorithm::HS256};
9
10 // Create payload
11 jwt::jwt_payload jp;
12 jp.add_claim("sub", "1234567890");
13 jp.add_claim("name", "John Doe");
14 jp.add_claim("admin", true);
15
16 jwt::jwt_signature sgn{"secret"};
17 std::error_code ec{};
18 auto res = sgn.encode(hdr, jp, ec);
19 std::cout << res << std::endl;
20
21 using namespace jwt::params;
22
23 std::cout << "DECODE: \n";
24 jwt::decode(res, algorithms({"none", "HS256"}), ec, verify(false), secret("secret"));
25 }
26
27 int main() {
28 basic_decode_test();
29 return 0;
30 }