Skip to content

Commit 885d8e7

Browse files
committed
WIP: Add support for TDEI access token authentication
1 parent e75de80 commit 885d8e7

34 files changed

+6432
-17
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ find_package(fmt 6.0 REQUIRED)
116116
target_link_libraries(cgimap_common_compiler_options INTERFACE
117117
$<IF:$<BOOL:${ENABLE_FMT_HEADER}>,fmt::fmt-header-only,fmt::fmt>)
118118

119+
# TDEI Workspaces - we need to link an OpenSSL implementation for JWT-CPP:
120+
find_package(OpenSSL REQUIRED)
121+
119122

120123
###########################
121124
# source subdirectories
@@ -141,7 +144,8 @@ target_link_libraries(openstreetmap_cgimap
141144
cgimap_fcgi
142145
cgimap_apidb
143146
Boost::program_options
144-
PQXX::PQXX)
147+
PQXX::PQXX
148+
OpenSSL::SSL)
145149

146150

147151
#############################################################

README

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ If you're running a Debian or Ubuntu system these can be installed
3434
using the following command:
3535

3636
sudo apt-get install libxml2-dev libpqxx-dev libfcgi-dev zlib1g-dev libbrotli-dev \
37-
libboost-program-options-dev libfmt-dev libmemcached-dev libcrypto++-dev libyajl-dev
37+
libboost-program-options-dev libfmt-dev libmemcached-dev libcrypto++-dev libyajl-dev \
38+
libssl-dev
3839

3940
Note that C++17 is _required_ to build CGImap.
4041

@@ -65,7 +66,7 @@ directory. For system-wide installation you still need to run:
6566

6667
For historic reasons, CGImap provides a number of shared libraries which were
6768
originally intended for reuse by other applications. As there are no real world
68-
consumers of these libraries, a static build is used by default. If you want
69+
consumers of these libraries, a static build is used by default. If you want
6970
to build with dynamic libraries instead, you can use the following cmake parameters:
7071

7172
cmake .. -DBUILD_SHARED_LIBS=ON

contrib/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ disable_build_lint()
44
add_subdirectory(catch2)
55
add_subdirectory(libxml++)
66
add_subdirectory(sjparser)
7+
add_subdirectory(jwt-cpp)
78

89
target_link_libraries(catch2 INTERFACE cgimap_common_compiler_options)
910
target_link_libraries(libxml++ PUBLIC cgimap_common_compiler_options)
11+
target_link_libraries(jwt-cpp INTERFACE cgimap_common_compiler_options)

contrib/jwt-cpp/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
3+
project(jwt-cpp
4+
LANGUAGES CXX)
5+
6+
add_library(jwt-cpp INTERFACE)
7+
8+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.23.0)
9+
target_sources(jwt-cpp
10+
INTERFACE
11+
FILE_SET HEADERS
12+
BASE_DIRS include/
13+
FILES
14+
picojson/picojson.h
15+
jwt-cpp/base.h
16+
jwt-cpp/traits/boost-json/defaults.h
17+
jwt-cpp/traits/boost-json/traits.h
18+
jwt-cpp/traits/danielaparker-jsoncons/defaults.h
19+
jwt-cpp/traits/danielaparker-jsoncons/traits.h
20+
jwt-cpp/traits/nlohmann-json/defaults.h
21+
jwt-cpp/traits/nlohmann-json/traits.h
22+
jwt-cpp/traits/kazuho-picojson/defaults.h
23+
jwt-cpp/traits/kazuho-picojson/traits.h
24+
jwt-cpp/traits/defaults.h.mustache
25+
jwt-cpp/jwt.h)
26+
27+
else()
28+
target_include_directories(jwt-cpp INTERFACE
29+
include/)
30+
endif()

contrib/jwt-cpp/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Dominik Thalhammer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

contrib/jwt-cpp/README.contrib

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Source: https://github.com/Thalhammer/jwt-cpp
2+
Revision: v0.7.0
3+
Commit: 08bcf77a687fb06e34138e9e9fa12a4ecbe12332
4+
5+
This library is used for TDEI Workspaces JWT token authentication.

