diff --git a/example/rsa-create.cpp b/example/rsa-create.cpp index 4870f1c..0c25396 100644 --- a/example/rsa-create.cpp +++ b/example/rsa-create.cpp @@ -46,6 +46,8 @@ YwIDAQAB .set_type("JWT") .set_id("rsa-create-example") .set_issued_at(std::chrono::system_clock::now()) + .set_expires_at(std::chrono::system_clock::now() + std::chrono::seconds{36000}) + .set_payload_claim("sample", jwt::claim(std::string{"test"})) .sign(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", "")); std::cout << "token:\n" << token << std::endl; diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h index c58df7d..aa35976 100644 --- a/include/jwt-cpp/jwt.h +++ b/include/jwt-cpp/jwt.h @@ -1440,8 +1440,8 @@ namespace jwt { return res; }; - jwt::header::header_claims = parse_claims(header); - jwt::payload::payload_claims = parse_claims(payload); + this->header_claims = parse_claims(header); + this->payload_claims = parse_claims(payload); } /** @@ -1479,7 +1479,20 @@ namespace jwt { * \return signature part before base64 decoding */ const typename json_traits::string_type& get_signature_base64() const noexcept { return signature_base64; } - + /** + * Get all payload claims + * \return map of claims + */ + std::unordered_map> get_payload_claims() const { + return this->payload_claims; + } + /** + * Get all header claims + * \return map of claims + */ + std::unordered_map> get_header_claims() const { + return this->header_claims; + } }; /** @@ -1579,19 +1592,19 @@ namespace jwt { * \param d Expires time * \return *this to allow for method chaining */ - builder& set_expires_at(const date& d) { return set_payload_claim("exp", typename json_traits::value_type(d)); } + builder& set_expires_at(const date& d) { return set_payload_claim("exp", basic_claim(d)); } /** * Set not before claim * \param d First valid time * \return *this to allow for method chaining */ - builder& set_not_before(const date& d) { return set_payload_claim("nbf", typename json_traits::value_type(d)); } + builder& set_not_before(const date& d) { return set_payload_claim("nbf", basic_claim(d)); } /** * Set issued at claim * \param d Issued at time, should be current time * \return *this to allow for method chaining */ - builder& set_issued_at(const date& d) { return set_payload_claim("iat", typename json_traits::value_type(d)); } + builder& set_issued_at(const date& d) { return set_payload_claim("iat", basic_claim(d)); } /** * Set id claim * \param str ID to set