JWT-CPP v0.7.0
A header only library for creating and validating JSON Web Tokens (JWT) in C++
Loading...
Searching...
No Matches
jwt Namespace Reference

JSON Web Token. More...

Namespaces

namespace  algorithm
 Various cryptographic algorithms when working with JWT.
 
namespace  alphabet
 character maps when encoding and decoding
 
namespace  base
 A collection of fellable functions for working with base64 and base64url.
 
namespace  error
 Everything related to error codes issued by the library.
 
namespace  helper
 A collection for working with certificates.
 
namespace  json
 JSON Abstractions for working with any library.
 
namespace  traits
 Namespace containing all the json_trait implementations for a jwt::basic_claim.
 

Classes

class  basic_claim
 a class to store a generic JSON value as claim More...
 
class  builder
 
class  decoded_jwt
 
struct  default_clock
 
class  header
 
class  jwk
 JSON Web Key. More...
 
class  jwks
 JWK Set. More...
 
class  payload
 
class  verifier
 

Typedefs

using date = std::chrono::system_clock::time_point
 
using claim = basic_claim<traits::boost_json>
 a class to store a generic Boost.JSON value as claim
 
using verify_context = verify_ops::verify_context<traits::boost_json>
 

Functions

template<typename Clock , typename json_traits >
verifier< Clock, json_traits > verify (Clock c)
 
template<typename Clock , typename json_traits >
builder< Clock, json_traits > create (Clock c)
 
template<typename json_traits >
verifier< default_clock, json_traits > verify (default_clock c={})
 
template<typename json_traits >
builder< default_clock, json_traits > create (default_clock c={})
 
template<typename json_traits , typename Decode >
decoded_jwt< json_traits > decode (const typename json_traits::string_type &token, Decode decode)
 Decode a token. This can be used to to help access important feild like 'x5c' for verifying tokens. See associated example rsa-verify.cpp for more details.
 
template<typename json_traits >
decoded_jwt< json_traits > decode (const typename json_traits::string_type &token)
 
template<typename json_traits >
jwk< json_traits > parse_jwk (const typename json_traits::string_type &jwk_)
 
template<typename json_traits >
jwks< json_traits > parse_jwks (const typename json_traits::string_type &jwks_)
 
verifier< default_clock, traits::boost_jsonverify ()
 
builder< default_clock, traits::boost_jsoncreate ()
 
decoded_jwt< traits::boost_jsondecode (const std::string &token)
 
template<typename Decode >
decoded_jwt< traits::boost_jsondecode (const std::string &token, Decode decode)
 
jwk< traits::boost_jsonparse_jwk (const traits::boost_json::string_type &token)
 
jwks< traits::boost_jsonparse_jwks (const traits::boost_json::string_type &token)
 
template<typename Decode >
decoded_jwt< traits::danielaparker_jsonconsdecode (const std::string &token, Decode decode)
 
template<typename Decode >
decoded_jwt< traits::kazuho_picojsondecode (const std::string &token, Decode decode)
 
template<typename Decode >
decoded_jwt< traits::nlohmann_jsondecode (const std::string &token, Decode decode)
 
template<typename Decode >
decoded_jwt< traits::open_source_parsers_jsoncppdecode (const std::string &token, Decode decode)
 

Detailed Description

JSON Web Token.

A namespace to contain everything related to handling JSON Web Tokens, JWT for short, as a part of RFC7519, or alternatively for JWS (JSON Web Signature) from RFC7515

Typedef Documentation

◆ claim

a class to store a generic Boost.JSON value as claim

a class to store a generic jsoncpp value as claim

a class to store a generic JSON for Modern C++ value as claim

a class to store a generic picojson value as claim

a class to store a generic jsoncons value as claim

This type is the specialization of the basic_claim class which uses the standard template types.

◆ date

using jwt::date = std::chrono::system_clock::time_point

Default system time point in UTC

◆ verify_context

This type is the specialization of the verify_ops::verify_context class which uses the standard template types.

Function Documentation

◆ create() [1/3]

Create a builder using the default clock

Returns
builder instance to create a new token

◆ create() [2/3]

template<typename Clock , typename json_traits >
builder< Clock, json_traits > jwt::create ( Clock c)

Create a builder using the given clock

Parameters
cClock instance to use
Returns
builder instance

◆ create() [3/3]

template<typename json_traits >
builder< default_clock, json_traits > jwt::create ( default_clock c = {})

Return a builder instance to create a new token

◆ decode() [1/8]

decoded_jwt< traits::open_source_parsers_jsoncpp > jwt::decode ( const std::string & token)
inline

Decode a token

Parameters
tokenToken to decode
Returns
Decoded token
Exceptions
std::invalid_argumentToken is not in correct format
std::runtime_errorBase64 decoding failed or invalid json

◆ decode() [2/8]

template<typename Decode >
decoded_jwt< traits::boost_json > jwt::decode ( const std::string & token,
Decode decode )

Decode a token

Template Parameters
Decodeis callable, taking a string_type and returns a string_type. It should ensure the padding of the input and then base64url decode and return the results.
Parameters
tokenToken to decode
decodeThe token to parse
Returns
Decoded token
Exceptions
std::invalid_argumentToken is not in correct format
std::runtime_errorBase64 decoding failed or invalid json

◆ decode() [3/8]