contrib/jwt-cpp/README.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<img src="https://raw.githubusercontent.com/Thalhammer/jwt-cpp/master/.github/logo.svg" alt="logo" width="100%">
2+
3+
[![License Badge](https://img.shields.io/github/license/Thalhammer/jwt-cpp)](https://github.com/Thalhammer/jwt-cpp/blob/master/LICENSE)
4+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5f7055e294744901991fd0a1620b231d)](https://app.codacy.com/gh/Thalhammer/jwt-cpp/dashboard)
5+
[![Linux Badge][Linux]][Cross-Platform]
6+
[![MacOS Badge][MacOS]][Cross-Platform]
7+
[![Windows Badge][Windows]][Cross-Platform]
8+
[![Coverage Status](https://coveralls.io/repos/github/Thalhammer/jwt-cpp/badge.svg?branch=master)](https://coveralls.io/github/Thalhammer/jwt-cpp?branch=master)
9+
10+
[![Documentation Badge](https://img.shields.io/badge/Documentation-master-blue)](https://thalhammer.github.io/jwt-cpp/)
11+
12+
[![Stars Badge](https://img.shields.io/github/stars/Thalhammer/jwt-cpp)](https://github.com/Thalhammer/jwt-cpp/stargazers)
13+
[![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/Thalhammer/jwt-cpp?include_prereleases)](https://github.com/Thalhammer/jwt-cpp/releases)
14+
[![ConanCenter package](https://repology.org/badge/version-for-repo/conancenter/jwt-cpp.svg)](https://repology.org/project/jwt-cpp/versions)
15+
[![Vcpkg package](https://repology.org/badge/version-for-repo/vcpkg/jwt-cpp.svg)](https://repology.org/project/jwt-cpp/versions)
16+
17+
[Linux]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/cross-platform/ubuntu-latest/shields.json
18+
[MacOS]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/cross-platform/macos-latest/shields.json
19+
[Windows]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/cross-platform/windows-latest/shields.json
20+
[Cross-Platform]: https://github.com/Thalhammer/jwt-cpp/actions?query=workflow%3A%22Cross-Platform+CI%22
21+
22+
A header only library for creating and validating [JSON Web Tokens](https://tools.ietf.org/html/rfc7519) in C++11. For a great introduction, [read this](https://jwt.io/introduction/).
23+
24+
## Signature algorithms
25+
26+
jwt-cpp supports all the algorithms defined by the specifications. The modular design allows to easily add additional algorithms without any problems. If you need any feel free to create a pull request or [open an issue](https://github.com/Thalhammer/jwt-cpp/issues/new).
27+
28+
For completeness, here is a list of all supported algorithms:
29+
30+
| HMSC | RSA | ECDSA | PSS | EdDSA |
31+
|-------|-------|--------|-------|---------|
32+
| HS256 | RS256 | ES256 | PS256 | Ed25519 |
33+
| HS384 | RS384 | ES384 | PS384 | Ed448 |
34+
| HS512 | RS512 | ES512 | PS512 | |
35+
| | | ES256K | | |
36+
37+
## SSL Compatibility
38+
39+
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). Read [this page](docs/ssl.md) for more details. These are the version which are currently being tested:
40+
41+
| OpenSSL | LibreSSL | wolfSSL |
42+
|-------------------|----------------|----------------|
43+
| ![1.0.2u][o1.0.2] | ![3.3.6][l3.3] | ![5.1.1][w5.1] |
44+
| ![1.1.0i][o1.1.0] | ![3.4.3][l3.4] | ![5.2.0][w5.2] |
45+
| ![1.1.1q][o1.1.1] | ![3.5.3][l3.5] | ![5.3.0][w5.3] |
46+
| ![3.0.5][o3.0] | | |
47+
48+
> ℹ️ Note: A complete list of versions tested in the past can be found [here](https://github.com/Thalhammer/jwt-cpp/tree/badges).
49+
50+
[o1.0.2]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/openssl/1.0.2u/shields.json
51+
[o1.1.0]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/openssl/1.1.0i/shields.json
52+
[o1.1.1]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/openssl/1.1.1q/shields.json
53+
[o3.0]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/openssl/3.0.5/shields.json
54+
[l3.3]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.3.6/shields.json
55+
[l3.4]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.4.3/shields.json
56+
[l3.5]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.5.3/shields.json
57+
[w5.1]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/wolfssl/5.1.1/shields.json
58+
[w5.2]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/wolfssl/5.2.0/shields.json
59+
[w5.3]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/wolfssl/5.3.0/shields.json
60+
61+
## Overview
62+
63+
There is no hard dependency on a JSON library. Instead, there's a generic `jwt::basic_claim` which is templated around type traits, which described the semantic [JSON types](https://json-schema.org/understanding-json-schema/reference/type.html) for a value, object, array, string, number, integer and boolean, as well as methods to translate between them.
64+
65+
```cpp
66+
jwt::basic_claim<my_favorite_json_library_traits> claim(json::object({{"json", true},{"example", 0}}));
67+
```
68+
69+
This allows for complete freedom when picking which libraries you want to use. For more information, [read this page](docs/traits.md)).
70+
71+
For your convenience there are serval traits implementation which provide some popular JSON libraries. They are:
72+
73+
[![picojson][picojson]](https://github.com/kazuho/picojson)
74+
[![nlohmann][nlohmann]](https://github.com/nlohmann/json)
75+
[![jsoncons][jsoncons]](https://github.com/danielaparker/jsoncons)
76+
[![boostjson][boostjson]](https://github.com/boostorg/json)
77+
78+
[picojson]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/traits/kazuho-picojson/shields.json
79+
[nlohmann]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/traits/nlohmann-json/shields.json
80+
[jsoncons]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/traits/danielaparker-jsoncons/shields.json
81+
[boostjson]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/traits/boost-json/shields.json
82+
83+
In order to maintain compatibility, [picojson](https://github.com/kazuho/picojson) is still used to provide a specialized `jwt::claim` along with all helpers. Defining `JWT_DISABLE_PICOJSON` will remove this optional dependency. It's possible to directly include the traits defaults for the other JSON libraries. See the [traits examples](https://github.com/Thalhammer/jwt-cpp/tree/master/example/traits) for details.
84+
85+
As for the base64 requirements of JWTs, this library provides `base.h` with all the required implementation; However base64 implementations are very common, with varying degrees of performance. When providing your own base64 implementation, you can define `JWT_DISABLE_BASE64` to remove the jwt-cpp implementation.
86+
87+
### Getting Started
88+
89+
Simple example of decoding a token and printing all [claims](https://tools.ietf.org/html/rfc7519#section-4) ([try it out](https://github.com/Thalhammer/jwt-cpp/tree/master/example/print-claims.cpp)):
90+
91+
```cpp
92+
#include <jwt-cpp/jwt.h>
93+
#include <iostream>
94+
95+
int main() {
96+
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
97+
auto decoded = jwt::decode(token);
98+
99+
for(auto& e : decoded.get_payload_json())
100+
std::cout << e.first << " = " << e.second << std::endl;
101+
}
102+
```
103+
104+
In order to verify a token you first build a verifier and use it to verify a decoded token.
105+
106+
```cpp
107+
auto verifier = jwt::verify()
108+
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
109+
.with_issuer("auth0");
110+
111+
verifier.verify(decoded_token);
112+
```
113+
114+
The created verifier is stateless so you can reuse it for different tokens.
115+
116+
Creating a token (and signing) is equally as easy.
117+
118+
```cpp
119+
auto token = jwt::create()
120+
.set_issuer("auth0")
121+
.set_type("JWS")
122+
.set_payload_claim("sample", jwt::claim(std::string("test")))
123+
.sign(jwt::algorithm::hs256{"secret"});
124+
```
125+
126+
> To see more examples working with RSA public and private keys, visit our [examples](https://github.com/Thalhammer/jwt-cpp/tree/master/example)!
127+
128+
### Providing your own JSON Traits
129+
130+
To learn how to writes a trait's implementation, checkout the [these instructions](docs/traits.md)
131+
132+
## Contributing
133+
134+
If you have an improvement or found a bug feel free to [open an issue](https://github.com/Thalhammer/jwt-cpp/issues/new) or add the change and create a pull request. If you file a bug please make sure to include as much information about your environment (compiler version, etc.) as possible to help reproduce the issue. If you add a new feature please make sure to also include test cases for it.
135+
136+
## Dependencies
137+
138+
In order to use jwt-cpp you need the following tools.
139+
140+
* libcrypto (openssl or compatible)
141+
* libssl-dev (for the header files)
142+
* a compiler supporting at least c++11
143+
* basic stl support
144+
145+
In order to build the test cases you also need
146+
147+
* gtest
148+
* pthread
149+
150+
## Troubleshooting
151+
152+
See the [FAQs](docs/faqs.md) for tips.
153+
154+
## Conference Coverage
155+
[![CppCon](https://img.youtube.com/vi/Oq4NW5idmiI/0.jpg)](https://www.youtube.com/watch?v=Oq4NW5idmiI)

0 commit comments

Comments
 (0)