Class jwt_object
Defined in File jwt.hpp
Class Documentation
-
class jwt_object
The main class representing the JWT object. It is a composition of all JWT composition classes.
Note
: This class does not provide all the required APIs in its public interface. Instead the class provides
header()andpayload()APIs. Those can be used to access more public APIs specific to those components.Public Functions
-
jwt_object() = default
Default constructor.
-
template<typename First, typename ...Rest, typename = std::enable_if_t<detail::meta::is_parameter_concept<First>::value>>
jwt_object(First &&first, Rest&&... rest) Takes a variadic set of parameters. Each type must satisfy the
ParameterConceptconcept.The parameters that can be passed:
payload : Can pass a initializer list of pairs or any associative containers which models
MappingConcept(seemeta::is_mapping_concept) to populate claims. Useadd_claimfor more controlled additions.secret : The secret to be used for generating and verification of JWT signature. Not required for NONE algorithm.
algorithm : The algorithm to be used for signing and decoding.
headers : Can pass a initializer list of pairs or any associative containers which models
MappingConcept(seemeta::is_mapping_concept) to populate header. Not much useful unless JWE is supported.
-
inline jwt_payload &payload() noexcept
Returns the payload component object by reference.
-
inline const jwt_payload &payload() const noexcept
Returns the payload component object by const-reference.
-
inline void payload(const jwt_payload &p)
Sets the payload component object.
-
inline void payload(jwt_payload &&p)
Sets the payload component object. Takes the payload object as rvalue-reference.
-
inline void header(const jwt_header &h)
Sets the header component object.
-
inline void header(jwt_header &&h)
Sets the header component object. Takes the header object as rvalue-reference.
-
inline jwt_header &header() noexcept
Get the header component object as reference.
-
inline const jwt_header &header() const noexcept
Get the header component object as const-reference.
-
inline std::string secret() const
Get the secret to be used for signing.
-
inline void secret(const jwt::string_view sv)
Set the secret to be used for signing.
-
template<typename T, typename = typename std::enable_if_t<!std::is_same<system_time_t, std::decay_t<T>>::value>>
inline jwt_object &add_claim(const jwt::string_view name, T &&value) Provides the glue interface for adding claim.
Note
: See
jwt_payload::add_claimfor more details.
-
inline jwt_object &add_claim(const jwt::string_view name, system_time_t time_point)
Provides the glue interface for adding claim.
Specialization for time points. Eg: Users can set
expclaim tochrono::system_clock::now().Note
: See
jwt_payload::add_claimfor more details.
- template<typename T> inline jwt_object & add_claim (SCOPED_ENUM registered_claims cname, T &&value)
Provides the glue interface for adding claim. Overload for taking claim name as
registered_claimsinstance.Note
: See
jwt_payload::add_claimfor more details.
-
inline jwt_object &remove_claim(const jwt::string_view name)
Provides the glue interface for removing claim.
Note
: See
jwt_payload::remove_claimfor more details.
- inline jwt_object & remove_claim (SCOPED_ENUM registered_claims cname)
Provides the glue interface for removing claim.
Note
: See
jwt_payload::remove_claimfor more details.
-
inline bool has_claim(const jwt::string_view cname) const noexcept
Provides the glue interface for checking if a claim is present or not.
Note
: See
jwt_payload::has_claimfor more details.
- inline bool has_claim (SCOPED_ENUM registered_claims cname) const noexcept
Provides the glue interface for checking if a claim is present or not.
Note
: See
jwt_payload::has_claimfor more details.
-
inline std::string signature(std::error_code &ec) const
Generate the JWS for the header + payload using the secret. This version takes the error_code for reporting errors.
Note
: The API would still throw for memory allocation exceptions (
std::bad_allocorjwt::MemoryAllocationException) or exceptions thrown by user types.
-
inline std::string signature() const
Generate the JWS for the header + payload using the secret. Exception throwing version.
-
template<typename Params, typename SequenceT>
std::error_code verify(const Params &dparams, const params::detail::algorithms_param<SequenceT> &algos) const Verify the signature. TODO: Returns an error_code instead of taking by reference.
-
template<typename Map, typename ...Rest>
void set_parameters(params::detail::payload_param<Map> &&payload, Rest&&... rargs)
-
template<typename ...Rest>
void set_parameters(params::detail::secret_param secret, Rest&&... rargs)
-
template<typename ...Rest>
void set_parameters(params::detail::algorithm_param alg, Rest&&... rargs)
-
template<typename Map, typename ...Rest>
void set_parameters(params::detail::headers_param<Map> &&header, Rest&&... rargs)
Public Static Functions
-
static inline std::array<jwt::string_view, 3> three_parts(const jwt::string_view enc_str)
Splitsa JWT string into its three parts using dot(‘.’) as the delimiter.
Note
: Instead of actually splitting the API simply provides an array of view.
-
template<typename DecodeParams, typename ...Rest>
static void set_decode_params(DecodeParams &dparams, params::detail::secret_param s, Rest&&... args) Decode parameters.
-
template<typename DecodeParams, typename T, typename ...Rest>
static void set_decode_params(DecodeParams &dparams, params::detail::secret_function_param<T> &&s, Rest&&... args)
-
template<typename DecodeParams, typename ...Rest>
static void set_decode_params(DecodeParams &dparams, params::detail::leeway_param l, Rest&&... args)
-
template<typename DecodeParams, typename ...Rest>
static void set_decode_params(DecodeParams &dparams, params::detail::verify_param v, Rest&&... args)
-
template<typename DecodeParams, typename ...Rest>
static void set_decode_params(DecodeParams &dparams, params::detail::issuer_param i, Rest&&... args)
-
template<typename DecodeParams, typename ...Rest>
static void set_decode_params(DecodeParams &dparams, params::detail::audience_param a, Rest&&... args)
-
template<typename DecodeParams, typename ...Rest>
static void set_decode_params(DecodeParams &dparams, params::detail::subject_param a, Rest&&... args)
-
template<typename DecodeParams, typename ...Rest>
static void set_decode_params(DecodeParams &dparams, params::detail::validate_iat_param v, Rest&&... args)
-
template<typename DecodeParams, typename ...Rest>
static void set_decode_params(DecodeParams &dparams, params::detail::validate_jti_param v, Rest&&... args)
-
template<typename DecodeParams>
static void set_decode_params(DecodeParams &dparams)
-
jwt_object() = default