From b89a5b1cb5071c63333ea842c2ff42589340309a Mon Sep 17 00:00:00 2001 From: Ilya Andreev Date: Mon, 29 Dec 2025 16:08:15 +0300 Subject: [PATCH] Fix `set_expires_in` not accepting non-default `Period` (#402) --- example/rsa-create.cpp | 2 +- include/jwt-cpp/jwt.h | 4 ++-- tests/traits/BoostJsonTest.cpp | 2 +- tests/traits/JsonconsTest.cpp | 2 +- tests/traits/NlohmannTest.cpp | 2 +- tests/traits/OspJsoncppTest.cpp | 2 +- tests/traits/TraitsTest.cpp.mustache | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/example/rsa-create.cpp b/example/rsa-create.cpp index 2243f26..4ee3f60 100644 --- a/example/rsa-create.cpp +++ b/example/rsa-create.cpp @@ -37,7 +37,7 @@ rK0/Ikt5ybqUzKCMJZg2VKGTxg== .set_type("JWT") .set_id("rsa-create-example") .set_issued_now() - .set_expires_in(std::chrono::seconds{36000}) + .set_expires_in(std::chrono::hours{1}) .set_payload_claim("sample", jwt::claim(std::string{"test"})) .sign(jwt::algorithm::rs256("", rsa_priv_key, "", "")); diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h index 2c23202..5dcd2d2 100644 --- a/include/jwt-cpp/jwt.h +++ b/include/jwt-cpp/jwt.h @@ -3246,8 +3246,8 @@ namespace jwt { * \param d token expiration timeout * \return *this to allow for method chaining */ - template - builder& set_expires_in(const std::chrono::duration& d) { + template + builder& set_expires_in(const std::chrono::duration& d) { return set_payload_claim("exp", basic_claim(clock.now() + d)); } /** diff --git a/tests/traits/BoostJsonTest.cpp b/tests/traits/BoostJsonTest.cpp index 82c3810..8cdf7e1 100644 --- a/tests/traits/BoostJsonTest.cpp +++ b/tests/traits/BoostJsonTest.cpp @@ -87,7 +87,7 @@ TEST(BoostJsonTest, VerifyTokenExpirationInValid) { const auto token = jwt::create() .set_issuer("auth0") .set_issued_now() - .set_expires_in(std::chrono::seconds{3600}) + .set_expires_in(std::chrono::hours{1}) .sign(jwt::algorithm::hs256{"secret"}); const auto decoded_token = jwt::decode(token); diff --git a/tests/traits/JsonconsTest.cpp b/tests/traits/JsonconsTest.cpp index 7d0f1ad..facd90e 100644 --- a/tests/traits/JsonconsTest.cpp +++ b/tests/traits/JsonconsTest.cpp @@ -90,7 +90,7 @@ TEST(JsonconsTest, VerifyTokenExpirationInValid) { const auto token = jwt::create() .set_issuer("auth0") .set_issued_now() - .set_expires_in(std::chrono::seconds{3600}) + .set_expires_in(std::chrono::hours{1}) .sign(jwt::algorithm::hs256{"secret"}); const auto decoded_token = jwt::decode(token); diff --git a/tests/traits/NlohmannTest.cpp b/tests/traits/NlohmannTest.cpp index 616b622..513a6c7 100644 --- a/tests/traits/NlohmannTest.cpp +++ b/tests/traits/NlohmannTest.cpp @@ -86,7 +86,7 @@ TEST(NlohmannTest, VerifyTokenExpirationInValid) { const auto token = jwt::create() .set_issuer("auth0") .set_issued_now() - .set_expires_in(std::chrono::seconds{3600}) + .set_expires_in(std::chrono::hours{1}) .sign(jwt::algorithm::hs256{"secret"}); const auto decoded_token = jwt::decode(token); diff --git a/tests/traits/OspJsoncppTest.cpp b/tests/traits/OspJsoncppTest.cpp index 39a6df2..b853118 100644 --- a/tests/traits/OspJsoncppTest.cpp +++ b/tests/traits/OspJsoncppTest.cpp @@ -90,7 +90,7 @@ TEST(OspJsoncppTest, VerifyTokenExpirationInValid) { const auto token = jwt::create() .set_issuer("auth0") .set_issued_now() - .set_expires_in(std::chrono::seconds{3600}) + .set_expires_in(std::chrono::hours{1}) .sign(jwt::algorithm::hs256{"secret"}); const auto decoded_token = jwt::decode(token); diff --git a/tests/traits/TraitsTest.cpp.mustache b/tests/traits/TraitsTest.cpp.mustache index 84ae8fc..bc94fc9 100644 --- a/tests/traits/TraitsTest.cpp.mustache +++ b/tests/traits/TraitsTest.cpp.mustache @@ -90,7 +90,7 @@ TEST({{test_suite_name}}, VerifyTokenExpirationInValid) { const auto token = jwt::create() .set_issuer("auth0") .set_issued_now() - .set_expires_in(std::chrono::seconds{3600}) + .set_expires_in(std::chrono::hours{1}) .sign(jwt::algorithm::hs256{"secret"}); const auto decoded_token = jwt::decode(token);