Goby3 3.5.1
2026.06.04
Loading...
Searching...
No Matches
jwt::builder< Clock, json_traits > Class Template Reference

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

Public Member Functions

JWT_CLAIM_EXPLICIT builder (Clock c)
 
builderset_header_claim (const typename json_traits::string_type &id, typename json_traits::value_type c)
 
builderset_header_claim (const typename json_traits::string_type &id, basic_claim< json_traits > c)
 
builderset_payload_claim (const typename json_traits::string_type &id, typename json_traits::value_type c)
 
builderset_payload_claim (const typename json_traits::string_type &id, basic_claim< json_traits > c)
 
builderset_algorithm (typename json_traits::string_type str)
 Set algorithm claim You normally don't need to do this, as the algorithm is automatically set if you don't change it.
 
builderset_type (typename json_traits::string_type str)
 
builderset_content_type (typename json_traits::string_type str)
 
builderset_key_id (typename json_traits::string_type str)
 Set key id claim.
 
builderset_issuer (typename json_traits::string_type str)
 
builderset_subject (typename json_traits::string_type str)
 
builderset_audience (typename json_traits::array_type a)
 
builderset_audience (typename json_traits::string_type aud)
 
builderset_expires_at (const date &d)
 
template<class Rep , class Period >
builderset_expires_in (const std::chrono::duration< Rep, Period > &d)
 
builderset_not_before (const date &d)
 
builderset_issued_at (const date &d)
 
builderset_issued_now ()
 
builderset_id (const typename json_traits::string_type &str)
 
template<typename Algo , typename Encode >
json_traits::string_type sign (const Algo &algo, Encode encode) const
 
template<typename Algo >
json_traits::string_type sign (const Algo &algo) const
 
template<typename Algo , typename Encode >
json_traits::string_type sign (const Algo &algo, Encode encode, std::error_code &ec) const
 
template<typename Algo >
json_traits::string_type sign (const Algo &algo, std::error_code &ec) const
 

Detailed Description

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

Builder class to build and sign a new token Use jwt::create() to get an instance of this class.

Definition at line 3127 of file jwt.h.

Constructor & Destructor Documentation

◆ builder()

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

Constructor for building a new builder instance

Parameters
cClock instance

Definition at line 3139 of file jwt.h.

Member Function Documentation

◆ set_algorithm()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_algorithm ( typename json_traits::string_type  str)
inline

Set algorithm claim You normally don't need to do this, as the algorithm is automatically set if you don't change it.

Parameters
strName of algorithm
Returns
*this to allow for method chaining

Definition at line 3188 of file jwt.h.

◆ set_audience() [1/2]

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_audience ( typename json_traits::array_type  a)
inline

Set audience claim

Parameters
aAudience set
Returns
*this to allow for method chaining

Definition at line 3237 of file jwt.h.

◆ set_audience() [2/2]

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_audience ( typename json_traits::string_type  aud)
inline

Set audience claim

Parameters
audSingle audience
Returns
*this to allow for method chaining

Definition at line 3245 of file jwt.h.

◆ set_content_type()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_content_type ( typename json_traits::string_type  str)
inline

Set content type claim

Parameters
strType to set
Returns
*this to allow for method chaining

Definition at line 3204 of file jwt.h.

◆ set_expires_at()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_expires_at ( const date d)
inline

Set expires at claim

Parameters
dExpires time
Returns
*this to allow for method chaining

Definition at line 3253 of file jwt.h.

◆ set_expires_in()

template<typename Clock , typename json_traits >
template<class Rep , class Period >
builder & jwt::builder< Clock, json_traits >::set_expires_in ( const std::chrono::duration< Rep, Period > &  d)
inline

Set expires at claim to d from the current moment

Parameters
dtoken expiration timeout
Returns
*this to allow for method chaining

Definition at line 3260 of file jwt.h.

◆ set_header_claim() [1/2]

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_header_claim ( const typename json_traits::string_type &  id,
basic_claim< json_traits >  c 
)
inline

Set a header claim.

Parameters
idName of the claim
cClaim to add
Returns
*this to allow for method chaining

Definition at line 3157 of file jwt.h.

◆ set_header_claim() [2/2]

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_header_claim ( const typename json_traits::string_type &  id,
typename json_traits::value_type  c 
)
inline

Set a header claim.

Parameters
idName of the claim
cClaim to add
Returns
*this to allow for method chaining

Definition at line 3146 of file jwt.h.

◆ set_id()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_id ( const typename json_traits::string_type &  str)
inline

Set id claim

