1#ifndef SOURCEMETA_CORE_JOSE_VERIFY_H_
2#define SOURCEMETA_CORE_JOSE_VERIFY_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_jwk.h>
11#include <sourcemeta/core/jose_jwks.h>
12#include <sourcemeta/core/jose_jwt.h>
21namespace sourcemeta::core {
69 const std::chrono::seconds not_before_tolerance,
70 const std::chrono::seconds issued_at_tolerance) noexcept
99 -> std::chrono::seconds {
102 constexpr std::chrono::seconds maximum{31556952};
103 return skew < std::chrono::seconds::zero() ? std::chrono::seconds::zero()
104 : skew > maximum ? maximum
131SOURCEMETA_CORE_JOSE_EXPORT
133 const std::string_view expected_audience,
134 const std::chrono::system_clock::time_point now,
136 const std::optional<std::string_view> expected_subject =
137 std::nullopt) -> std::optional<JWTClaimError>;
159SOURCEMETA_CORE_JOSE_EXPORT
161 const std::string_view signing_input,
162 const std::string_view signature,
const JWK &key)
188SOURCEMETA_CORE_JOSE_EXPORT
248SOURCEMETA_CORE_JOSE_EXPORT
250 const std::span<const JWSAlgorithm> allowed_algorithms,
251 const std::string_view expected_issuer,
252 const std::string_view expected_audience,
253 const std::chrono::system_clock::time_point now,
255 const std::optional<std::string_view> expected_subject,
256 const std::optional<std::string_view> expected_type)
257 -> std::optional<JWTVerificationError>;
std::chrono::seconds issued_at
The tolerance applied to the issued-at time claim.
Definition jose_verify.h:79
JWTClockSkew(const std::chrono::seconds expiration_tolerance, const std::chrono::seconds not_before_tolerance, const std::chrono::seconds issued_at_tolerance) noexcept
Apply a distinct tolerance to each time-based claim.
Definition jose_verify.h:68
std::chrono::seconds expiration
The tolerance applied to the expiration time claim.
Definition jose_verify.h:75
std::chrono::seconds not_before
The tolerance applied to the not-before time claim.
Definition jose_verify.h:77
JWTClockSkew() noexcept=default
Apply no tolerance to any time-based claim.
SOURCEMETA_CORE_JOSE_EXPORT auto jwt_verify(const JWT &token, const JWKS &keys, const std::span< const JWSAlgorithm > allowed_algorithms, const std::string_view expected_issuer, const std::string_view expected_audience, const std::chrono::system_clock::time_point now, const JWTClockSkew clock_skew, const std::optional< std::string_view > expected_subject, const std::optional< std::string_view > expected_type) -> std::optional< JWTVerificationError >
auto jwt_bounded_clock_skew(const std::chrono::seconds skew) noexcept -> std::chrono::seconds
Definition jose_verify.h:98
JWTClaimError
Definition jose_verify.h:26
JWTVerificationError
Definition jose_verify.h:194
SOURCEMETA_CORE_JOSE_EXPORT auto jws_verify_signature(const std::optional< JWSAlgorithm > algorithm, const std::string_view signing_input, const std::string_view signature, const JWK &key) -> bool
SOURCEMETA_CORE_JOSE_EXPORT auto jwt_verify_signature(const JWT &token, const JWK &key) -> bool
SOURCEMETA_CORE_JOSE_EXPORT auto jwt_check_claims(const JWT &token, const std::string_view expected_issuer, const std::string_view expected_audience, const std::chrono::system_clock::time_point now, const JWTClockSkew clock_skew={}, const std::optional< std::string_view > expected_subject=std::nullopt) -> std::optional< JWTClaimError >
@ Issuer
The issuer claim is missing or does not match the expected value.
Definition jose_verify.h:28
@ IssuedAt
The issued-at time claim is malformed or lies in the future.
Definition jose_verify.h:38
@ Subject
The subject claim is missing or does not match the expected value.
Definition jose_verify.h:30
@ Expiration
The expiration time claim is missing or the token has expired.
Definition jose_verify.h:34
@ NotBefore
The not-before time claim is malformed or lies in the future.
Definition jose_verify.h:36
@ Audience
The audience claim is missing or does not contain the expected value.
Definition jose_verify.h:32
@ AlgorithmNotAllowed
The token's algorithm is missing or absent from the allow-list.
Definition jose_verify.h:196
@ Signature
The named key was found but its signature did not verify.
Definition jose_verify.h:200
@ UnknownKey
No key in the set could be selected or verified the signature.
Definition jose_verify.h:198
@ Type
The token type does not match the expected media type.
Definition jose_verify.h:202