Skip to content
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

jsoncons trait longer compatible with latest release #371

Open
1 task done
dmazzella opened this issue Feb 27, 2025 · 5 comments
Open
1 task done

jsoncons trait longer compatible with latest release #371

dmazzella opened this issue Feb 27, 2025 · 5 comments
Labels

Comments

@dmazzella
Copy link

dmazzella commented Feb 27, 2025

What happened?

A bug happened!

With master version of jwt-cpp and jsoncons at 1.2.0

traits.h(93,28): error C2039: 'object_value': non è un membro di 'jsoncons::basic_json<char,jsoncons::sorted_policy,std::allocator<char>>'

traits.h(98,27): error C2039: 'array_value': non è un membro di 'jsoncons::basic_json<char,jsoncons::sorted_policy,std::allocator<char>>'

P.S.
updated static_assert from static_assert(jsoncons::version().minor >= 167, "A higher version of jsoncons is required!");

to

static_assert(jsoncons::version().minor >= 167 || (jsoncons::version().major > 0), "A higher version of jsoncons is required!");

How To Reproduce?

#include <iostream>

// #define USE_NLOHMANN_JSON

#pragma warning(push)
#pragma warning(disable: 4267)
#pragma warning(disable: 4244)
#define JWT_DISABLE_PICOJSON
#if defined(USE_NLOHMANN_JSON)
#include "jwt-cpp/traits/nlohmann-json/traits.h"
#else
#include "jsoncons/json.hpp"
#include "jwt-cpp/traits/danielaparker-jsoncons/traits.h"
#endif
#pragma warning(pop)

std::string _private_key = R"(-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC4ZtdaIrd1BPIJ
tfnF0TjIK5inQAXZ3XlCrUlJdP+XHwIRxdv1FsN12XyMYO/6ymLmo9ryoQeIrsXB
XYqlET3zfAY+diwCb0HEsVvhisthwMU4gZQu6TYW2s9LnXZB5rVtcBK69hcSlA2k
ZudMZWxZcj0L7KMfO2rIvaHw/qaVOE9j0T257Z8Kp2CLF9MUgX0ObhIsdumFRLaL
DvDUmBPr2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6Gdi+Kca3DE3F9Pq
PKgejo0SwP5vDT+rOGHN14bmGJUMsX9i4MTmZUZ5s8s3lXh3ysfT+GAhTd6nKrIE
kM3Nh6HWFhROptfc6BNusRh1kX/cspDplK5x8EpJ0QKBgQDWFg6S2je0KtbV5PYe
RultUEe2C0jYMDQx+JYxbPmtcopvZQrFEur3WKVuLy5UAy7EBvwMnZwIG7OOohJb
vkSpADK6VPn9lbqq7O8cTedEHttm6otmLt8ZyEl3hZMaL3hbuRj6ysjmoFKx6CrX
rK0/Ikt5ybqUzKCMJZg2VKGTxg==
-----END PRIVATE KEY-----
)";

std::string _public_key = R"(-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGbXWiK3dQTyCbX5xdE4
yCuYp0AF2d15Qq1JSXT/lx8CEcXb9RbDddl8jGDv+spi5qPa8qEHiK7FwV2KpRE9
83wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVs
WXI9C+yjHztqyL2h8P6mlThPY9E9ue2fCqdgixfTFIF9Dm4SLHbphUS2iw7w1JgT
69s7of9+I9l5lsJ9cozf1rxrXX4V1u/SotUuNB3Fp8oB4C1fLBEhSlMcUJirz1E8
AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0
YwIDAQAB
-----END PUBLIC KEY-----)";

