Thalhammer / jwt-cpp

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

Exception is thrown with the exmple private-claims.cpp #351

Closed gggamemaster closed 1 month ago

gggamemaster commented 1 month ago

What's your question?

it raise a exception

Additional Context

the other example,i can run its well except example\partial-claim-verifier.cpp,because i do not install nlohmann-json。and why private-claims.cpp run fail? image image

prince-chrismc commented 1 month ago

What message does the exception print?

They were not meant to be running a debugger. They are likely just expiring

https://github.com/Thalhammer/jwt-cpp/blob/0d03bc5bc8b0fa16d535ec89e0dd6043b65b54d9/example/private-claims.cpp#L25

You should also check the call stack to see which verification function is failing, it's another way then reading the messages.

gggamemaster commented 1 month ago

image it seems time Expire? 89dd4fa218574dffc765dcc5fd0379e

gggamemaster commented 1 month ago

.set_expires_at(time + sec{15} + min{2}) menas that the token will time expire after 2 min 15 sec???just few time the exception araise..

gggamemaster commented 1 month ago

@Thalhammer

prince-chrismc commented 1 month ago

I'ts very difficult to see pictures, please keep the screenshot for the IDE. It's hard to follow with your language settings. It be great if you changed it to English (or french or german).

You can add

https://github.com/Thalhammer/jwt-cpp/blob/0d03bc5bc8b0fa16d535ec89e0dd6043b65b54d9/example/partial-claim-verifier.cpp#L89-L92

And this will print a message that will make ot easier to know what error you are getting.

Error 14 (I assume it's token verification)

https://github.com/Thalhammer/jwt-cpp/blob/0d03bc5bc8b0fa16d535ec89e0dd6043b65b54d9/include/jwt-cpp/jwt.h#L341

Do get the exception if you run the code outside of the debugger?

gggamemaster commented 1 month ago

you are right ,print "token expired" after i add the code on windows environment.

gggamemaster commented 1 month ago

i run private-claims.cpp fail in vs2022 debug 64 and vs2017 relaese64

Thalhammer commented 1 month ago

Thats pretty odd, ngl. The example sets a expiration of 1h and there should be no way he is halting the program for more than an hour (except on purpose) to debug it.

The example seems to work fine on godbolt (or at least it did with the 0.7 release, I don't add master to godbolt).

prince-chrismc commented 1 month ago

~The examples built last week with #348 so I dont think anything broke. Might be some localization with the time?~

prince-chrismc commented 1 month ago

Oh that example is not ran in CI... 😡

https://github.com/Thalhammer/jwt-cpp/blob/0d03bc5bc8b0fa16d535ec89e0dd6043b65b54d9/example/private-claims.cpp#L24

Is wrong that should be minus 15 seconds not plus.