2019-05-06 14:50:19 +00:00
|
|
|
#ifndef ArduinoJsonJWT_H
|
|
|
|
#define ArduinoJsonJWT_H
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <ArduinoJson.h>
|
2019-05-11 14:11:11 +00:00
|
|
|
#include <libb64/cdecode.h>
|
|
|
|
#include <libb64/cencode.h>
|
2019-12-24 11:19:19 +00:00
|
|
|
|
|
|
|
#ifdef ESP32
|
2019-12-03 23:16:06 +00:00
|
|
|
#include <mbedtls/md.h>
|
2019-12-24 11:19:19 +00:00
|
|
|
#elif defined(ESP8266)
|
2019-12-03 23:16:06 +00:00
|
|
|
#include <bearssl/bearssl_hmac.h>
|
|
|
|
#endif
|
2019-05-06 21:40:24 +00:00
|
|
|
|
2019-05-06 14:50:19 +00:00
|
|
|
class ArduinoJsonJWT {
|
2019-12-03 23:16:06 +00:00
|
|
|
private:
|
2019-05-06 14:50:19 +00:00
|
|
|
String _secret;
|
|
|
|
|
|
|
|
const String JWT_HEADER = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9";
|
2019-06-04 19:05:43 +00:00
|
|
|
const int JWT_HEADER_SIZE = JWT_HEADER.length();
|
2019-06-03 20:05:02 +00:00
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
String sign(String& value);
|
2019-05-11 14:11:11 +00:00
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
static String encode(const char* cstr, int len);
|
2019-05-11 14:11:11 +00:00
|
|
|
static String decode(String value);
|
2019-05-06 14:50:19 +00:00
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
public:
|
2019-05-06 14:50:19 +00:00
|
|
|
ArduinoJsonJWT(String secret);
|
|
|
|
|
|
|
|
void setSecret(String secret);
|
2019-05-29 22:48:16 +00:00
|
|
|
String getSecret();
|
2019-05-06 14:50:19 +00:00
|
|
|
|
2019-12-03 23:16:06 +00:00
|
|
|
String buildJWT(JsonObject& payload);
|
|
|
|
void parseJWT(String jwt, JsonDocument& jsonDocument);
|
|
|
|
};
|
2019-05-06 14:50:19 +00:00
|
|
|
|
|
|
|
#endif
|