userver: userver/crypto/jwt.hpp File Reference
Loading...
Searching...
No Matches
jwt.hpp File Reference

Detailed Description

Creation, parsing and verification of signed JSON Web Tokens.

See also
Issuing and verifying JSON Web Tokens

Definition in file jwt.hpp.

Go to the source code of this file.

#include <chrono>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <userver/crypto/exception.hpp>
#include <userver/formats/json/value.hpp>
#include <userver/formats/parse/to.hpp>
#include <userver/formats/serialize/to.hpp>
This graph shows which files directly or indirectly include this file:

Classes

struct  crypto::jwt::JoseHeader
 JOSE header parameters for a compact signed JWT. More...
struct  crypto::jwt::Token
 Header and claims returned by crypto::jwt::Verify. More...
struct  crypto::jwt::VerificationOptions
 Claim checks performed by crypto::jwt::Verify after signature verification. More...

Namespaces

namespace  crypto
 Cryptographic primitives: hashing, signatures, certificates, and randomness.
namespace  crypto::jwt
 Signed JWTs in the three-part JWS compact serialization.

Enumerations

enum class  crypto::jwt::ExpirationPolicy {
  crypto::jwt::kRequired ,
  crypto::jwt::kOptional
}
 Whether verification requires an expiration claim. More...

Functions

JoseHeader crypto::jwt::Parse (const formats::json::Value &value, formats::parse::To< JoseHeader >)
 Parses the JOSE header from a JSON object.
formats::json::Value crypto::jwt::Serialize (const JoseHeader &header, formats::serialize::To< formats::json::Value >)
 Serializes a JOSE header to a JSON object, omitting absent parameters.
std::string crypto::jwt::MakeToken (const formats::json::Value &payload, const crypto::Signer &signer)
 Signs the supplied claims with typ: JWT and the signer's algorithm. Checks registered claim types before signing.
std::string crypto::jwt::MakeToken (std::string_view json_payload, const crypto::Signer &signer)
 Creates a compact token from the exact bytes of a serialized JSON payload. The header contains typ: JWT followed by the signer's alg. Any crypto::Signer is accepted, including crypto::SignerNone for unsigned tokens. The caller is responsible for validating registered claims.
std::string crypto::jwt::MakeToken (std::string_view json_payload, const crypto::Signer &signer, std::string_view key_id)
JoseHeader crypto::jwt::UnverifiedParseJoseHeader (std::string_view token)
 Reads the unverified JOSE header from a compact JWT for key selection. Checks the three-part structure and decodes only the header. The returned algorithm may be unknown. Pass the original token to crypto::jwt::Verify to check the algorithm, signature, and claims.
Token crypto::jwt::Verify (std::string_view token, const crypto::Verifier &verifier, const VerificationOptions &options={})
 Verifies a JWT with the application's trusted key and algorithm, then validates its registered claims.