-
-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add set_expires_in and set_issued_now methods #322
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are good QOL improvements. Just all of the examples
auto token = jwt::create()
.set_issuer("auth0")
.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_issued_now()
+ .set_expires_in(std::chrono::seconds{36000})
.set_payload_claim("sample", jwt::claim(std::string{"test"}))
.sign(jwt::algorithm::rs256("", rsa_priv_key, "", ""));
I would love to bring the verifier
and builder
closer in API design by making them use the default_clock
and this way under the hood both of them can have a clock::now()
to help them.
I think it makes sense the build could do the same as
Line 3478 in 953aab6
verify_ops::verify_context<json_traits> ctx{clock.now(), jwt, default_leeway}; |
WDYT?
Should I update examples or README with the new methods? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I update examples or README with the new methods?
I think that would be excellent. Going over the code in more details, I think this new API is less error prone (prevents creating tokens that are already expired) and I'd love to see this being used going forward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this awesome improvement!
Hi there!
I added
set_expires_in
andset_issued_now
method for the jwt builder.set_issued_now
sets a "iat" claim by calling system_clock::now() by itself;set_expires_in
sets a "exp" claim by adding the given duration tothe "iat" claimsystem_clock::now()Common usage of the jwt builder is:
This should make it a little bit more convenient.
Update: builder now has the Clock template parameter just like the verifier