1#ifndef SOURCEMETA_CORE_JOSE_JWT_H_
2#define SOURCEMETA_CORE_JOSE_JWT_H_
4#ifndef SOURCEMETA_CORE_JOSE_EXPORT
5#include <sourcemeta/core/jose_export.h>
9#include <sourcemeta/core/jose_algorithm.h>
10#include <sourcemeta/core/jose_error.h>
13#include <sourcemeta/core/json.h>
20namespace sourcemeta::core {
38class SOURCEMETA_CORE_JOSE_EXPORT
JWT {
42 explicit JWT(
const std::string_view input);
46 [[nodiscard]]
static auto from(
const std::string_view input)
47 -> std::optional<JWT>;
53 return this->algorithm_;
57 [[nodiscard]]
auto key_id() const noexcept -> std::optional<std::string_view>;
60 [[nodiscard]] auto
type() const noexcept -> std::optional<std::string_view>;
65 [[nodiscard]] auto
has_type(const std::string_view media_type) const ->
bool;
68 [[nodiscard]] auto
header() const noexcept -> const
JSON & {
75 [[nodiscard]]
auto issuer() const noexcept -> std::optional<std::string_view>;
78 [[nodiscard]] auto
subject() const noexcept
79 -> std::optional<std::string_view>;
83 has_audience(const std::string_view audience) const noexcept ->
bool;
87 -> std::optional<std::chrono::system_clock::time_point>;
91 -> std::optional<std::chrono::system_clock::time_point>;
95 -> std::optional<std::chrono::system_clock::time_point>;
99 -> std::optional<std::string_view>;
103 return this->payload_;
110 return this->signing_input_;
114 [[nodiscard]]
auto signature() const noexcept -> std::string_view {
115 return this->signature_;
120 static auto parse(
const std::string_view input,
JWT &result) -> bool;
123#pragma warning(disable : 4251)
125 std::string_view signing_input_;
126 std::string signature_;
127 JSON header_{
nullptr};
128 JSON payload_{
nullptr};
129 std::optional<JWSAlgorithm> algorithm_;
131#pragma warning(default : 4251)
auto signing_input() const noexcept -> std::string_view
The exact wire bytes the signature is computed over.
Definition jose_jwt.h:109
auto has_audience(const std::string_view audience) const noexcept -> bool
Whether the token is intended for the given audience.
static auto from(const std::string_view input) -> std::optional< JWT >
auto key_id() const noexcept -> std::optional< std::string_view >
The key identifier from the token header, if present.
auto issuer() const noexcept -> std::optional< std::string_view >
The issuer that created the token, if present.
auto subject() const noexcept -> std::optional< std::string_view >
The subject the token is about, if present.
auto token_id() const noexcept -> std::optional< std::string_view >
The unique identifier of the token, if present.
auto type() const noexcept -> std::optional< std::string_view >
The token type declared in the header, if present.
auto algorithm() const noexcept -> std::optional< JWSAlgorithm >
The signing algorithm declared in the token header, if present.
Definition jose_jwt.h:52
auto has_type(const std::string_view media_type) const -> bool
auto not_before() const -> std::optional< std::chrono::system_clock::time_point >
The time before which the token is not yet valid, if present.
auto payload() const noexcept -> const JSON &
The decoded token payload.
Definition jose_jwt.h:102
auto signature() const noexcept -> std::string_view
The raw token signature.
Definition jose_jwt.h:114
auto issued_at() const -> std::optional< std::chrono::system_clock::time_point >
The time at which the token was issued, if present.
auto header() const noexcept -> const JSON &
The decoded token header.
Definition jose_jwt.h:68
JWT(const std::string_view input)
auto expires_at() const -> std::optional< std::chrono::system_clock::time_point >
The time after which the token is no longer valid, if present.
JWSAlgorithm
Definition jose_algorithm.h:21