Thalhammer / jwt-cpp

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

Guide to Setting Up jwt-cpp? #319

Closed hkRho closed 8 months ago

hkRho commented 9 months ago

What's your question?

Guide to Setting Up jwt-cpp?

Additional Context

Hi, before anything, thank you for creating and supporting this repo!

I was a bit confused in using this library--should I just include the entire folder in the desired project folder that I wish to use jwt-cpp? Do I also have to install the dependencies that I'd like to use (like OpenSSL) separately on my own, and/or build the repo with cmake?

I'm trying to use the functionalities in Visual Studio, but the #include is not recognizing jwt-cpp's dependencies like Openssl and picojson so was a bit lost on the setup steps that I may be missing. image I've tried including the jwt-cpp repo under my project directory and tried building it using cmake (the build seemed to work except this part -- Could NOT find jsoncons (missing: jsoncons_DIR) -- Could NOT find nlohmann_json (missing: nlohmann_json_DIR)

I really appreciate taking a look at this basic question and would love any guidance on how I can properly set jwt-cpp up and use it!

Thalhammer commented 9 months ago

Hi,

Jwt-cpp is extremly flexible when it comes to your project setup, all you need to make sure is that you have the contents in the include of this repo available in your include path and at least one of the dependencies is available.

You can, but don't have to use make for this. Assuming your project already uses cmake it just makes it extremly easy because you can use fetchcontent or a cmake package manager like cpm or hunter to pull in jwt-cpp.

However since you seem to be using visual studio without cmake, I would recommend using the official nuget packages for both jwt-cpp and openssl since they will setup all the include directories and libraries as needed.

Picojson is the only dependency thats shipped with jwt-cpp, but its mostly a placeholder for those that do not use another json library already, nowadays since the developer of it basically abandonded it years ago. Assuming you have set up your include paths correctly it should get recognized, since its part of the same directory.

hkRho commented 9 months ago

Hi @Thalhammer,

Thank you for a quick reply!

Just a quick clarification on

"make sure is that you have the contents in the include of this repo available in your include path"

so if I had #include <openssl/ssl.h> in jwt.h, I'd have to make sure that the ssl.h exists in jwt-cpp\include? Similarly, if I wanted to use another json library apart from Picojson, I'd just have to add it under jwt-cpp\include?

One follow-up question on using official nuget packages--I'm trying to use Jwt-cpp in a C++ Visual Studio Project. I thought Nuget packages are for C# and .Net projects (please correct me if I'm wrong) so would this not be a viable option?

Thank you so much!

Thalhammer commented 9 months ago

I'd have to make sure that the ssl.h exists in jwt-cpp\include?

No, you need to make sure your compiler can resolve <openssl/ssl.h> and <jwt-cpp/jwt.h> to the correct directories. The easiest way to achieve in your case would be installing the nuget packages, since they set everything up, but you can also do that manually in your project settings inside visual studio.

I thought Nuget packages are for C# and .Net projects

Not exclusively. Even though nuget started out for C#, it can also be used with C++.

prince-chrismc commented 9 months ago

I would always recommend looking into a package manager. Conan has MSbuild support if you are windows only along with the Nuget suggestion is very good.

I did at one time try to write a "getting started" guide 😅 Code here but that was Linux only

I would absolutely love to see a contribution, even if it's very limited to just your use case, that would be a tremendous asset.