pokowaka/jwt-cpp

Undefined reference to `json_loads'

konstantin-doncov opened this issue · 6 comments

I'm trying to use your library in Qt project using these lines in the my .pro file:

INCLUDEPATH += /usr/local/include/jwt
LIBS += -ljansson -ljwt -lcrypto -L/usr/local/lib

But I get these errors on the build stage:

/usr/local/lib/libjwt.a(jwt.cpp.o): In function `JWT::ExtractPayload(char const*, unsigned long)':
jwt.cpp:(.text+0x77b): undefined reference to `json_loads'
/usr/local/lib/libjwt.a(jwt.cpp.o): In function `JWT::Decode(char const*, unsigned long, MessageValidator*, ClaimValidator*)':
jwt.cpp:(.text+0xd41): undefined reference to `json_loads'
Makefile:333: recipe for target 'ProjectY_Server' failed
collect2: error: ld returned 1 exit status

How can I fix it?
Regards.

Do you have the libjansson-dev package (or similar) installed on your development system?

Yes, I had this library, but the problem probably in Qt - I deleted some statements in .pro file and then tried to bring them back, now all fine. I did not want to write until I understood exactly, so, sorry for the delay. But now I came to another misunderstanding (just don't want to raise your "issues" with non-issues, so, if you do not mind, I'll post it here): I want to use your library for Firebase token verification, as I understood, for this I need to do next:

  1. Get keys dictionary from this link
  2. Read kid field of the token
  3. Use kid field of the token as key for keys dictionary and get corresponding value. This is should be a public key
  4. Verify token using this public key

As I also understood, there is an another way which you used in your library: we can put ALL dictionary in the json message validator and JWT::Decode will do all what we need. But not everything is so good: if I just will put Google dictionary as follows:

std::string JSON_VALIDATORS =
        "{ \"set\" : [ "
        "  { \"RS256\" : { \"70a762492bfb611b371c0a1ffbd9efa473c9ecc0\" : \"MIIDHDCCAgSgAwIBAgIIAPBNQDY/y1cwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE\nAxMmc2VjdXJldG9rZW4uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wHhcNMTcw\nNzI1MDA0NTI2WhcNMTcwNzI4MDExNTI2WjAxMS8wLQYDVQQDEyZzZWN1cmV0b2tl\nbi5zeXN0ZW0uZ3NlcnZpY2VhY2NvdW50LmNvbTCCASIwDQYJKoZIh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3\nJ+cLX2iWoH/UgtLi7j7DZMKB1c7bdExJWWqyTr7Qsa0=\" } } "
        " ]"
        "}";

Then I will get:

terminate called after throwing an instance of 'std::logic_error'
what(): Failed to parse JSON: unexpected newline, at line: 1, col: 138

Then I tried to remove all \n chars and got this:

terminate called after throwing an instance of 'std::logic_error'
what(): Json error inside: parsing secret, property: public is missing from:

So, what I should to do for verifying Firebase token?

Now I understood that I need to use kid, but I can't use kid with the public key:

const char *json = "{ \"kid\" : { "
    "\"key1\" : { \"RS256\" : { \"public\" : \"key1\" } }, "
    "\"key2\" : { \"RS256\" : { \"public\" : \"key2\" } }, "
    "\"key3\" : { \"RS256\" : { \"public\" : \"key3\" } } "
    "} }";
validator_ptr validator(MessageValidatorFactory::Build(json));

Leads to:

terminate called after throwing an instance of 'std::logic_error'
what(): Json error inside: error:0906D06C:lib(9):func(109):reason(108)

So, how can I fix it or what can I use as an alternative?

The set one is ill formatted json. I will add a unit test to validate the last one. Note, I'm rewriting the library to get rid of jansson.

The cryptic error indicates that RSA validator does not understand that "key1" is an actual key. For rsa this needs to be a PEM formatted string. See https://support.quovadisglobal.com/kb/a37/what-is-pem-format.aspx

The library is no longer jannson