arun11299/cpp-jwt

Error when calling the function "get_claim_value"

Closed this issue · 3 comments

Hello,
I'm in it and testing your library. The decoding worked. Now I would like to read out a value via the function get_claim_value().

std::error_code ec;
auto decodeObj = jwt::decode(strFeatures.toStdString(), algorithms({"RS256"}), ec, secret(keyPublicKey.toStdString()));

jwt::string_view claimName = "Webvisu";
auto claimValue = decodeObj.payload().get_claim_value(claimName);
std::cout << claimValue << std::endl;

I get the following error:
image

Next I tested the following:
jwt::string_view claimName = "Webvisu";
auto claimValue = decodeObj.payload().get_claim_value<const jwt::string_view>(claimName);
std::cout << claimValue << std::endl;

And get this error:
image

Just seeing it now. I will take a look at it and get back.

The first error is because you need to explicitly provide the template parameter. There is no type deduction happening there as the type 'T' is not being used as the function argument.

As for the second case, its the nlohmann json library having some issue in supporting jwt::string_view. I will have to look into it. By that time, can you try doing:

auto claimValue = decodeObj.payload().get_claim_value<std::string>(claimName);

It works!