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-05-06 21:40:24 +00:00
|
|
|
#if defined(ESP_PLATFORM)
|
|
|
|
#include <mbedtls/md.h>
|
|
|
|
#else
|
|
|
|
#include <bearssl/bearssl_hmac.h>
|
|
|
|
#endif
|
|
|
|
|
2019-05-06 14:50:19 +00:00
|
|
|
#define JWT_HEADER_SIZE 36
|
|
|
|
#define JWT_SIG_SIZE 43
|
|
|
|
|
|
|
|
class ArduinoJsonJWT {
|
|
|
|
|
|
|
|
private:
|
|
|
|
String _secret;
|
|
|
|
|
|
|
|
// {"alg": "HS256", "typ": "JWT"}
|
|
|
|
const String JWT_HEADER = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9";
|
|
|
|
|
|
|
|
String sign(String &value);
|
2019-05-11 14:11:11 +00:00
|
|
|
|
|
|
|
static String encode(String value);
|
|
|
|
static String decode(String value);
|
2019-05-06 14:50:19 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
ArduinoJsonJWT(String secret);
|
|
|
|
|
|
|
|
void setSecret(String secret);
|
|
|
|
String buildJWT(JsonObject &payload);
|
|
|
|
void parseJWT(String jwt, JsonDocument &jsonDocument);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|