14 #ifndef JWT_AUTHENTICATOR_H
15 #define JWT_AUTHENTICATOR_H
39 void init(
const std::string &secret,
int expirySeconds);
47 std::string
generateJWT(
const std::string &userId,
const std::string &userName)
const;
55 bool validateJWT(
const std::string &token,
bool validateExpiry =
false)
const;
65 bool decodeJWT(
const std::string &token, std::string &header, std::string &payload, std::string &signature)
const;
88 bool verifyJWTSignature(
const std::string &encoded_header,
const std::string &encoded_payload,
const std::string &signature)
const;
118 bool base64urlDecode(
const std::string &input, std::string &output)
const;
133 std::string
bytesToBase64url(
const unsigned char *data,
size_t length)
const;
140 std::string
hmacSHA256(
const std::string &message)
const;
JWT JwtAuthenticator for embedded applications.
bool validateJWT(const std::string &token, bool validateExpiry=false) const
Validate a JWT's signature and optionally its expiration.
std::string base64urlEncode(const std::string &input) const
Encode a string using base64url encoding.
std::string hmacSHA256(const std::string &message) const
Calculate HMAC-SHA256 for a given message.
bool isJWTPayloadExpired(const std::string &payload) const
Check if a decoded JWT payload is expired.
bool verifyJWTSignature(const std::string &encoded_header, const std::string &encoded_payload, const std::string &signature) const
Verify a JWT's signature using HMAC-SHA256.
std::string bytesToBase64url(const unsigned char *data, size_t length) const
Convert a byte buffer to a base64url string.
std::string generateJWT(const std::string &userId, const std::string &userName) const
Generate a JWT for a given user.
bool isJWTExpired(const std::string &token) const
Check if a JWT is expired based on the exp claim.
bool decodeJWT(const std::string &token, std::string &header, std::string &payload, std::string &signature) const
Decode a JWT into its components.
void init(const std::string &secret, int expirySeconds)
Initialize the JwtAuthenticator with a secret key and expiry time.
bool base64urlDecode(const std::string &input, std::string &output) const
Decode a base64url-encoded string.
JwtAuthenticator()
Get an instance of the JwtAuthenticator.
bool isBase64urlEncoded(const std::string &str) const
Check if a string is valid base64url.
std::string secretKey
Construct a new JwtAuthenticator object.