| 3 | #include <jwt-cpp/jwt.h> |
| 4 | |
| 5 | int main() { |
| 6 | const std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY----- |
| 7 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGbXWiK3dQTyCbX5xdE4 |
| 8 | yCuYp0AF2d15Qq1JSXT/lx8CEcXb9RbDddl8jGDv+spi5qPa8qEHiK7FwV2KpRE9 |
| 9 | 83wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVs |
| 10 | WXI9C+yjHztqyL2h8P6mlThPY9E9ue2fCqdgixfTFIF9Dm4SLHbphUS2iw7w1JgT |
| 11 | 69s7of9+I9l5lsJ9cozf1rxrXX4V1u/SotUuNB3Fp8oB4C1fLBEhSlMcUJirz1E8 |
| 12 | AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0 |
| 13 | YwIDAQAB |
| 14 | -----END PUBLIC KEY-----)"; |
| 15 | |
| 16 | const std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9." |
| 17 | "VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8" |
| 18 | "HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-" |
| 19 | "GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4" |
| 20 | "YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-" |
| 21 | "IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9" |
| 22 | "sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-" |
| 23 | "uc2z5c05CCXqVSpfCjWbh9gQ"; |
| 24 | |
| 25 | /* [allow rsa algorithm] */ |
| 26 | auto verify = jwt::verify() |
| 27 | // We only need an RSA public key to verify tokens |
| 28 | .allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, "", "", "")) |
| 29 | // We expect token to come from a known authorization server |
| 30 | .with_issuer("auth0"); |
| 31 | /* [allow rsa algorithm] */ |
| 32 | |
| 33 | auto decoded = jwt::decode(token); |
| 34 | |
| 35 | verify.verify(decoded); |
| 36 | |
| 37 | for (auto& e : decoded.get_header_json()) |
| 38 | std::cout << e.first << " = " << e.second << '\n'; |
| 39 | for (auto& e : decoded.get_payload_json()) |
| 40 | std::cout << e.first << " = " << e.second << '\n'; |
| 41 | } |
nothing calls this directly
no test coverage detected