int main()
{
#if defined(USE_NLOHMANN_JSON)
	using jwt_traits = jwt::traits::nlohmann_json;
#else
	using jwt_traits = jwt::traits::danielaparker_jsoncons;
#endif

	try
	{
		jwt::algorithm::rs256 rs256_private_key = jwt::algorithm::rs256{ "", _private_key, "", "" };
		std::cout << "private: " << rs256_private_key.name() << std::endl;

		jwt::algorithm::rs256 rs256_public_key = jwt::algorithm::rs256{ _public_key};
		std::cout << "pub: "  << rs256_public_key.name() << std::endl;

		auto access_token = jwt::create<jwt_traits>()
			.set_issuer("issuer")
			.set_type("JWT")
			.set_audience("aud")
			.set_issued_at(std::chrono::system_clock::now())
			.set_not_before(std::chrono::system_clock::now())
			.set_expires_at(std::chrono::system_clock::now() + std::chrono::seconds{ 3600 }).sign(rs256_private_key);
		std::cout << "Access Created: " << access_token << std::endl;

		const jwt::decoded_jwt<jwt_traits> access_decoded = jwt::decode<jwt_traits>(access_token);
		std::cout << "Access Token: " << access_decoded.get_payload() << std::endl;

		auto p = access_decoded.get_payload_json();

		jwt::verify<jwt_traits>().allow_algorithm(rs256_public_key).with_issuer("issuer").leeway(60UL).verify(access_decoded);
		std::cout << "Access Token Verified" << std::endl;
	}
	catch (const std::exception &e)
	{
		std::cerr << "Access Token Verification Failed: " << e.what() << std::endl;
	}
}

Version

0.7.0

What OS are you seeing the problem on?

Windows

What compiler are you seeing the problem on?

MSVC

Relevant log output

Compilazione avviata alle 09:09...
1>------ Inizio compilazione: Progetto: ConsoleApplication, Configurazione: Release ARM64 ------
1>ConsoleApplication.cpp
1>C:\Users\damianomazzella\source\repos\Others\jwt-cpp\ConsoleApplication\third_party\jwt-cpp\include\jwt-cpp\traits\danielaparker-jsoncons\traits.h(93,28): error C2039: 'object_value': non è un membro di 'jsoncons::basic_json<char,jsoncons::sorted_policy,std::allocator<char>>'
1>(compilazione del file di origine 'ConsoleApplication.cpp')
1>    C:\Users\damianomazzella\source\repos\Others\jwt-cpp\ConsoleApplication\third_party\jsoncons\jsoncons\basic_json.hpp(389,11):
1>    vedere la dichiarazione di 'jsoncons::basic_json<char,jsoncons::sorted_policy,std::allocator<char>>'
1>C:\Users\damianomazzella\source\repos\Others\jwt-cpp\ConsoleApplication\third_party\jwt-cpp\include\jwt-cpp\traits\danielaparker-jsoncons\traits.h(98,27): error C2039: 'array_value': non è un membro di 'jsoncons::basic_json<char,jsoncons::sorted_policy,std::allocator<char>>'
1>(compilazione del file di origine 'ConsoleApplication.cpp')
1>    C:\Users\damianomazzella\source\repos\Others\jwt-cpp\ConsoleApplication\third_party\jsoncons\jsoncons\basic_json.hpp(389,11):
1>    vedere la dichiarazione di 'jsoncons::basic_json<char,jsoncons::sorted_policy,std::allocator<char>>'
1>Compilazione progetto "ConsoleApplication.vcxproj" NON COMPLETATA.
========== Compilazione: 0 completato/i, 1 non riuscito/i, 0 aggiornato/i, 0 ignorato/i ==========
========== Compilazione completato alle 09:09 e ha richiesto 01,772 secondi ==========

Code of Conduct

  • I agree to follow this project's Code of Conduct
@dmazzella dmazzella added the bug label Feb 27, 2025
@prince-chrismc prince-chrismc changed the title jsoncons traits jsoncons trait longer compatible with latest release Feb 27, 2025
@prince-chrismc
Copy link
Collaborator

I would strongly encourage you to update the trait definition to be compatible with the newest release. If younise that library you'll be best suited for it.

It does seem the range needs set since there's a breaking change

@dmazzella
Copy link
Author

I'm on master of jwt-cpp, and on the latest release of jsoncons 1.2.0.

The Version 0.7.0 in the issue is forced by template, but I use the commit 482f4f1c050fb59db7f824636d8ab70ef8525544

Do you want me to do any particular tests?

@prince-chrismc
Copy link
Collaborator

Well the logs you posted show it does not compile, looks like the internals of jsocons have changed.

Maybe update the trait implementation to work with the new version?

@dmazzella
Copy link
Author

602

@prince-chrismc
Copy link
Collaborator

First reported in #366

@prince-chrismc prince-chrismc marked this as a duplicate of #366 Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants