Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
756 B

  1. #ifndef ArduinoJsonJWT_H
  2. #define ArduinoJsonJWT_H
  3. #include <Arduino.h>
  4. #include <ArduinoJson.h>
  5. #include <libb64/cdecode.h>
  6. #include <libb64/cencode.h>
  7. #ifdef ESP32
  8. #include <mbedtls/md.h>
  9. #elif defined(ESP8266)
  10. #include <bearssl/bearssl_hmac.h>
  11. #endif
  12. class ArduinoJsonJWT {
  13. private:
  14. String _secret;
  15. const String JWT_HEADER = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9";
  16. const int JWT_HEADER_SIZE = JWT_HEADER.length();
  17. String sign(String& value);
  18. static String encode(const char* cstr, int len);
  19. static String decode(String value);
  20. public:
  21. ArduinoJsonJWT(String secret);
  22. void setSecret(String secret);
  23. String getSecret();
  24. String buildJWT(JsonObject& payload);
  25. void parseJWT(String jwt, JsonDocument& jsonDocument);
  26. };
  27. #endif