1#ifndef SOURCEMETA_CORE_OAUTH_DPOP_H_
2#define SOURCEMETA_CORE_OAUTH_DPOP_H_
4#ifndef SOURCEMETA_CORE_OAUTH_EXPORT
5#include <sourcemeta/core/oauth_export.h>
8#include <sourcemeta/core/jose_algorithm.h>
9#include <sourcemeta/core/jose_jwk_private.h>
11#include <sourcemeta/core/json.h>
25namespace sourcemeta::core {
78 proof(
const std::string_view server,
const std::string_view method,
79 const std::string_view url,
const std::string_view access_token,
80 const std::chrono::system_clock::time_point now, std::string &sink)
86 auto observe(
const std::string_view server,
const std::string_view nonce)
93 [[nodiscard]]
auto thumbprint() const -> std::optional<std::
string>;
99#pragma warning(disable : 4251)
101 mutable std::mutex mutex_;
102 std::map<std::string, std::string, std::less<>> nonces_;
104#pragma warning(default : 4251)
123[[nodiscard]] SOURCEMETA_CORE_OAUTH_EXPORT
auto
139[[nodiscard]] SOURCEMETA_CORE_OAUTH_EXPORT
auto
141 -> std::optional<std::string>;
231 const std::string_view proof,
const std::string_view method,
232 const std::string_view url,
const std::chrono::system_clock::time_point now,
291 const std::string_view target,
292 const std::chrono::system_clock::time_point now,
293 const std::chrono::seconds window,
294 const bool normalize_target =
true) -> bool;
299 [[nodiscard]]
auto size(
const std::chrono::system_clock::time_point now)
const
304 std::array<std::uint8_t, 32> digest;
305 std::chrono::system_clock::time_point expiry;
308 std::size_t capacity_;
310#pragma warning(disable : 4251)
312 mutable std::mutex mutex_;
313 std::vector<Entry> entries_;
315#pragma warning(default : 4251)
331[[nodiscard]] SOURCEMETA_CORE_OAUTH_EXPORT
auto
JWSAlgorithm
Definition jose_algorithm.h:21
@ Signature
The named key was found but its signature did not verify.
Definition jose_verify.h:200
std::optional< std::string_view > access_token
Definition oauth_dpop.h:205
std::span< const JWSAlgorithm > allowed_algorithms
Definition oauth_dpop.h:193
std::optional< std::string_view > expected_nonce
Definition oauth_dpop.h:201
auto check_and_insert(const std::string_view identifier, const std::string_view target, const std::chrono::system_clock::time_point now, const std::chrono::seconds window, const bool normalize_target=true) -> bool
auto proof(const std::string_view server, const std::string_view method, const std::string_view url, const std::string_view access_token, const std::chrono::system_clock::time_point now, std::string &sink) -> bool
OAuthDPoPProofer(JWKPrivate key, const JWSAlgorithm algorithm)
OAuthDPoPProofer(const OAuthDPoPProofer &)=delete
std::chrono::seconds past_window
How far in the past a creation time may be (RFC 9449 Section 11.1).
Definition oauth_dpop.h:195
std::chrono::seconds future_window
Definition oauth_dpop.h:198
std::optional< std::string_view > bound_thumbprint
Definition oauth_dpop.h:208
OAuthDPoPReplayStore(const OAuthDPoPReplayStore &)=delete
A store owns a mutex, so it is neither copied nor moved.
std::size_t proof_count
Definition oauth_dpop.h:190
auto observe(const std::string_view server, const std::string_view nonce) -> void
auto thumbprint() const -> std::optional< std::string >
static constexpr std::size_t DEFAULT_CAPACITY
The default maximum number of live entries a store retains.
Definition oauth_dpop.h:264
OAuthDPoPReplayStore(const std::size_t capacity=DEFAULT_CAPACITY) noexcept
Definition oauth_dpop.h:268
auto size(const std::chrono::system_clock::time_point now) const -> std::size_t
OAuthDPoPError
Definition oauth_dpop.h:147
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_is_valid_dpop_nonce(const std::string_view value) noexcept -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_dpop_verify(const std::string_view proof, const std::string_view method, const std::string_view url, const std::chrono::system_clock::time_point now, const OAuthDPoPVerifyOptions &options) -> std::optional< OAuthDPoPError >
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_dpop_confirmation(const std::string_view thumbprint) -> JSON
constexpr std::string_view OAUTH_TOKEN_TYPE_DPOP
Definition oauth_dpop.h:30
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_dpop_proof_thumbprint(const std::string_view proof) -> std::optional< std::string >
@ MissingClaim
A required header parameter or claim was absent (check 3).
Definition oauth_dpop.h:153
@ MethodMismatch
The method claim did not match the request method (check 8).
Definition oauth_dpop.h:164
@ KeyMismatch
Definition oauth_dpop.h:179
@ MissingNonce
Definition oauth_dpop.h:169
@ AccessTokenMismatch
Definition oauth_dpop.h:176
@ NonceMismatch
The nonce claim did not match the nonce the server issued (check 10).
Definition oauth_dpop.h:171
@ ProofCount
More or fewer than one DPoP header field was present (check 1).
Definition oauth_dpop.h:149
@ UnexpectedType
The token type header parameter was not dpop+jwt (check 4).
Definition oauth_dpop.h:155
@ TargetMismatch
The target claim did not match the request target (check 9).
Definition oauth_dpop.h:166
@ Malformed
The assertion was not a well-formed JSON Web Token.
Definition oauth_assertion.h:131
@ Expired
The assertion has expired (RFC 7523 Section 3 check 4).
Definition oauth_assertion.h:147
@ UnsupportedAlgorithm
The algorithm was absent or outside the accepted set (RFC 7523 Section 5).
Definition oauth_assertion.h:133