Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
oauth_assertion.h
1#ifndef SOURCEMETA_CORE_OAUTH_ASSERTION_H_
2#define SOURCEMETA_CORE_OAUTH_ASSERTION_H_
3
4#ifndef SOURCEMETA_CORE_OAUTH_EXPORT
5#include <sourcemeta/core/oauth_export.h>
6#endif
7
8#include <sourcemeta/core/crypto.h>
9#include <sourcemeta/core/jose_algorithm.h>
10#include <sourcemeta/core/jose_jwk_private.h>
11#include <sourcemeta/core/jose_jwks.h>
12#include <sourcemeta/core/oauth_dpop.h>
13
14#include <chrono> // std::chrono::seconds, std::chrono::system_clock
15#include <cstdint> // std::uint8_t
16#include <optional> // std::optional
17#include <span> // std::span
18#include <string> // std::string
19#include <string_view> // std::string_view
20
21namespace sourcemeta::core {
22
26inline constexpr std::string_view OAUTH_GRANT_TYPE_JWT_BEARER{
27 "urn:ietf:params:oauth:grant-type:jwt-bearer"};
28
31inline constexpr std::string_view OAUTH_CLIENT_ASSERTION_TYPE_JWT_BEARER{
32 "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"};
33
54[[nodiscard]] SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_assertion(
55 const std::string_view issuer, const std::string_view subject,
56 const std::string_view audience, const std::chrono::seconds lifetime,
57 const std::chrono::system_clock::time_point now, const JWKPrivate &key,
58 const JWSAlgorithm algorithm) -> std::optional<std::string>;
59
80[[nodiscard]] SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_client_assertion(
81 const std::string_view client_id, const std::string_view audience,
82 const std::chrono::seconds lifetime,
83 const std::chrono::system_clock::time_point now, const JWKPrivate &key,
84 const JWSAlgorithm algorithm) -> std::optional<std::string>;
85
101SOURCEMETA_CORE_OAUTH_EXPORT
102auto oauth_client_assertion(const std::string_view assertion,
103 SecureString &sink) -> void;
104
122SOURCEMETA_CORE_OAUTH_EXPORT
123auto oauth_build_token_request_jwt_bearer(const std::string_view assertion,
124 const std::string_view scope,
125 SecureString &sink) -> void;
126
156
164 std::span<const JWSAlgorithm> allowed_algorithms{};
166 std::chrono::seconds clock_skew{std::chrono::seconds{0}};
171};
172
201[[nodiscard]] SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_verify_client_assertion(
202 const std::string_view assertion,
203 const std::span<const std::string_view> expected_audiences,
204 const std::string_view request_client_id, const JWKS &keys,
205 const std::chrono::system_clock::time_point now,
206 const OAuthAssertionVerifyOptions &options)
207 -> std::optional<OAuthAssertionError>;
208
234[[nodiscard]] SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_verify_assertion_grant(
235 const std::string_view assertion, const std::string_view expected_issuer,
236 const std::span<const std::string_view> expected_audiences,
237 const JWKS &keys, const std::chrono::system_clock::time_point now,
238 const OAuthAssertionVerifyOptions &options)
239 -> std::optional<OAuthAssertionError>;
240
241} // namespace sourcemeta::core
242
243#endif
Definition crypto_secure.h:162
Definition jose_jwk_private.h:35
Definition jose_jwks.h:40
JWSAlgorithm
Definition jose_algorithm.h:21
@ Issuer
The issuer claim is missing or does not match the expected value.
Definition jose_verify.h:28
@ Subject
The subject claim is missing or does not match the expected value.
Definition jose_verify.h:30
@ Audience
The audience claim is missing or does not contain the expected value.
Definition jose_verify.h:32
@ 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
std::chrono::seconds clock_skew
The tolerance applied to the expiration, not-before, and issue times.
Definition oauth_assertion.h:166
std::span< const JWSAlgorithm > allowed_algorithms
Definition oauth_assertion.h:164
OAuthDPoPReplayStore * replay_store
Definition oauth_assertion.h:170
Definition oauth_dpop.h:261
constexpr std::string_view OAUTH_CLIENT_ASSERTION_TYPE_JWT_BEARER
Definition oauth_assertion.h:31
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_assertion(const std::string_view issuer, const std::string_view subject, const std::string_view audience, const std::chrono::seconds lifetime, const std::chrono::system_clock::time_point now, const JWKPrivate &key, const JWSAlgorithm algorithm) -> std::optional< std::string >
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_client_assertion(const std::string_view assertion, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_verify_assertion_grant(const std::string_view assertion, const std::string_view expected_issuer, const std::span< const std::string_view > expected_audiences, const JWKS &keys, const std::chrono::system_clock::time_point now, const OAuthAssertionVerifyOptions &options) -> std::optional< OAuthAssertionError >
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_client_assertion(const std::string_view client_id, const std::string_view audience, const std::chrono::seconds lifetime, const std::chrono::system_clock::time_point now, const JWKPrivate &key, const JWSAlgorithm algorithm) -> std::optional< std::string >
constexpr std::string_view OAUTH_GRANT_TYPE_JWT_BEARER
Definition oauth_assertion.h:26
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_verify_client_assertion(const std::string_view assertion, const std::span< const std::string_view > expected_audiences, const std::string_view request_client_id, const JWKS &keys, const std::chrono::system_clock::time_point now, const OAuthAssertionVerifyOptions &options) -> std::optional< OAuthAssertionError >
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_jwt_bearer(const std::string_view assertion, const std::string_view scope, SecureString &sink) -> void
OAuthAssertionError
Definition oauth_assertion.h:129
@ NotYetValid
The assertion is not yet valid (RFC 7523 Section 3 check 5).
Definition oauth_assertion.h:149
@ 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
@ Replay
Definition oauth_assertion.h:154
@ UnsupportedAlgorithm
The algorithm was absent or outside the accepted set (RFC 7523 Section 5).
Definition oauth_assertion.h:133
@ IssuedInFuture
The issue time lies in the future (RFC 7523 Section 3 check 6).
Definition oauth_assertion.h:151
Definition oauth_assertion.h:161