template<typename Decode >
decoded_jwt< traits::danielaparker_jsoncons > jwt::decode ( const std::string & token,
Decode decode )

Decode a token

Template Parameters
Decodeis callable, taking a string_type and returns a string_type. It should ensure the padding of the input and then base64url decode and return the results.
Parameters
tokenToken to decode
decodeThe token to parse
Returns
Decoded token
Exceptions
std::invalid_argumentToken is not in correct format
std::runtime_errorBase64 decoding failed or invalid json

◆ decode() [4/8]

template<typename Decode >
decoded_jwt< traits::kazuho_picojson > jwt::decode ( const std::string & token,
Decode decode )

Decode a token

Template Parameters
Decodeis callable, taking a string_type and returns a string_type. It should ensure the padding of the input and then base64url decode and return the results.
Parameters
tokenToken to decode
decodeThe token to parse
Returns
Decoded token
Exceptions
std::invalid_argumentToken is not in correct format
std::runtime_errorBase64 decoding failed or invalid json

◆ decode() [5/8]

template<typename Decode >
decoded_jwt< traits::nlohmann_json > jwt::decode ( const std::string & token,
Decode decode )

Decode a token

Template Parameters
Decodeis callable, taking a string_type and returns a string_type. It should ensure the padding of the input and then base64url decode and return the results.
Parameters
tokenToken to decode
decodeThe token to parse
Returns
Decoded token
Exceptions
std::invalid_argumentToken is not in correct format
std::runtime_errorBase64 decoding failed or invalid json

◆ decode() [6/8]

template<typename Decode >
decoded_jwt< traits::open_source_parsers_jsoncpp > jwt::decode ( const std::string & token,
Decode decode )

Decode a token

Template Parameters
Decodeis callable, taking a string_type and returns a string_type. It should ensure the padding of the input and then base64url decode and return the results.
Parameters
tokenToken to decode
decodeThe token to parse
Returns
Decoded token
Exceptions
std::invalid_argumentToken is not in correct format
std::runtime_errorBase64 decoding failed or invalid json

◆ decode() [7/8]

template<typename json_traits >
decoded_jwt< json_traits > jwt::decode ( const typename json_traits::string_type & token)

Decode a token. This can be used to to help access important feild like 'x5c' for verifying tokens. See associated example rsa-verify.cpp for more details.

Template Parameters
json_traitsJSON implementation traits
Parameters
tokenToken to decode
Returns
Decoded token
Exceptions
std::invalid_argumentToken is not in correct format
std::runtime_errorBase64 decoding failed or invalid json

◆ decode() [8/8]

template<typename json_traits , typename Decode >
decoded_jwt< json_traits > jwt::decode ( const typename json_traits::string_type & token,
Decode decode )

Decode a token. This can be used to to help access important feild like 'x5c' for verifying tokens. See associated example rsa-verify.cpp for more details.

Template Parameters
json_traitsJSON implementation traits
Decodeis callable, taking a string_type and returns a string_type. It should ensure the padding of the input and then base64url decode and return the results.
Parameters
tokenToken to decode
decodefunction that will pad and base64url decode the token
Returns
Decoded token
Exceptions
std::invalid_argumentToken is not in correct format
std::runtime_errorBase64 decoding failed or invalid json

◆ parse_jwk() [1/2]

jwk< traits::open_source_parsers_jsoncpp > jwt::parse_jwk ( const traits::boost_json::string_type & token)
inline

Parse a jwk

Parameters
tokenJWK Token to parse
Returns
Parsed JWK
Exceptions
std::runtime_errorToken is not in correct format

◆ parse_jwk() [2/2]

template<typename json_traits >
jwk< json_traits > jwt::parse_jwk ( const typename json_traits::string_type & jwk_)

Parse a single JSON Web Key

Template Parameters
json_traitsJSON implementation traits
Parameters
jwk_string buffer containing the JSON object
Returns
Decoded jwk

◆ parse_jwks() [1/2]

jwks< traits::open_source_parsers_jsoncpp > jwt::parse_jwks ( const traits::boost_json::string_type & token)
inline

Parse a jwks

Parameters
tokenJWKs Token to parse
Returns
Parsed JWKs
Exceptions
std::runtime_errorToken is not in correct format

◆ parse_jwks() [2/2]

template<typename json_traits >
jwks< json_traits > jwt::parse_jwks ( const typename json_traits::string_type & jwks_)

Parse a JSON Web Key Set. This can be used to to help access important feild like 'x5c' for verifying tokens. See example jwks-verify.cpp for more information.

Template Parameters
json_traitsJSON implementation traits
Parameters
jwks_string buffer containing the JSON object
Returns
Parsed JSON object containing the data of the JWK SET string
Exceptions
std::runtime_errorToken is not in correct format

◆ verify() [1/3]

Create a verifier using the default clock

Returns
verifier instance

◆ verify() [2/3]

template<typename Clock , typename json_traits >
verifier< Clock, json_traits > jwt::verify ( Clock c)

Create a verifier using the given clock

Parameters
cClock instance to use
Returns
verifier instance

◆ verify() [3/3]

template<typename json_traits >
verifier< default_clock, json_traits > jwt::verify ( default_clock c = {})

Create a verifier using the default_clock.

Parameters
cClock instance to use
Returns
verifier instance