Parameters
strID to set
Returns
*this to allow for method chaining

Definition at line 3285 of file jwt.h.

◆ set_issued_at()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_issued_at ( const date d)
inline

Set issued at claim

Parameters
dIssued at time, should be current time
Returns
*this to allow for method chaining

Definition at line 3274 of file jwt.h.

◆ set_issued_now()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_issued_now ( )
inline

Set issued at claim to the current moment

Returns
*this to allow for method chaining

Definition at line 3279 of file jwt.h.

◆ set_issuer()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_issuer ( typename json_traits::string_type  str)
inline

Set issuer claim

Parameters
strIssuer to set
Returns
*this to allow for method chaining

Definition at line 3221 of file jwt.h.

◆ set_key_id()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_key_id ( typename json_traits::string_type  str)
inline

Set key id claim.

Parameters
strKey id to set
Returns
*this to allow for method chaining

Definition at line 3213 of file jwt.h.

◆ set_not_before()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_not_before ( const date d)
inline

Set not before claim

Parameters
dFirst valid time
Returns
*this to allow for method chaining

Definition at line 3268 of file jwt.h.

◆ set_payload_claim() [1/2]

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_payload_claim ( const typename json_traits::string_type &  id,
basic_claim< json_traits >  c 
)
inline

Set a payload claim.

Parameters
idName of the claim
cClaim to add
Returns
*this to allow for method chaining

Definition at line 3177 of file jwt.h.

◆ set_payload_claim() [2/2]

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_payload_claim ( const typename json_traits::string_type &  id,
typename json_traits::value_type  c 
)
inline

Set a payload claim.

Parameters
idName of the claim
cClaim to add
Returns
*this to allow for method chaining

Definition at line 3167 of file jwt.h.

◆ set_subject()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_subject ( typename json_traits::string_type  str)
inline

Set subject claim

Parameters
strSubject to set
Returns
*this to allow for method chaining

Definition at line 3229 of file jwt.h.

◆ set_type()

template<typename Clock , typename json_traits >
builder & jwt::builder< Clock, json_traits >::set_type ( typename json_traits::string_type  str)
inline

Set type claim

Parameters
strType to set
Returns
*this to allow for method chaining

Definition at line 3196 of file jwt.h.

◆ sign() [1/4]

template<typename Clock , typename json_traits >
template<typename Algo >
json_traits::string_type jwt::builder< Clock, json_traits >::sign ( const Algo &  algo) const
inline

Sign token and return result

using the jwt::base functions provided

Parameters
algoInstance of an algorithm to sign the token with
Returns
Final token as a string

Definition at line 3317 of file jwt.h.

◆ sign() [2/4]

template<typename Clock , typename json_traits >
template<typename Algo , typename Encode >
json_traits::string_type jwt::builder< Clock, json_traits >::sign ( const Algo &  algo,
Encode  encode 
) const
inline

Sign token and return result

Template Parameters
AlgoCallable method which takes a string_type and return the signed input as a string_type
EncodeCallable method which takes a string_type and base64url safe encodes it, MUST return the result with no padding; trim the result.
Parameters
algoInstance of an algorithm to sign the token with
encodeCallable to transform the serialized json to base64 with no padding
Returns
Final token as a string
Note
If the 'alg' header in not set in the token it will be set to algo.name()

Definition at line 3301 of file jwt.h.

◆ sign() [3/4]

template<typename Clock , typename json_traits >
template<typename Algo , typename Encode >
json_traits::string_type jwt::builder< Clock, json_traits >::sign ( const Algo &  algo,
Encode  encode,
std::error_code &  ec 
) const
inline

Sign token and return result

Template Parameters
AlgoCallable method which takes a string_type and return the signed input as a string_type
EncodeCallable method which takes a string_type and base64url safe encodes it, MUST return the result with no padding; trim the result.
Parameters
algoInstance of an algorithm to sign the token with
encodeCallable to transform the serialized json to base64 with no padding
ecerror_code filled with details on error
Returns
Final token as a string
Note
If the 'alg' header in not set in the token it will be set to algo.name()

Definition at line 3338 of file jwt.h.

◆ sign() [4/4]

template<typename Clock , typename json_traits >
template<typename Algo >
json_traits::string_type jwt::builder< Clock, json_traits >::sign ( const Algo &  algo,
std::error_code &  ec 
) const
inline

Sign token and return result

using the jwt::base functions provided

Parameters
algoInstance of an algorithm to sign the token with
ecerror_code filled with details on error
Returns
Final token as a string

Definition at line 3363 of file jwt.h.


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