| 1 |
#include <iostream> |
| 2 |
#include "jwt/jwt.hpp" |
| 3 |
|
| 4 |
void basic_payload_test() |
| 5 |
{ |
| 6 |
jwt::jwt_payload jp; |
| 7 |
jp.add_claim("iss", "myself"); |
| 8 |
jp.add_claim("exp", 1234567); |
| 9 |
jp.add_claim("Exp", 1234567, true); |
| 10 |
|
| 11 |
auto jstr = jwt::to_json_str(jp); |
| 12 |
std::cout << jstr << std::endl; |
| 13 |
|
| 14 |
auto enc = jp.base64_encode(); |
| 15 |
std::cout << "Base64 enc: " << enc << std::endl; |
| 16 |
|
| 17 |
auto dec = jp.base64_decode(enc); |
| 18 |
std::cout << "Base64 dec: " << dec << std::endl; |
| 19 |
std::cout << "Base64 dec: " << jstr << std::endl; |
| 20 |
|
| 21 |
assert (jstr == dec && "Encoded and decoded messages do not match"); |
| 22 |
assert (jp.has_claim("exp") && "Claim exp must exist"); |
| 23 |
assert (jp.has_claim("Exp") && "Claim Exp must exist"); |
| 24 |
|
| 25 |
assert (!jp.has_claim("aud") && "Claim aud does not exist"); |
| 26 |
assert (jp.has_claim_with_value("exp", 1234567) && "Claim exp with value 1234567 does not exist"); |
| 27 |
|
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
int main() { |
| 32 |
basic_payload_test(); |
| 33 |
return 0; |
| 34 |
} |