Thalhammer / jwt-cpp

A header only library for creating and validating json web tokens in c++
https://thalhammer.github.io/jwt-cpp/
MIT License
917 stars 243 forks source link

support json string and picojson value type to set payload. #334

Closed Unbreak4ble closed 8 months ago

Unbreak4ble commented 8 months ago

This will allow programmers to quickly set payload by using an existing json string.

prince-chrismc commented 8 months ago

Could you please add some tests and an example? I would love to see how you are expecting this be be used :)

For the example how would you set the iat and exp claims.

prince-chrismc commented 8 months ago

My concern is this extra helper adds more complexity and could be mis-used.

How do you plan on changing those values such that they would be correct? The timestamps should always be different. Another's design questions, how do you prevent someone from destroying values they set?

What about the current API is not able to supporting this? You could roughly

const auto json_object = traits::parse(your_str);
for(auto [key, value] : json_object) {
   jwt_builder.set_payload_claim(key, value);
}

Why is this "quickly"? parsing JSON is terribly slow.

Unbreak4ble commented 8 months ago

The ideia is to parse a json string into the payload by using a single line. And i used the incorrect term "quickly" to express how big lines can be done in a single line.

I had not thought about using interactive loops. Thank you!