Goby3  3.1.5a
2024.05.23
jwt::verifier< Clock, json_traits > Class Template Reference

#include <goby/util/thirdparty/jwt-cpp/jwt.h>

Public Types

using basic_claim_t = basic_claim< json_traits >
 
using verify_check_fn_t = std::function< void(const verify_ops::verify_context< json_traits > &, std::error_code &ec)>
 

Public Member Functions

 verifier (Clock c)
 
verifierleeway (size_t leeway)
 
verifierexpires_at_leeway (size_t leeway)
 
verifiernot_before_leeway (size_t leeway)
 
verifierissued_at_leeway (size_t leeway)
 
verifierwith_type (const typename json_traits::string_type &type, std::locale locale=std::locale{})
 
verifierwith_issuer (const typename json_traits::string_type &iss)
 
verifierwith_subject (const typename json_traits::string_type &sub)
 
verifierwith_audience (const typename basic_claim_t::set_t &aud)
 
verifierwith_audience (const typename json_traits::string_type &aud)
 
verifierwith_id (const typename json_traits::string_type &id)
 
verifierwith_claim (const typename json_traits::string_type &name, verify_check_fn_t fn)
 
verifierwith_claim (const typename json_traits::string_type &name, basic_claim_t c)
 
template<typename Algorithm >
verifierallow_algorithm (Algorithm alg)
 
void verify (const decoded_jwt< json_traits > &jwt) const
 
void verify (const decoded_jwt< json_traits > &jwt, std::error_code &ec) const
 

Detailed Description

template<typename Clock, typename json_traits>
class jwt::verifier< Clock, json_traits >

Verifier class used to check if a decoded token contains all claims required by your application and has a valid signature.

Definition at line 3562 of file jwt.h.

Member Typedef Documentation

◆ basic_claim_t

template<typename Clock , typename json_traits >
using jwt::verifier< Clock, json_traits >::basic_claim_t = basic_claim<json_traits>

Definition at line 3565 of file jwt.h.

◆ verify_check_fn_t

template<typename Clock , typename json_traits >
using jwt::verifier< Clock, json_traits >::verify_check_fn_t = std::function<void(const verify_ops::verify_context<json_traits>&, std::error_code& ec)>

Verification function

This gets passed the current verifier, a reference to the decoded jwt, a reference to the key of this claim, as well as a reference to an error_code. The function checks if the actual value matches certain rules (e.g. equality to value x) and sets the error_code if it does not. Once a non zero error_code is encountered the verification stops and this error_code becomes the result returned from verify

Definition at line 3576 of file jwt.h.

Constructor & Destructor Documentation

◆ verifier()

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

Constructor for building a new verifier instance

Parameters
cClock instance

Definition at line 3608 of file jwt.h.

Member Function Documentation

◆ allow_algorithm()

template<typename Clock , typename json_traits >
template<typename Algorithm >
verifier& jwt::verifier< Clock, json_traits >::allow_algorithm ( Algorithm  alg)
inline

Add an algorithm available for checking.

Parameters
algAlgorithm to allow
Returns
*this to allow chaining

Definition at line 3787 of file jwt.h.

◆ expires_at_leeway()

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::expires_at_leeway ( size_t  leeway)
inline

Set leeway for expires at. If not specified the default leeway will be used.

Parameters
leewaySet leeway to use for expires at.
Returns
*this to allow chaining

Definition at line 3658 of file jwt.h.

◆ issued_at_leeway()

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::issued_at_leeway ( size_t  leeway)
inline

Set leeway for issued at. If not specified the default leeway will be used.

Parameters
leewaySet leeway to use for issued at.
Returns
*this to allow chaining

Definition at line 3680 of file jwt.h.

◆ leeway()

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::leeway ( size_t  leeway)
inline

Set default leeway to use.

Parameters
leewayDefault leeway to use if not specified otherwise
Returns
*this to allow chaining

Definition at line 3647 of file jwt.h.

◆ not_before_leeway()

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::not_before_leeway ( size_t  leeway)
inline

Set leeway for not before. If not specified the default leeway will be used.

Parameters
leewaySet leeway to use for not before.
Returns
*this to allow chaining

Definition at line 3669 of file jwt.h.

◆ verify() [1/2]

template<typename Clock , typename json_traits >
void jwt::verifier< Clock, json_traits >::verify ( const decoded_jwt< json_traits > &  jwt) const
inline

Verify the given token.

Parameters
jwtToken to check
Exceptions
token_verification_exceptionVerification failed

Definition at line 3798 of file jwt.h.

◆ verify() [2/2]

template<typename Clock , typename json_traits >
void jwt::verifier< Clock, json_traits >::verify ( const decoded_jwt< json_traits > &  jwt,
std::error_code &  ec 
) const
inline

Verify the given token.

Parameters
jwtToken to check
ecerror_code filled with details on error

Definition at line 3809 of file jwt.h.

◆ with_audience() [1/2]

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::with_audience ( const typename basic_claim_t::set_t aud)
inline

Set an audience to check for. If any of the specified audiences is not present in the token the check fails.

Parameters
audAudience to check for.
Returns
*this to allow chaining

Definition at line 3731 of file jwt.h.

◆ with_audience() [2/2]

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::with_audience ( const typename json_traits::string_type &  aud)
inline

Set an audience to check for. If the specified audiences is not present in the token the check fails.

Parameters
audAudience to check for.
Returns
*this to allow chaining

Definition at line 3742 of file jwt.h.

◆ with_claim() [1/2]

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::with_claim ( const typename json_traits::string_type &  name,
basic_claim_t  c 
)
inline

Specify a claim to check for equality (both type & value).

Parameters
nameName of the claim to check for
cClaim to check for
Returns
*this to allow chaining

Definition at line 3777 of file jwt.h.

◆ with_claim() [2/2]

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::with_claim ( const typename json_traits::string_type &  name,
verify_check_fn_t  fn 
)
inline

Specify a claim to check for using the specified operation.

Parameters
nameName of the claim to check for
fnFunction to use for verifying the claim
Returns
*this to allow chaining

Definition at line 3765 of file jwt.h.

◆ with_id()

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::with_id ( const typename json_traits::string_type &  id)
inline

Set an id to check for. Check is casesensitive.

Parameters
idID to check for.
Returns
*this to allow chaining

Definition at line 3754 of file jwt.h.

◆ with_issuer()

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::with_issuer ( const typename json_traits::string_type &  iss)
inline

Set an issuer to check for. Check is casesensitive.

Parameters
issIssuer to check for.
Returns
*this to allow chaining

Definition at line 3710 of file jwt.h.

◆ with_subject()

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::with_subject ( const typename json_traits::string_type &  sub)
inline

Set a subject to check for. Check is casesensitive.

Parameters
subSubject to check for.
Returns
*this to allow chaining

Definition at line 3721 of file jwt.h.

◆ with_type()

template<typename Clock , typename json_traits >
verifier& jwt::verifier< Clock, json_traits >::with_type ( const typename json_traits::string_type &  type,
std::locale  locale = std::locale{} 
)
inline

Set an type to check for.

According to RFC 7519 Section 5.1, This parameter is ignored by JWT implementations; any processing of this parameter is performed by the JWT application. Check is casesensitive.

Parameters
typeType Header Parameter to check for.
localeLocalization functionality to use when comapring
Returns
*this to allow chaining

Definition at line 3697 of file jwt.h.


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