10Duke Enterprise C++ Client
Loading...
Searching...
No Matches
tenduke::jwt::JWT Class Reference

#include <JWT.h>

Detailed Description

Very simple JWT implementation.

This will likely be heavily modified in the future.

Inheritance diagram for tenduke::jwt::JWT:
tenduke::oidc::IdToken

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 &copy)=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.
 

Constructor & Destructor Documentation

◆ JWT() [1/3]

tenduke::jwt::JWT::JWT ( std::map< std::string, std::string >  claims)
explicit

Constructs new JWT instance from given claims.

Parameters
claims-

◆ JWT() [2/3]

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.

Parameters
claims-
headerParameters-
mapClaims-
arrayClaims-

◆ JWT() [3/3]

tenduke::jwt::JWT::JWT ( const JWT copy)
default

Copy-constructs new JWT instance.

Parameters
copy-

Member Function Documentation

◆ claim()

const std::string * tenduke::jwt::JWT::claim ( const std::string &  name) const

Returns a JWT-claim by given name.

Parameters
namename of the claim
Returns
pointer to the claim, or nullptr if no such claim

◆ getArrayClaim()

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.

Parameters
name-
Returns
the claim. Returns empty map if no such claim is present.

◆ getAudience()

const std::string & tenduke::jwt::JWT::getAudience ( ) const

Returns "Audience", "aud"-claim.

Returns
"Audience" or empty string if not present

◆ getClaims()

const std::map< std::string, std::string > & tenduke::jwt::JWT::getClaims ( ) const
inline

Returns all claims as a map.

Returns
-

◆ getExpirationTime()

std::int64_t tenduke::jwt::JWT::getExpirationTime ( ) const

Returns "Expiration time", "exp"-claim.

Returns
"Expiration time" or NUMBER_NOT_PRESENT if not present.

◆ getHeaderParameterKID()

std::string tenduke::jwt::JWT::getHeaderParameterKID ( ) const

Returns header-parameter KeyId ("kid"-parameter).

Returns
"KeyId" or empty string if not present.

◆ getHeaderParameters()

std::map< std::string, std::string > tenduke::jwt::JWT::getHeaderParameters ( ) const

Returns header parameters.

Returns
-

◆ getIntClaim()

std::int64_t tenduke::jwt::JWT::getIntClaim ( const std::string &  claimName) const

Returns claim value as std::int64_t.

Parameters
claimName-
Returns
-

◆ getIssuedAt()

std::int64_t tenduke::jwt::JWT::getIssuedAt ( ) const

Returns "Issued at", "iat"-claim.

Returns
"Issued at" or NUMBER_NOT_PRESENT if not present.

◆ getIssuer()

const std::string & tenduke::jwt::JWT::getIssuer ( ) const

Returns "Issuer", "iss"-claim.

Returns
"Issuer" or empty string if not present

◆ getJWTID()

const std::string & tenduke::jwt::JWT::getJWTID ( ) const

Returns "JWT ID", "jti"-claim.

Returns
"JWT ID" or empty string if not present

◆ getMapClaim()

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.

Parameters
name-
Returns
the claim. Returns empty map if no such claim is present.

◆ getStringClaim()

const std::string & tenduke::jwt::JWT::getStringClaim ( const std::string &  claimName) const

Returns a claim value as string.

Parameters
claimNamename of the claim
Returns
-

◆ getSubject()

const std::string & tenduke::jwt::JWT::getSubject ( ) const

Returns "Subject", "sub"-claim.

Returns
"Subject" or empty string if not present

◆ hasClaim()

bool tenduke::jwt::JWT::hasClaim ( const std::string &  name) const

Checks if the JWT has given claim.

Parameters
namename of the claim
Returns
-

◆ isInfinite()

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.

Returns
-

Member Data Documentation

◆ arrayClaims

std::map<std::string, std::vector<std::string> > tenduke::jwt::JWT::arrayClaims
protected

Claims with values of arrays.

These are also contained in claims.

◆ mapClaims

std::map<std::string, std::map<std::string, std::string> > tenduke::jwt::JWT::mapClaims
protected

Claims with values of maps.

These are also contained in claims.


The documentation for this class was generated from the following files: