Payload data type addded

This commit is contained in:
Arun M 2017-11-04 19:21:46 +05:30
parent 733696bf49
commit e7d52450d6
8 changed files with 199 additions and 11 deletions

View file

@ -0,0 +1,34 @@
#include <iostream>
#include "jwt/jwt.hpp"
void basic_payload_test()
{
jwt::jwt_payload jp;
jp.add_claim("iss", "myself");
jp.add_claim("exp", 1234567);
jp.add_claim("Exp", 1234567, true);
auto jstr = jwt::to_json_str(jp);
std::cout << jstr << std::endl;
auto enc = jp.base64_encode();
std::cout << "Base64 enc: " << enc << std::endl;
auto dec = jp.base64_decode(enc);
std::cout << "Base64 dec: " << dec << std::endl;
std::cout << "Base64 dec: " << jstr << std::endl;
assert (jstr == dec && "Encoded and decoded messages do not match");
assert (jp.has_claim("exp") && "Claim exp must exist");
assert (jp.has_claim("Exp") && "Claim Exp must exist");
assert (!jp.has_claim("aud") && "Claim aud does not exist");
assert (jp.has_claim_with_value("exp", 1234567) && "Claim exp with value 1234567 does not exist");
return;
}
int main() {
basic_payload_test();
return 0;
}