10Duke Enterprise C++ Client
|
#include <JWT.h>
Very simple JWT implementation.
This will likely be heavily modified in the future.
Public Member Functions | |
JWT (std::map< std::string, std::string > claims) | |
Constructs new JWT instance from given claims. | |
JWT (const std::map< std::string, std::string > &claims, const std::map< std::string, std::string > &headerParameters, const std::map< std::string, std::map< std::string, std::string > > &mapClaims={}, const std::map< std::string, std::vector< std::string > > &arrayClaims={}) | |
Constructs new JWT instance from given claims and header parameters. | |
JWT (const JWT ©)=default | |
Copy-constructs new JWT instance. | |
bool | hasClaim (const std::string &name) const |
Checks if the JWT has given claim. | |
const std::string * | claim (const std::string &name) const |
Returns a JWT-claim by given name. | |
const std::map< std::string, std::string > & | getClaims () const |
Returns all claims as a map. | |
const std::string & | getStringClaim (const std::string &claimName) const |
Returns a claim value as string. | |
std::int64_t | getIntClaim (const std::string &claimName) const |
Returns claim value as std::int64_t . | |
const std::string & | getJWTID () const |
Returns "JWT ID", "jti"-claim. | |
const std::string & | getIssuer () const |
Returns "Issuer", "iss"-claim. | |
const std::string & | getSubject () const |
Returns "Subject", "sub"-claim. | |
const std::string & | getAudience () const |
Returns "Audience", "aud"-claim. | |
std::int64_t | getExpirationTime () const |
Returns "Expiration time", "exp"-claim. | |
std::int64_t | getIssuedAt () const |
Returns "Issued at", "iat"-claim. | |
std::string | getHeaderParameterKID () const |
Returns header-parameter KeyId ("kid"-parameter). | |
std::map< std::string, std::string > | getHeaderParameters () const |
Returns header parameters. | |
std::map< std::string, std::string > | getMapClaim (const std::string &name) const |
Returns a claim, which is a map. | |
std::vector< std::string > | getArrayClaim (const std::string &name) const |
Returns a claim, which is a JSON array, as vector of strings. | |
bool | isInfinite () const |
Returns true if token does expire. | |
Static Public Attributes | |
static const std::int64_t | NUMBER_NOT_PRESENT = INT64_MIN |
Magic value to indicate that numeric claim is not present. | |
Protected Attributes | |
std::map< std::string, std::string > | claims |
Claims. | |
std::map< std::string, std::string > | headerParameters |
Header parameters. | |
std::map< std::string, std::map< std::string, std::string > > | mapClaims |
Claims with values of maps. | |
std::map< std::string, std::vector< std::string > > | arrayClaims |
Claims with values of arrays. | |
|
explicit |
Constructs new JWT instance from given claims.
claims | - |
tenduke::jwt::JWT::JWT | ( | const std::map< std::string, std::string > & | claims, |
const std::map< std::string, std::string > & | headerParameters, | ||
const std::map< std::string, std::map< std::string, std::string > > & | mapClaims = {} , |
||
const std::map< std::string, std::vector< std::string > > & | arrayClaims = {} |
||
) |
Constructs new JWT instance from given claims and header parameters.
claims | - |
headerParameters | - |
mapClaims | - |
arrayClaims | - |
|
default |
Copy-constructs new JWT instance.
copy | - |
const std::string * tenduke::jwt::JWT::claim | ( | const std::string & | name | ) | const |
Returns a JWT-claim by given name.
name | name of the claim |
nullptr
if no such claim std::vector< std::string > tenduke::jwt::JWT::getArrayClaim | ( | const std::string & | name | ) | const |
Returns a claim, which is a JSON array, as vector of strings.
The vector returned uses string values: The JSON values are converted into their string representations. This does not recurse any further and if the data does, the user must parse the JSON from the value manually.
name | - |
const std::string & tenduke::jwt::JWT::getAudience | ( | ) | const |
Returns "Audience", "aud"-claim.
|
inline |
Returns all claims as a map.
std::int64_t tenduke::jwt::JWT::getExpirationTime | ( | ) | const |
Returns "Expiration time", "exp"-claim.
std::string tenduke::jwt::JWT::getHeaderParameterKID | ( | ) | const |
Returns header-parameter KeyId ("kid"-parameter).
std::map< std::string, std::string > tenduke::jwt::JWT::getHeaderParameters | ( | ) | const |
Returns header parameters.
std::int64_t tenduke::jwt::JWT::getIntClaim | ( | const std::string & | claimName | ) | const |
Returns claim value as std::int64_t
.
claimName | - |
std::int64_t tenduke::jwt::JWT::getIssuedAt | ( | ) | const |
Returns "Issued at", "iat"-claim.
const std::string & tenduke::jwt::JWT::getIssuer | ( | ) | const |
Returns "Issuer", "iss"-claim.
const std::string & tenduke::jwt::JWT::getJWTID | ( | ) | const |
Returns "JWT ID", "jti"-claim.
std::map< std::string, std::string > tenduke::jwt::JWT::getMapClaim | ( | const std::string & | name | ) | const |
Returns a claim, which is a map.
The map returned uses string as keys and values. If the data contains nested JSON objects or an array of JSON objects, the user must parse the JSON from the value manually.
name | - |
const std::string & tenduke::jwt::JWT::getStringClaim | ( | const std::string & | claimName | ) | const |
Returns a claim value as string.
claimName | name of the claim |
const std::string & tenduke::jwt::JWT::getSubject | ( | ) | const |
Returns "Subject", "sub"-claim.
bool tenduke::jwt::JWT::hasClaim | ( | const std::string & | name | ) | const |
bool tenduke::jwt::JWT::isInfinite | ( | ) | const |
Returns true
if token does expire.
This is based on "exp"-claim, returns true if the claim is missing.
|
protected |
Claims with values of arrays.
These are also contained in claims.
|
protected |
Claims with values of maps.
These are also contained in claims.