|
#include <JWT.h>
Public Types | |
| enum class | Algorithm : uint8_t { NONE = 0 , HS256 , HS384 , HS512 , RS256 , RS384 , RS512 , ES256 , ES384 , ES512 , INVAL } |
Public Member Functions | |
| JWT ()=default | |
| const Variant & | get (const String &name) const |
| void | set (const String &name, const Variant &data) const |
| Algorithm | get_alg () const |
| void | set_alg (Algorithm _alg, const String &_key) |
| void | sign (Buffer &token, const char *str) const |
| void | encode (std::ostream &out) const |
| void | decode (const char *token, const String &_key="") |
| void | exportTo (std::ostream &output, bool pretty) const |
| void | write_head (std::ostream &output, bool pretty) const |
| void | write_body (std::ostream &output, bool pretty) const |
| void | verify (const Buffer &head, const Buffer &sig) const |
| void | sign_sha_hmac (Buffer &out, const char *str) const |
| void | verify_sha_hmac (const char *head, const char *sig) const |
| void | sign_sha_pem (Buffer &out, const char *str) const |
| void | verify_sha_pem (const char *head, const char *sig_b64) const |
Static Public Member Functions | |
| static const char * | alg_str (Algorithm _alg) |
| static Algorithm | str_alg (const char *alg) |
| static String | get_js_string (const xdoc::SNode &node, const String &key, bool *found=nullptr) |
| static long | get_js_int (const xdoc::SNode &node, const String &key, bool *found=nullptr) |
| static bool | get_js_bool (const xdoc::SNode &node, const String &key, bool *found=nullptr) |
Public Attributes | |
| Algorithm | alg {Algorithm::NONE} |
| Signature encryption algorithm. | |
| String | key |
| Signature encryption key. | |
| xdoc::Document | grants |
| Token content. | |
Java Web Token encoding and decoding
|
strong |
JWT algorithm types.
|
default |
Constructor
|
static |
Get signature encryption algorithm name
| _alg | Signature encryption algorithm |
| void sptk::JWT::decode | ( | const char * | token, |
| const String & | _key = "" |
||
| ) |
Decode token
| token | Input token data |
| _key | Optional signature encryption key |
| void sptk::JWT::encode | ( | std::ostream & | out | ) | const |
Encode token to stream
| out | Output stream |
| void sptk::JWT::exportTo | ( | std::ostream & | output, |
| bool | pretty | ||
| ) | const |
Export token to stream
| output | Output stream |
| pretty | If true, produce formatted output |
Get JSON element in JSON object element by name. If element doesn't exist in JSON object yet, it's created as JSON null element. If this element is not JSON object, an exception is thrown.
| name | Name of the element in the object element |
|
static |
Find boolean grant value by name
| node | Parent JSON element |
| key | Grant name |
| found | Optional (output) flag, true is found |
|
static |
Find integer grant value by name
| node | Parent JSON element |
| key | Grant name |
| found | Optional (output) flag, true is found |
|
static |
Find string grant value by name
| node | Parent JSON element |
| key | Grant name |
| found | Optional (output) flag, true is found |
Set JSON element in JSON object element by name. If element doesn't exist in JSON object yet, it's created as JSON null element. If this element is not JSON object, an exception is thrown.
| name | Name of the element in the object element |
Set signature encryption algorithm
| _alg | Signature encryption algorithm |
| _key | Signature encryption key |
| void sptk::JWT::sign | ( | Buffer & | token, |
| const char * | str | ||
| ) | const |
Sign token
| token | Output token data |
| str | Data to sign |
| void sptk::JWT::sign_sha_hmac | ( | Buffer & | out, |
| const char * | str | ||
| ) | const |
Sign using SHA algorithm to HMAC format
| out | Output data |
| str | Input data |
| void sptk::JWT::sign_sha_pem | ( | Buffer & | out, |
| const char * | str | ||
| ) | const |
Sign using SHA algorithm to PEM format
| out | Output data |
| str | Input data |
|
static |
Get signature encryption algorithm from name
| alg | Signature encryption algorithm name |
Verify token
| head | Token head |
| sig | Signature |
| void sptk::JWT::verify_sha_hmac | ( | const char * | head, |
| const char * | sig | ||
| ) | const |
Verify using SHA algorithm in HMAC format
| head | Token head |
| sig | Signature |
| void sptk::JWT::verify_sha_pem | ( | const char * | head, |
| const char * | sig_b64 | ||
| ) | const |
Verify using SHA algorithm in PEM format
| head | Token head |
| sig_b64 | Signature |
| void sptk::JWT::write_body | ( | std::ostream & | output, |
| bool | pretty | ||
| ) | const |
Write token body to output stream
| output | Output stream |
| pretty | If true then produce formatted output |
| void sptk::JWT::write_head | ( | std::ostream & | output, |
| bool | pretty | ||
| ) | const |
Write token head to output stream
| output | Output stream |
| pretty | If true then produce formatted output |