Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-chrismc committed Dec 29, 2023
1 parent 0832604 commit 4e61103
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 48 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jwt-cpp supports all the algorithms defined by the specifications. The modular d
For completeness, here is a list of all supported algorithms:

| HMSC | RSA | ECDSA | PSS | EdDSA |
|-------|-------|--------|-------|---------|
| ----- | ----- | ------ | ----- | ------- |
| HS256 | RS256 | ES256 | PS256 | Ed25519 |
| HS384 | RS384 | ES384 | PS384 | Ed448 |
| HS512 | RS512 | ES512 | PS512 | |
Expand Down Expand Up @@ -101,7 +101,7 @@ Building on the goal of providing flexibility.

#### SSL Compatibility

In the name of flexibility and extensibility, jwt-cpp supports [OpenSSL](https://github.com/openssl/openssl), [LibreSSL](https://github.com/libressl-portable/portable), and [wolfSSL](https://github.com/wolfSSL/wolfssl). For a listed of tested versions, check [this page](docs/ssl.md) for more details.
jwt-cpp supports [OpenSSL](https://github.com/openssl/openssl), [LibreSSL](https://github.com/libressl-portable/portable), and [wolfSSL](https://github.com/wolfSSL/wolfssl). For a listed of tested versions, check [this page](docs/ssl.md) for more details.

#### JSON Implementation

Expand Down Expand Up @@ -144,4 +144,5 @@ In order to build the test cases you also need
See the [FAQs](docs/faqs.md) for tips.
## Conference Coverage
[![CppCon](https://img.youtube.com/vi/Oq4NW5idmiI/0.jpg)](https://www.youtube.com/watch?v=Oq4NW5idmiI)
18 changes: 7 additions & 11 deletions docs/faqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,30 @@ auto token = jwt::create()
### Can you add claims to a signed token?
The signature includes both the header and payload, according to the RFCs... changing the payload would cause a discrepancy.
That should result in the token being rejected. For more details checkout [#194](https://github.com/Thalhammer/jwt-cpp/issues/194).
The signature includes both the header and payload, according to the RFCs... changing the payload would cause a discrepancy. That should result in the token being rejected. For more details checkout [#194](https://github.com/Thalhammer/jwt-cpp/issues/194).
### Why does `jwt::basic_claim` have no `as_object()` method?
This was brought up in [#212](https://github.com/Thalhammer/jwt-cpp/issues/212#issuecomment-1054344192) and
[#101](https://github.com/Thalhammer/jwt-cpp/issues/101) as it's an excellent question.
It simply was not required to handle the required keys in JWTs for signing or verification. All the the mandatory keys
are numeric, string or array types which required type definitions and access.
It simply was not required to handle the required keys in JWTs for signing or verification. All the the mandatory keys are numeric, string or array types which required type definitions and access.
The alternative is to use the `to_json()` method and use the libraries own APIs to pick the data type you need.
## Build Issues
### Missing \_HMAC and \_EVP_sha256 symbols on Mac
There seems to exists a problem with the included openssl library of MacOS. Make sure you link to one provided by brew.
See [#6](https://github.com/Thalhammer/jwt-cpp/issues/6) for more details.
There seems to exists a problem with the included openssl library of MacOS. Make sure you link to one provided by brew. See [#6](https://github.com/Thalhammer/jwt-cpp/issues/6) for more details.
### Building on windows fails with syntax errors
The header `<Windows.h>`, which is often included in Windows projects, defines macros for MIN and MAX which conflicts
with `std::numeric_limits`. See [#5](https://github.com/Thalhammer/jwt-cpp/issues/5) for more details or
[this StackOverflow thread](https://stackoverflow.com/questions/13416418/define-nominmax-using-stdmin-max).
with `std::numeric_limits`. See [#5](https://github.com/Thalhammer/jwt-cpp/issues/5) for more details or [this StackOverflow thread](https://stackoverflow.com/questions/13416418/define-nominmax-using-stdmin-max).
To fix this do one of the following things:
* define `NOMINMAX`, which suppresses this behavior
* include this library before you `#include <Windows.h>`
* place `#undef max` and `#undef min` before you include this library
- define `NOMINMAX`, which suppresses this behavior
- include this library before you `#include <Windows.h>`
- place `#undef max` and `#undef min` before you include this library
12 changes: 6 additions & 6 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ When manually adding this dependency, and the dependencies this has, check the G

### Package Manager

- Conan: https://conan.io/center/recipes/jwt-cpp
- vcpkg: https://vcpkg.link/ports/jwt-cpp
- Nuget: https://www.nuget.org/packages/jwt-cpp/
- Hunter: https://hunter.readthedocs.io/en/latest/packages/pkg/jwt-cpp.html
- Spack: https://packages.spack.io/package.html?name=jwt-cpp
- Xrepo: https://xrepo.xmake.io/#/packages/linux?id=jwt-cpp-linux
- Conan: <https://conan.io/center/recipes/jwt-cpp>
- vcpkg: <https://vcpkg.link/ports/jwt-cpp>
- Nuget: <https://www.nuget.org/packages/jwt-cpp/>
- Hunter: <https://hunter.readthedocs.io/en/latest/packages/pkg/jwt-cpp.html>
- Spack: <https://packages.spack.io/package.html?name=jwt-cpp>
- Xrepo: <https://xrepo.xmake.io/#/packages/linux?id=jwt-cpp-linux>

Looking for ways to contribute? Help by adding JWT-CPP to your favorite package manager!
[Nixpkgs](https://github.com/NixOS/nixpkgs) for example. Currently many are behind the latest.
Expand Down
19 changes: 9 additions & 10 deletions docs/signing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@ The libraries design is open so you can implement your own algorithms, see [exis

```cpp
struct your_algorithm{
std::string sign(const std::string& /*unused*/, std::error_code& ec) const {
ec.clear();
std::string sign(const std::string& /*unused*/, std::error_code& ec) const {
ec.clear();
// CALL YOUR METHOD HERE
return {};
}
void verify(const std::string& /*unused*/, const std::string& signature, std::error_code& ec) const {
ec.clear();
if (!signature.empty()) { ec = error::signature_verification_error::invalid_signature; }
return {};
}
void verify(const std::string& /*unused*/, const std::string& signature, std::error_code& ec) const {
ec.clear();
if (!signature.empty()) { ec = error::signature_verification_error::invalid_signature; }
// CALL YOUR METHOD HERE
}
std::string name() const { return "your_algorithm"; }
}
std::string name() const { return "your_algorithm"; }
};
```

Then everything else is the same, just pass in your implementation such as:


```cpp
auto token = jwt::create()
.set_id("custom-algo-example")
Expand Down
5 changes: 2 additions & 3 deletions docs/ssl.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Cryptography Libraries

The underlying cryptography libraries describe [here](../README.md#ssl-compatibility) can be selected when
configuring CMake by explicitly setting `JWT_SSL_LIBRARY` to one of three values. The default is to use OpenSSL.
The underlying cryptography libraries describe [here](../README.md#ssl-compatibility) can be selected when configuring CMake by explicitly setting `JWT_SSL_LIBRARY` to one of three values. The default is to use OpenSSL.

- OpenSSL
- LibreSSL
Expand All @@ -18,7 +17,7 @@ cmake . -DJWT_SSL_LIBRARY:STRING=wolfSSL
These are the version which are currently being tested:

| OpenSSL | LibreSSL | wolfSSL |
|-------------------|----------------|----------------|
| ----------------- | -------------- | -------------- |
| ![1.0.2u][o1.0.2] | ![3.3.6][l3.3] | ![5.1.1][w5.1] |
| ![1.1.0i][o1.1.0] | ![3.4.3][l3.4] | ![5.2.0][w5.2] |
| ![1.1.1q][o1.1.1] | ![3.5.3][l3.5] | ![5.3.0][w5.3] |
Expand Down
32 changes: 16 additions & 16 deletions docs/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ In order to maintain compatibility, [picojson](https://github.com/kazuho/picojso

int main() {
// All the provided traits are in jwt::traits namespace
using traits = jwt::traits::nlohmann_json;
using traits = jwt::traits::nlohmann_json;

const auto time = jwt::date::clock::now();
const auto token = jwt::create<traits>()
.set_type("JWT")
.set_issuer("auth.mydomain.io")
.set_audience("mydomain.io")
.set_issued_at(time)
.set_not_before(time)
.set_expires_at(time + std::chrono::minutes{2} + std::chrono::seconds{15})
.sign(jwt::algorithm::none{});
const auto decoded = jwt::decode<traits>(token);

jwt::verify<traits>()
.allow_algorithm(jwt::algorithm::none{})
.with_issuer("auth.mydomain.io")
.with_audience("mydomain.io")
.verify(decoded);
const auto token = jwt::create<traits>()
.set_type("JWT")
.set_issuer("auth.mydomain.io")
.set_audience("mydomain.io")
.set_issued_at(time)
.set_not_before(time)
.set_expires_at(time + std::chrono::minutes{2} + std::chrono::seconds{15})
.sign(jwt::algorithm::none{});
const auto decoded = jwt::decode<traits>(token);

jwt::verify<traits>()
.allow_algorithm(jwt::algorithm::none{})
.with_issuer("auth.mydomain.io")
.with_audience("mydomain.io")
.verify(decoded);
```
## Providing your own JSON Traits
Expand Down

0 comments on commit 4e61103

Please sign in to comment.