qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches

Comprehensive JWT implementation for the QB IO library. More...

#include <crypto_jwt.h>

Classes

struct  CreateOptions
 JWT creation options. More...
struct  TokenParts
 JWT token parts. More...
struct  ValidationResult
 Result of JWT validation containing error code and payload if valid. More...
struct  VerifyOptions
 JWT verification options. More...

Public Types

enum class  Algorithm {
  HS256 , HS384 , HS512 , RS256 ,
  RS384 , RS512 , ES256 , ES384 ,
  ES512 , EdDSA
}
 Supported JWT signing algorithms. More...
enum class  ValidationError {
  NONE , INVALID_FORMAT , INVALID_SIGNATURE , TOKEN_EXPIRED ,
  TOKEN_NOT_ACTIVE , INVALID_ISSUER , INVALID_AUDIENCE , INVALID_SUBJECT ,
  CLAIM_MISMATCH
}
 JWT validation error codes.

Static Public Member Functions

static std::string create (const std::map< std::string, std::string > &payload, const CreateOptions &options)
 Create a JWT token with custom payload and options.
static std::string create_token (const std::map< std::string, std::string > &payload, const std::string &issuer, const std::string &subject, const std::string &audience, std::chrono::seconds expires_in, std::chrono::seconds not_before=std::chrono::seconds(0), const std::string &jti="", const CreateOptions &options=CreateOptions())
 Create a JWT token with standard claims and custom payload.
static ValidationResult verify (const std::string &token, const VerifyOptions &options)
 Verify a JWT token.
static TokenParts decode (const std::string &token)
 Decode a JWT token without verification.
static std::string algorithm_to_string (Algorithm algorithm)
 Get string representation of algorithm.
static std::optional< Algorithmalgorithm_from_string (const std::string &algorithm_str)
 Get algorithm from string representation.

Detailed Description

Comprehensive JWT implementation for the QB IO library.

This class provides functionality for creating, signing, and verifying JSON Web Tokens (JWT) according to RFC 7519. It supports multiple signing algorithms and standard JWT claims validation.

Member Enumeration Documentation

◆ Algorithm

enum class qb::jwt::Algorithm
strong

Supported JWT signing algorithms.

Enumerator
HS256 

HMAC using SHA-256.

HS384 

HMAC using SHA-384.

HS512 

HMAC using SHA-512.

RS256 

RSASSA-PKCS1-v1_5 using SHA-256.

RS384 

RSASSA-PKCS1-v1_5 using SHA-384.

RS512 

RSASSA-PKCS1-v1_5 using SHA-512.

ES256 

ECDSA using P-256 and SHA-256.

ES384 

ECDSA using P-384 and SHA-384.

ES512 

ECDSA using P-521 and SHA-512.

EdDSA 

Edwards-curve Digital Signature Algorithm (Ed25519)

Member Function Documentation

◆ create()

std::string qb::jwt::create ( const std::map< std::string, std::string > & payload,
const CreateOptions & options )
static

Create a JWT token with custom payload and options.

Parameters
payloadMap of claims to include in the payload
optionsOptions for creating the token
Returns
JWT token string

◆ create_token()

std::string qb::jwt::create_token ( const std::map< std::string, std::string > & payload,
const std::string & issuer,
const std::string & subject,
const std::string & audience,
std::chrono::seconds expires_in,
std::chrono::seconds not_before = std::chrono::seconds(0),
const std::string & jti = "",
const CreateOptions & options = CreateOptions() )
static

Create a JWT token with standard claims and custom payload.

Parameters
payloadMap of custom claims to include in the payload
issuerToken issuer
subjectToken subject
audienceToken audience
expires_inToken expiration time in seconds from now
not_beforeToken not valid before time in seconds from now (default: 0)
jtiUnique JWT ID
optionsOptions for creating the token
Returns
JWT token string

◆ verify()

ValidationResult qb::jwt::verify ( const std::string & token,
const VerifyOptions & options )
static

Verify a JWT token.

Parameters
tokenJWT token to verify
optionsOptions for verifying the token
Returns
ValidationResult containing error code and payload if valid

◆ decode()

TokenParts qb::jwt::decode ( const std::string & token)
static

Decode a JWT token without verification.

Parameters
tokenJWT token to decode
Returns
TokenParts containing header, payload, and signature
Exceptions
std::runtime_errorif token format is invalid

◆ algorithm_to_string()

std::string qb::jwt::algorithm_to_string ( Algorithm algorithm)
static

Get string representation of algorithm.

Parameters
algorithmAlgorithm to convert to string
Returns
String representation of algorithm

◆ algorithm_from_string()

std::optional< Algorithm > qb::jwt::algorithm_from_string ( const std::string & algorithm_str)
static

Get algorithm from string representation.

Parameters
algorithm_strString representation of algorithm
Returns
Algorithm enum value, or std::nullopt if not recognized