Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
OAuth

A standards-driven implementation of the OAuth 2.0 and 2.1 message family. More...

Classes

struct  sourcemeta::core::OAuthAssertionVerifyOptions
struct  sourcemeta::core::OAuthParameter
struct  sourcemeta::core::OAuthAuthorizationRequest
struct  sourcemeta::core::OAuthAuthorizationResponse
struct  sourcemeta::core::OAuthChallenge
struct  sourcemeta::core::OAuthClientCredentials
class  sourcemeta::core::OAuthDeviceAuthorizationResponse
class  sourcemeta::core::OAuthDevicePoller
class  sourcemeta::core::OAuthDPoPProofer
struct  sourcemeta::core::OAuthDPoPVerifyOptions
class  sourcemeta::core::OAuthDPoPReplayStore
class  sourcemeta::core::OAuthMetadataParseError
class  sourcemeta::core::OAuthRegistrationParseError
class  sourcemeta::core::OAuthIntrospectionResponse
struct  sourcemeta::core::OAuthServerMetadataConfig
struct  sourcemeta::core::OAuthResourceMetadataConfig
class  sourcemeta::core::OAuthMetadataProvider
class  sourcemeta::core::OAuthResourceMetadataProvider
class  sourcemeta::core::OAuthPARResponse
struct  sourcemeta::core::OAuthClientRegistrationConfig
struct  sourcemeta::core::OAuthClientRegistrationResult
struct  sourcemeta::core::OAuthTokenLookupRequest
struct  sourcemeta::core::OAuthTokenRequest
class  sourcemeta::core::OAuthTokenResponse
struct  sourcemeta::core::OAuthTokenGrant
struct  sourcemeta::core::OAuthTokenExchangeRequest
struct  sourcemeta::core::OAuthTransactionSecrets
struct  sourcemeta::core::OAuthTransaction

Enumerations

enum class  sourcemeta::core::OAuthAssertionError : std::uint8_t {
  OAuthAssertionError::Malformed , OAuthAssertionError::UnsupportedAlgorithm , OAuthAssertionError::UnknownKey , OAuthAssertionError::Signature ,
  OAuthAssertionError::Issuer , OAuthAssertionError::Subject , OAuthAssertionError::Audience , OAuthAssertionError::Expired ,
  OAuthAssertionError::NotYetValid , OAuthAssertionError::IssuedInFuture , OAuthAssertionError::Replay
}
enum class  sourcemeta::core::OAuthResponseMode : std::uint8_t { OAuthResponseMode::Query , OAuthResponseMode::Fragment , OAuthResponseMode::FormPost }
enum class  sourcemeta::core::OAuthClientAuthenticationMethod : std::uint8_t {
  OAuthClientAuthenticationMethod::None , OAuthClientAuthenticationMethod::Basic , OAuthClientAuthenticationMethod::Post , OAuthClientAuthenticationMethod::Public ,
  OAuthClientAuthenticationMethod::Assertion
}
enum class  sourcemeta::core::OAuthDevicePollDecision : std::uint8_t {
  OAuthDevicePollDecision::Continue , OAuthDevicePollDecision::RetryWithNonce , OAuthDevicePollDecision::Denied , OAuthDevicePollDecision::Expired ,
  OAuthDevicePollDecision::Error
}
enum class  sourcemeta::core::OAuthDPoPError : std::uint8_t {
  OAuthDPoPError::ProofCount , OAuthDPoPError::Malformed , OAuthDPoPError::MissingClaim , OAuthDPoPError::UnexpectedType ,
  OAuthDPoPError::UnsupportedAlgorithm , OAuthDPoPError::PrivateKey , OAuthDPoPError::Signature , OAuthDPoPError::MethodMismatch ,
  OAuthDPoPError::TargetMismatch , OAuthDPoPError::MissingNonce , OAuthDPoPError::NonceMismatch , OAuthDPoPError::Expired ,
  OAuthDPoPError::AccessTokenMismatch , OAuthDPoPError::KeyMismatch
}
enum class  sourcemeta::core::OAuthAuthorizationError : std::uint8_t {
  OAuthAuthorizationError::InvalidRequest , OAuthAuthorizationError::UnauthorizedClient , OAuthAuthorizationError::AccessDenied , OAuthAuthorizationError::UnsupportedResponseType ,
  OAuthAuthorizationError::InvalidScope , OAuthAuthorizationError::ServerError , OAuthAuthorizationError::TemporarilyUnavailable
}
enum class  sourcemeta::core::OAuthTokenError : std::uint8_t {
  OAuthTokenError::InvalidRequest , OAuthTokenError::InvalidClient , OAuthTokenError::InvalidGrant , OAuthTokenError::UnauthorizedClient ,
  OAuthTokenError::UnsupportedGrantType , OAuthTokenError::InvalidScope , OAuthTokenError::AuthorizationPending , OAuthTokenError::SlowDown ,
  OAuthTokenError::AccessDenied , OAuthTokenError::ExpiredToken , OAuthTokenError::InvalidTarget , OAuthTokenError::InvalidDPoPProof ,
  OAuthTokenError::UseDPoPNonce , OAuthTokenError::UnsupportedTokenType
}
enum class  sourcemeta::core::OAuthBearerError : std::uint8_t {
  OAuthBearerError::InvalidRequest , OAuthBearerError::InvalidToken , OAuthBearerError::InsufficientScope , OAuthBearerError::InvalidDPoPProof ,
  OAuthBearerError::UseDPoPNonce
}
enum class  sourcemeta::core::OAuthRegistrationError : std::uint8_t { OAuthRegistrationError::InvalidRedirectURI , OAuthRegistrationError::InvalidClientMetadata , OAuthRegistrationError::InvalidSoftwareStatement , OAuthRegistrationError::UnapprovedSoftwareStatement }
enum class  sourcemeta::core::OAuthWellKnownKind : std::uint8_t { OAuthWellKnownKind::AuthorizationServer , OAuthWellKnownKind::ProtectedResource , OAuthWellKnownKind::OpenIDConfigurationInserted , OAuthWellKnownKind::OpenIDConfigurationAppended }
enum class  sourcemeta::core::OAuthPKCEMethod : std::uint8_t { OAuthPKCEMethod::S256 , OAuthPKCEMethod::Plain }
enum class  sourcemeta::core::OAuthPKCEOutcome : std::uint8_t {
  OAuthPKCEOutcome::Match , OAuthPKCEOutcome::NotUsed , OAuthPKCEOutcome::MissingVerifier , OAuthPKCEOutcome::MissingChallenge ,
  OAuthPKCEOutcome::Mismatch , OAuthPKCEOutcome::MethodNotAllowed , OAuthPKCEOutcome::MalformedVerifier , OAuthPKCEOutcome::MalformedChallenge
}
enum class  sourcemeta::core::OAuthProfile : std::uint8_t { OAuthProfile::Strict , OAuthProfile::Compatible }
enum class  sourcemeta::core::OAuthRevocationOutcome : std::uint8_t { OAuthRevocationOutcome::Success , OAuthRevocationOutcome::Retry , OAuthRevocationOutcome::Error }
enum class  sourcemeta::core::OAuthIssuerSupport : std::uint8_t { OAuthIssuerSupport::Supported , OAuthIssuerSupport::NotSupported , OAuthIssuerSupport::Unknown }
enum class  sourcemeta::core::OAuthCallbackError : std::uint8_t {
  OAuthCallbackError::State , OAuthCallbackError::ReceivedURI , OAuthCallbackError::Issuer , OAuthCallbackError::Declined ,
  OAuthCallbackError::MissingCode
}

Functions

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::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 sourcemeta::core::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 >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_client_assertion (const std::string_view assertion, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_jwt_bearer (const std::string_view assertion, const std::string_view scope, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::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 sourcemeta::core::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 sourcemeta::core::oauth_build_authorization_url (const std::string_view endpoint, const OAuthAuthorizationRequest &request, std::string &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_authorization_request (const std::string_view query, std::string &storage, OAuthAuthorizationRequest &result, const std::function< void(std::string_view, std::string_view)> &on_other) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_redirect_uri_matches (const std::string_view registered, const std::string_view presented, const OAuthProfile profile) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_private_use_scheme (const std::string_view scheme) noexcept -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_authorization_response (const std::string_view query, std::string &storage, OAuthAuthorizationResponse &result) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_redirect (const std::string_view redirect_uri, const OAuthAuthorizationResponse &response, std::string &sink) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_error_redirect (const std::string_view redirect_uri, const OAuthAuthorizationResponse &response, std::string &sink) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_default_response_mode (const std::string_view response_type) -> std::optional< OAuthResponseMode >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_response_mode_allowed (const std::string_view response_type, const OAuthResponseMode mode) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_redirect (const std::string_view redirect_uri, const OAuthAuthorizationResponse &response, const OAuthResponseMode mode, std::string &sink) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_error_redirect (const std::string_view redirect_uri, const OAuthAuthorizationResponse &response, const OAuthResponseMode mode, std::string &sink) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_form_post (const std::string_view redirect_uri, const OAuthAuthorizationResponse &response, std::string &sink, const std::string_view title="Submit This Form") -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_error_form_post (const std::string_view redirect_uri, const OAuthAuthorizationResponse &response, std::string &sink, const std::string_view title="Submit This Form") -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_bearer_header (const std::string_view token, std::string &sink) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_challenge_parameter (const std::string_view header, const std::string_view scheme, const std::string_view name) -> std::optional< std::string >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_challenge (const std::string_view scheme, const OAuthChallenge &challenge, std::string &sink) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_has_audience (const JSON &claims, const std::string_view audience) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_has_scope (const JSON &claims, const std::string_view value) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_dpop_bound (const JSON &claims) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_client_secret_basic (const std::string_view client_id, const std::string_view client_secret, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_client_secret_post (const std::string_view client_id, const std::string_view client_secret, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_client_id_only (const std::string_view client_id, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_client_authentication (const std::string_view authorization, const std::string_view body, SecureString &storage, OAuthClientCredentials &credentials) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_device_authorization_request (const std::string_view client_id, const std::string_view scope, const std::span< const OAuthParameter > resources, std::string &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_device (const std::string_view device_code, const std::span< const OAuthParameter > resources, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_device_authorization_response (const std::string_view device_code, const std::string_view user_code, const std::string_view verification_uri, const std::string_view verification_uri_complete, const std::chrono::seconds expires_in, const std::chrono::seconds interval) -> std::optional< JSON >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_device_user_code () -> std::array< char, 8 >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_device_user_code_matches (const std::string_view presented, const std::string_view stored) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_dpop_confirmation (const std::string_view thumbprint) -> JSON
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_dpop_proof_thumbprint (const std::string_view proof) -> std::optional< std::string >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::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 sourcemeta::core::oauth_is_valid_dpop_nonce (const std::string_view value) noexcept -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_error_code (const OAuthAuthorizationError error) noexcept -> std::string_view
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_error_code (const OAuthTokenError error) noexcept -> std::string_view
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_error_code (const OAuthBearerError error) noexcept -> std::string_view
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_error_code (const OAuthRegistrationError error) noexcept -> std::string_view
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::to_oauth_authorization_error (const std::string_view code) noexcept -> std::optional< OAuthAuthorizationError >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::to_oauth_token_error (const std::string_view code) noexcept -> std::optional< OAuthTokenError >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::to_oauth_bearer_error (const std::string_view code) noexcept -> std::optional< OAuthBearerError >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::to_oauth_registration_error (const std::string_view code) noexcept -> std::optional< OAuthRegistrationError >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_token_error_status (const OAuthTokenError error, const bool authenticated_via_header) noexcept -> HTTPStatus
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_bearer_error_status (const OAuthBearerError error) noexcept -> HTTPStatus
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_introspection_request (const std::string_view token, const std::string_view token_type_hint, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_introspection_inactive () -> JSON
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_well_known_url (const std::string_view identifier, const OAuthWellKnownKind kind, std::string &sink) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_endpoint_url (const std::string_view value) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_resource_identifier (const std::string_view value) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_issuer_identifier (const std::string_view value) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_server_metadata (const OAuthServerMetadataConfig &config) -> std::optional< JSON >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_resource_metadata (const OAuthResourceMetadataConfig &config) -> std::optional< JSON >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_par_request (const OAuthAuthorizationRequest &request, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_par_authorization_url (const std::string_view endpoint, const std::string_view client_id, const std::string_view request_uri, std::string &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_par_request (const std::string_view body, SecureString &storage, OAuthAuthorizationRequest &result, const std::function< void(std::string_view, std::string_view)> &on_other) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_par_request_uri () -> std::string
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_par_response (const std::string_view request_uri, const std::chrono::seconds expires_in) -> std::optional< JSON >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_par_dpop_binding (const std::string_view dpop_jkt, const std::optional< std::string_view > proof_thumbprint) -> std::optional< std::string_view >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_pkce_method_code (const OAuthPKCEMethod method) noexcept -> std::string_view
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::to_oauth_pkce_method (const std::string_view value) noexcept -> std::optional< OAuthPKCEMethod >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_pkce_verifier () -> std::array< char, 43 >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_pkce_challenge (const std::string_view verifier) -> std::array< char, 43 >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_pkce_verify (const std::string_view verifier, const std::string_view challenge, const OAuthPKCEMethod method, const OAuthProfile profile) -> OAuthPKCEOutcome
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_random_token () -> std::array< char, 43 >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_registration_request (const OAuthClientRegistrationConfig &config) -> std::optional< JSON >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_registration_error_response (const std::string_view error, const std::string_view error_description) -> JSON
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_registration_grant_response_consistent (const OAuthClientMetadata &metadata) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_apply_software_statement_claims (JSON &metadata, const JSON &claims) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_registration_response (const JSON &metadata, const OAuthClientRegistrationResult &result) -> std::optional< JSON >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_registration_update_request (const OAuthClientRegistrationConfig &config, const std::string_view client_id, const std::string_view client_secret) -> std::optional< JSON >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_revocation_request (const std::string_view token, const std::string_view token_type_hint, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_revocation_request (const std::string_view body, SecureString &storage, OAuthTokenLookupRequest &result, const std::function< void(std::string_view, std::string_view)> &on_other) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_revocation_outcome (const HTTPStatus status) noexcept -> OAuthRevocationOutcome
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_code (const std::string_view code, const std::string_view redirect_uri, const std::string_view code_verifier, const std::span< const OAuthParameter > resources, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_refresh (const std::string_view refresh_token, const std::string_view scope, const std::span< const OAuthParameter > resources, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_client_credentials (const std::string_view scope, const std::span< const OAuthParameter > resources, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_token_request (const std::string_view body, SecureString &storage, OAuthTokenRequest &result, const std::function< void(std::string_view, std::string_view)> &on_other) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_token_response (const OAuthTokenGrant &grant) -> JSON
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_token_error_response (const std::string_view error, const std::string_view error_description, const std::string_view error_uri) -> JSON
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_token_exchange_valid (const OAuthTokenExchangeRequest &request) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_exchange (const OAuthTokenExchangeRequest &request, SecureString &sink) -> bool
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_issued_token_type (const JSON &response) -> std::optional< std::string_view >
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_transaction_mint () -> OAuthTransactionSecrets
SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_transaction_check (const OAuthTransaction &transaction, const OAuthAuthorizationResponse &response, const OAuthIssuerSupport issuer_support, const std::string_view received_uri, std::string_view &code) -> std::optional< OAuthCallbackError >

Variables

constexpr std::string_view sourcemeta::core::OAUTH_GRANT_TYPE_JWT_BEARER
constexpr std::string_view sourcemeta::core::OAUTH_CLIENT_ASSERTION_TYPE_JWT_BEARER
constexpr std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_DPOP {"DPoP"}
constexpr std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_HINT_ACCESS_TOKEN
constexpr std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_HINT_REFRESH_TOKEN
constexpr std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_ACCESS_TOKEN
constexpr std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_REFRESH_TOKEN
constexpr std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_ID_TOKEN
constexpr std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_SAML1
constexpr std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_SAML2
constexpr std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_JWT

Detailed Description

A standards-driven implementation of the OAuth 2.0 and 2.1 message family.

This functionality is included as follows:

#include <sourcemeta/core/oauth.h>

Class Documentation

◆ sourcemeta::core::OAuthAssertionVerifyOptions

struct sourcemeta::core::OAuthAssertionVerifyOptions

The inputs to JWT bearer assertion verification beyond the request. The accepted algorithms are matched exactly, so an empty set accepts none, and a replay store, when set, rejects a reused identifier.

Public Attributes

std::span< const JWSAlgorithmallowed_algorithms {}
std::chrono::seconds clock_skew {std::chrono::seconds{0}}
 The tolerance applied to the expiration, not-before, and issue times.
OAuthDPoPReplayStorereplay_store {nullptr}

Member Data Documentation

◆ allowed_algorithms

std::span<const JWSAlgorithm> sourcemeta::core::OAuthAssertionVerifyOptions::allowed_algorithms {}

The algorithms accepted per local policy, a non-owning view whose backing storage must outlive the verification (RFC 7523 Section 5).

◆ replay_store

OAuthDPoPReplayStore* sourcemeta::core::OAuthAssertionVerifyOptions::replay_store {nullptr}

The store tracking assertion identifiers to reject a replay, ignored when null or when the assertion carries no identifier (RFC 7523 Section 3 check 7).

◆ sourcemeta::core::OAuthParameter

struct sourcemeta::core::OAuthParameter

A single query or form parameter as a name and value pair. Both members are non-owning views that must outlive any use of this parameter. For example:

#include <sourcemeta/core/oauth.h>
const sourcemeta::core::OAuthParameter parameter{"resource",
"https://api.example"};
Definition oauth_authorization.h:29

Public Attributes

std::string_view name
 The parameter name.
std::string_view value
 The parameter value, still in its raw unescaped form.

◆ sourcemeta::core::OAuthAuthorizationRequest

struct sourcemeta::core::OAuthAuthorizationRequest

A non-owning view of the parameters of an authorization request (RFC 6749 Section 4.1.1). Every field borrows from the caller and must outlive any use of this struct. An empty scalar field is treated as absent and is not emitted, and the spans carry the repeatable and extension parameters. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
request.client_id = "s6BhdRkqt3";
request.state = "xyz";
std::string url;
"https://server.example/authorize", request, url);
assert(url ==
"https://server.example/authorize?response_type=code"
"&client_id=s6BhdRkqt3&state=xyz");
std::string_view state
Definition oauth_authorization.h:68
std::string_view client_id
The client identifier (RFC 6749 Section 2.2).
Definition oauth_authorization.h:60
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_authorization_url(const std::string_view endpoint, const OAuthAuthorizationRequest &request, std::string &sink) -> void
Definition oauth_authorization.h:58

Public Attributes

std::string_view client_id
 The client identifier (RFC 6749 Section 2.2).
std::string_view redirect_uri
std::string_view scope
 The space-delimited requested scope (RFC 6749 Section 3.3).
std::string_view state
std::string_view code_challenge
 The PKCE code challenge (RFC 7636 Section 4.3).
std::string_view code_challenge_method
std::string_view request_uri
 The reference to a pushed authorization request (RFC 9126 Section 4).
std::string_view dpop_jkt
 The JWK thumbprint of the DPoP proof public key (RFC 9449 Section 10).
std::string_view response_type
std::span< const OAuthParameterresources
std::span< const OAuthParameterextra

Member Data Documentation

◆ code_challenge_method

std::string_view sourcemeta::core::OAuthAuthorizationRequest::code_challenge_method

The PKCE code challenge method, emitted only alongside a challenge (RFC 7636 Section 4.3).

◆ extra

std::span<const OAuthParameter> sourcemeta::core::OAuthAuthorizationRequest::extra

The extension parameters, such as an OpenID Connect nonce, emitted verbatim after the known parameters.

◆ redirect_uri

std::string_view sourcemeta::core::OAuthAuthorizationRequest::redirect_uri

The redirection endpoint the response is returned to (RFC 6749 Section 3.1.2).

◆ resources

std::span<const OAuthParameter> sourcemeta::core::OAuthAuthorizationRequest::resources

The repeatable resource indicators, each an absolute URI without a fragment (RFC 8707 Section 2).

◆ response_type

std::string_view sourcemeta::core::OAuthAuthorizationRequest::response_type

The response type, a space-delimited set that defaults to code when unset and is otherwise honored by the authorization URL and pushed request builders alike, surfaced on parse so a server can tell a missing value from one it does not understand (RFC 6749 Section 3.1.1). It is placed after the older members so an existing positional initializer keeps populating them.

◆ state

std::string_view sourcemeta::core::OAuthAuthorizationRequest::state

The opaque cross-site request forgery token echoed back on the response (RFC 6749 Section 10.12).

◆ sourcemeta::core::OAuthAuthorizationResponse

struct sourcemeta::core::OAuthAuthorizationResponse

A non-owning view of an authorization response returned on the redirection endpoint (RFC 6749 Section 4.1.2). Each field borrows from the parsed query or the decode arena, so both must outlive the view, and an absent parameter is an empty view. A present error marks a failure response (RFC 6749 Section 4.1.2.1).

Public Attributes

std::string_view code
 The authorization code (RFC 6749 Section 4.1.2).
std::string_view state
 The state value echoed from the request (RFC 6749 Section 4.1.2).
std::string_view iss
 The issuer identifier of the authorization server (RFC 9207 Section 2).
std::string_view error
 The error code of a failure response (RFC 6749 Section 4.1.2.1).
std::string_view error_description
std::string_view error_uri

Member Data Documentation

◆ error_description

std::string_view sourcemeta::core::OAuthAuthorizationResponse::error_description

The human-readable error description of a failure response (RFC 6749 Section 4.1.2.1).

◆ error_uri

std::string_view sourcemeta::core::OAuthAuthorizationResponse::error_uri

The URI of a human-readable error page for a failure response (RFC 6749 Section 4.1.2.1).

◆ sourcemeta::core::OAuthChallenge

struct sourcemeta::core::OAuthChallenge

The parameters of a WWW-Authenticate challenge a protected resource returns (RFC 6750 Section 3, RFC 9728 Section 5.1, RFC 9449 Section 7.1). Every field is a non-owning view that must outlive any use of this struct, and an empty field is omitted from the challenge.

Public Attributes

std::string_view realm
 The protection space the credentials apply to (RFC 6750 Section 3).
std::string_view scope
 The space-delimited scope the token must carry (RFC 6750 Section 3).
std::string_view error
 The error code (RFC 6750 Section 3.1).
std::string_view error_description
 The human-readable error description (RFC 6750 Section 3).
std::string_view error_uri
 The URI of a human-readable error page (RFC 6750 Section 3).
std::string_view resource_metadata
std::string_view algs

Member Data Documentation

◆ algs

std::string_view sourcemeta::core::OAuthChallenge::algs

The space-delimited JWS algorithms the DPoP scheme accepts (RFC 9449 Section 7.1).

◆ resource_metadata

std::string_view sourcemeta::core::OAuthChallenge::resource_metadata

The URL of the protected resource metadata document (RFC 9728 Section 5.1).

◆ sourcemeta::core::OAuthClientCredentials

struct sourcemeta::core::OAuthClientCredentials

The client credentials a token request presented, each a non-owning view into the request or the decode arena (RFC 6749 Section 2.3). An absent field is an empty view.

Public Attributes

OAuthClientAuthenticationMethod method
 The mechanism the request presented.
std::string_view client_id
 The client identifier.
std::string_view client_secret
 The client secret, present only for Basic and Post.
std::string_view assertion_type
 The assertion type, present only for Assertion (RFC 7521 Section 4.2).
std::string_view assertion
 The assertion, present only for Assertion (RFC 7521 Section 4.2).

◆ sourcemeta::core::OAuthDeviceAuthorizationResponse

class sourcemeta::core::OAuthDeviceAuthorizationResponse

A non-owning view over a device authorization response (RFC 8628 Section 3.2) held in a caller-owned JSON value, which must outlive the view. A client keeps displaying the user code even when it uses the complete verification URI (RFC 8628 Section 3.3.1). For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
const auto document{sourcemeta::core::parse_json(R"JSON({
"device_code": "GmRh", "user_code": "WDJB-MJHT",
"verification_uri": "https://example.com/device", "expires_in": 1800
})JSON")};
assert(response.user_code().value() == "WDJB-MJHT");
SOURCEMETA_CORE_JSON_EXPORT auto parse_json(std::basic_istream< JSON::Char, JSON::CharTraits > &stream) -> JSON
auto user_code() const -> std::optional< std::string_view >
The end-user verification code (RFC 8628 Section 3.2).

Public Member Functions

 OAuthDeviceAuthorizationResponse (const JSON &data)
 Construct a view over a device authorization response, which is borrowed.
auto device_code () const -> std::optional< std::string_view >
 The device verification code (RFC 8628 Section 3.2).
auto user_code () const -> std::optional< std::string_view >
 The end-user verification code (RFC 8628 Section 3.2).
auto verification_uri () const -> std::optional< std::string_view >
 The end-user verification URI (RFC 8628 Section 3.2).
auto verification_uri_complete () const -> std::optional< std::string_view >
 The verification URI with the user code included (RFC 8628 Section 3.2).
auto expires_in () const -> std::optional< std::chrono::seconds >
auto interval () const -> std::chrono::seconds
auto data () const -> const JSON &
 The underlying document.

Member Function Documentation

◆ expires_in()

auto sourcemeta::core::OAuthDeviceAuthorizationResponse::expires_in ( ) const -> std::optional< std::chrono::seconds >
nodiscard

The lifetime of the device and user codes, no value when non-positive (RFC 8628 Section 3.2).

◆ interval()

auto sourcemeta::core::OAuthDeviceAuthorizationResponse::interval ( ) const -> std::chrono::seconds
nodiscard

The minimum polling interval, defaulting to five seconds when absent (RFC 8628 Section 3.2).

◆ sourcemeta::core::OAuthDevicePoller

class sourcemeta::core::OAuthDevicePoller

A pure state machine driving the device flow polling (RFC 8628 Section 3.5). It tracks the polling interval and the code lifetime, and interprets token endpoint errors, without performing any I/O. For example:

#include <sourcemeta/core/oauth.h>
#include <chrono>
#include <cassert>
std::chrono::seconds{5}, std::chrono::seconds{1800},
std::chrono::steady_clock::now()};
assert(poller.interval() == std::chrono::seconds{10});
auto observe(const OAuthTokenError error) noexcept -> OAuthDevicePollDecision
auto interval() const noexcept -> std::chrono::seconds
The current polling interval, which a slow_down error grows.
Definition oauth_device.h:156
@ Continue
Keep polling at the current interval.
Definition oauth_device.h:125
@ SlowDown
Definition oauth_error.h:65

Public Member Functions

 OAuthDevicePoller (const std::chrono::seconds interval, const std::chrono::seconds lifetime, const std::chrono::steady_clock::time_point start) noexcept
auto interval () const noexcept -> std::chrono::seconds
 The current polling interval, which a slow_down error grows.
auto expired (const std::chrono::steady_clock::time_point now) const noexcept -> bool
 Whether the codes have expired locally by the given time.
auto observe (const OAuthTokenError error) noexcept -> OAuthDevicePollDecision

Constructor & Destructor Documentation

◆ OAuthDevicePoller()

sourcemeta::core::OAuthDevicePoller::OAuthDevicePoller ( const std::chrono::seconds interval,
const std::chrono::seconds lifetime,
const std::chrono::steady_clock::time_point start )
noexcept

Construct a poller with the interval and lifetime the device authorization response advertised, from a starting time. A steady clock is used so wall clock adjustments cannot shorten or extend the lifetime. An interval of zero or less defaults to five seconds (RFC 8628 Section 3.5).

Member Function Documentation

◆ observe()

auto sourcemeta::core::OAuthDevicePoller::observe ( const OAuthTokenError error) -> OAuthDevicePollDecision
noexcept

Interpret a token endpoint error, permanently adding five seconds to the interval on slow_down and continuing, continuing on authorization_pending, retrying with a nonce on a DPoP nonce requirement (RFC 9449 Section 8), and reporting a terminal decision otherwise (RFC 8628 Section 3.5).

◆ sourcemeta::core::OAuthDPoPProofer

class sourcemeta::core::OAuthDPoPProofer

A client-side minter of DPoP proof JSON Web Tokens (RFC 9449 Section 4.2) that holds one proof-of-possession key and the most recent nonce each server has issued. Nonces are tracked per server because a nonce is only accepted by the server that issued it (RFC 9449 Section 9), so a caller keys the authorization server by its issuer and each resource server by its origin. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/jose.h>
#include <chrono>
#include <string>
#include <cassert>
assert(key.has_value());
std::move(key.value()), sourcemeta::core::JWSAlgorithm::ES256};
std::string header;
assert(proofer.proof("https://server.example.com", "POST",
"https://server.example.com/token", "",
std::chrono::system_clock::now(), header));
static auto from_pem(const std::string_view pem) -> std::optional< JWKPrivate >
@ ES256
ECDSA using the NIST P-256 curve and SHA-256.
Definition jose_algorithm.h:35
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
Definition oauth_dpop.h:56

Public Member Functions

 OAuthDPoPProofer (JWKPrivate key, const JWSAlgorithm algorithm)
 OAuthDPoPProofer (const OAuthDPoPProofer &)=delete
 OAuthDPoPProofer (OAuthDPoPProofer &&)=delete
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
auto observe (const std::string_view server, const std::string_view nonce) -> void
auto thumbprint () const -> std::optional< std::string >

Constructor & Destructor Documentation

◆ OAuthDPoPProofer() [1/2]

sourcemeta::core::OAuthDPoPProofer::OAuthDPoPProofer ( JWKPrivate key,
const JWSAlgorithm algorithm )

Construct a proofer bound to a proof-of-possession key and the asymmetric signature algorithm to sign proofs with (RFC 9449 Section 4.2).

◆ OAuthDPoPProofer() [2/2]

sourcemeta::core::OAuthDPoPProofer::OAuthDPoPProofer ( const OAuthDPoPProofer & )
delete

A proofer owns a private key and a mutex, so it is neither copied nor moved.

Member Function Documentation

◆ observe()

auto sourcemeta::core::OAuthDPoPProofer::observe ( const std::string_view server,
const std::string_view nonce ) -> void

Record the most recent nonce a server issued through its response header, to be included in later proofs to that server, ignoring a malformed nonce rather than echoing it (RFC 9449 Section 8).

◆ proof()

auto sourcemeta::core::OAuthDPoPProofer::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
nodiscard

Append a DPoP proof for a request to the sink, returning whether it could be built and signed. The method and target URI are covered by the proof, the access token binds the proof through its hash when it is presented to a protected resource and is omitted otherwise (RFC 9449 Section 7), and the most recent nonce the server issued is included when one is known. The creation time is taken from the given clock reading (RFC 9449 Section 4.2).

◆ thumbprint()

auto sourcemeta::core::OAuthDPoPProofer::thumbprint ( ) const -> std::optional< std::string >
nodiscard

The JSON Web Key thumbprint of the proof-of-possession key (RFC 9449 Section 6.1), the value a client sends to bind an authorization code to the key (RFC 9449 Section 10), or no value when the public part cannot be recovered.

◆ sourcemeta::core::OAuthDPoPVerifyOptions

struct sourcemeta::core::OAuthDPoPVerifyOptions

The inputs to DPoP proof verification a caller supplies beyond the request (RFC 9449 Section 4.3). Every field has a safe default, so a token endpoint verifying a proof with no bound token leaves the token and thumbprint unset, and a protected resource sets both.

Public Attributes

std::size_t proof_count {1}
std::span< const JWSAlgorithmallowed_algorithms {}
std::chrono::seconds past_window {std::chrono::seconds{300}}
 How far in the past a creation time may be (RFC 9449 Section 11.1).
std::chrono::seconds future_window {std::chrono::seconds{5}}
std::optional< std::string_view > expected_nonce {std::nullopt}
std::optional< std::string_view > access_token {std::nullopt}
std::optional< std::string_view > bound_thumbprint {std::nullopt}

Member Data Documentation

◆ access_token

std::optional<std::string_view> sourcemeta::core::OAuthDPoPVerifyOptions::access_token {std::nullopt}

The access token presented alongside the proof, requiring a matching hash claim when set, and requiring the bound thumbprint to also be set so the key binding is confirmed rather than skipped (RFC 9449 Section 7).

◆ allowed_algorithms

std::span<const JWSAlgorithm> sourcemeta::core::OAuthDPoPVerifyOptions::allowed_algorithms {}

The asymmetric algorithms accepted per local policy, every asymmetric algorithm when empty (RFC 9449 Section 4.3 check 5).

◆ bound_thumbprint

std::optional<std::string_view> sourcemeta::core::OAuthDPoPVerifyOptions::bound_thumbprint {std::nullopt}

The thumbprint the access token is bound to, requiring a matching proof key when set (RFC 9449 Section 4.3 check 12).

◆ expected_nonce

std::optional<std::string_view> sourcemeta::core::OAuthDPoPVerifyOptions::expected_nonce {std::nullopt}

The nonce the server issued to the client, requiring a matching nonce claim when set (RFC 9449 Section 9).

◆ future_window

std::chrono::seconds sourcemeta::core::OAuthDPoPVerifyOptions::future_window {std::chrono::seconds{5}}

How far in the future a creation time may be, to tolerate clock offset (RFC 9449 Section 11.1).

◆ proof_count

std::size_t sourcemeta::core::OAuthDPoPVerifyOptions::proof_count {1}

The number of DPoP header fields the request carried, checked to be exactly one (RFC 9449 Section 4.3 check 1).

◆ sourcemeta::core::OAuthDPoPReplayStore

class sourcemeta::core::OAuthDPoPReplayStore

An in-memory store of the proof identifiers seen within their acceptance window, to reject a replayed DPoP proof at one target (RFC 9449 Section 11.1). A store instance is safe to share across threads, it holds a hash of each identifier rather than the identifier itself, and it is bounded to a fixed capacity so an attacker minting distinct proofs cannot exhaust memory. When full it fails closed, rejecting a new identifier rather than evicting a live entry whose replay guard is still needed, so a flood costs availability rather than replay protection. Give each entry a window that covers the whole acceptance window a proof enjoys, the sum of the past and future tolerances, so an entry never expires while its proof is still accepted. For example:

#include <sourcemeta/core/oauth.h>
#include <chrono>
#include <cassert>
const auto now{std::chrono::system_clock::now()};
assert(store.check_and_insert("id", "https://server.example.com/token", now,
std::chrono::seconds{300}));
assert(!store.check_and_insert("id", "https://server.example.com/token",
now,
std::chrono::seconds{300}));
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
Definition oauth_dpop.h:261

Public Member Functions

 OAuthDPoPReplayStore (const std::size_t capacity=DEFAULT_CAPACITY) noexcept
 OAuthDPoPReplayStore (const OAuthDPoPReplayStore &)=delete
 A store owns a mutex, so it is neither copied nor moved.
 OAuthDPoPReplayStore (OAuthDPoPReplayStore &&)=delete
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 size (const std::chrono::system_clock::time_point now) const -> std::size_t

Static Public Attributes

static constexpr std::size_t DEFAULT_CAPACITY {131072}
 The default maximum number of live entries a store retains.

Constructor & Destructor Documentation

◆ OAuthDPoPReplayStore()

sourcemeta::core::OAuthDPoPReplayStore::OAuthDPoPReplayStore ( const std::size_t capacity = DEFAULT_CAPACITY)
inlineexplicitnoexcept

Construct an empty store with the given maximum number of live entries, beyond which a new identifier is rejected until a slot frees on expiry.

Member Function Documentation

◆ check_and_insert()

auto sourcemeta::core::OAuthDPoPReplayStore::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
nodiscard

Record a proof identifier at a target and report whether it is new, returning false for one already seen within its window, which is a replay (RFC 9449 Section 11.1). Entries whose window has elapsed by the given time are pruned, and a new identifier is refused once the store is full of live entries, so the return also stands for a store that cannot admit it. The target is canonicalized as an HTTP target URI when normalize_target is set, so an equivalent but differently spelled DPoP target still collides (RFC 9449 Section 4.3 check 9), and keyed verbatim otherwise, for a target compared without normalization such as an assertion audience.

◆ size()

auto sourcemeta::core::OAuthDPoPReplayStore::size ( const std::chrono::system_clock::time_point now) const -> std::size_t
nodiscard

The number of entries whose window has not elapsed by the given time, counted without modifying the store, since expired entries are pruned when the next one is recorded.

◆ sourcemeta::core::OAuthMetadataParseError

class sourcemeta::core::OAuthMetadataParseError

An error that occurs when parsing an invalid authorization server or protected resource metadata document.

Inheritance diagram for sourcemeta::core::OAuthMetadataParseError:

◆ sourcemeta::core::OAuthRegistrationParseError

class sourcemeta::core::OAuthRegistrationParseError

An error that occurs when parsing an invalid dynamic client registration request or response.

Inheritance diagram for sourcemeta::core::OAuthRegistrationParseError:

◆ sourcemeta::core::OAuthIntrospectionResponse

class sourcemeta::core::OAuthIntrospectionResponse

A non-owning view over a token introspection response (RFC 7662 Section 2.2) held in a caller-owned JSON value, which must outlive the view. The active state is computed once at construction, since it is the one per-request hot accessor. A response must not be cached past its exp (RFC 7662 Section 4). For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
const auto document{sourcemeta::core::parse_json(
R"JSON({"active":true,"scope":"read","client_id":"abc"})JSON")};
assert(response.active());
assert(response.scope().value() == "read");
auto active() const noexcept -> bool
auto scope() const -> std::optional< std::string_view >
The space-delimited scope (RFC 7662 Section 2.2), or no value when absent.
Definition oauth_introspection.h:61

Public Member Functions

 OAuthIntrospectionResponse (const JSON &data)
auto active () const noexcept -> bool
auto scope () const -> std::optional< std::string_view >
 The space-delimited scope (RFC 7662 Section 2.2), or no value when absent.
auto client_id () const -> std::optional< std::string_view >
 The client identifier the token was issued to (RFC 7662 Section 2.2).
auto username () const -> std::optional< std::string_view >
 The resource owner username (RFC 7662 Section 2.2).
auto token_type () const -> std::optional< std::string_view >
auto subject () const -> std::optional< std::string_view >
 The subject of the token (RFC 7662 Section 2.2).
auto issuer () const -> std::optional< std::string_view >
 The issuer of the token (RFC 7662 Section 2.2).
auto jti () const -> std::optional< std::string_view >
 The identifier of the token (RFC 7662 Section 2.2).
auto expiration () const -> std::optional< std::chrono::seconds >
 The expiration time (RFC 7662 Section 2.2), or no value when absent.
auto issued_at () const -> std::optional< std::chrono::seconds >
 The issuance time (RFC 7662 Section 2.2).
auto not_before () const -> std::optional< std::chrono::seconds >
 The not-before time (RFC 7662 Section 2.2).
auto data () const -> const JSON &

Constructor & Destructor Documentation

◆ OAuthIntrospectionResponse()

sourcemeta::core::OAuthIntrospectionResponse::OAuthIntrospectionResponse ( const JSON & data)
explicit

Construct a view over an introspection response document, which is borrowed.

Member Function Documentation

◆ active()

auto sourcemeta::core::OAuthIntrospectionResponse::active ( ) const -> bool
nodiscardnoexcept

Whether the token is active (RFC 7662 Section 2.2), computed at construction. A missing or non-boolean active is treated as inactive.

◆ data()

auto sourcemeta::core::OAuthIntrospectionResponse::data ( ) const -> const JSON &
nodiscard

The underlying document, for reaching members without a typed accessor such as aud, may_act, or cnf.

◆ token_type()

auto sourcemeta::core::OAuthIntrospectionResponse::token_type ( ) const -> std::optional< std::string_view >
nodiscard

The token type, which is DPoP for a DPoP-bound token (RFC 7662 Section 2.2, RFC 9449 Section 6.2).

◆ sourcemeta::core::OAuthServerMetadata

class sourcemeta::core::OAuthServerMetadata

An authorization server metadata document (RFC 8414), owning its JSON. The document is validated on construction against the issuer it was retrieved for: the issuer must match by exact code points and be a valid issuer identifier, response_types_supported must be present and non-empty, and an authentication method that needs a signing algorithm list must carry a non-empty one without none. Accessors apply the specification defaults, and any member without a typed accessor is reachable through the underlying document. A string accessor returns a view into the owned document, valid for the lifetime of this object, so a view taken before the object is moved from must not be used afterward. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
R"JSON({"issuer":"https://example.com",
"response_types_supported":["code"],
"authorization_endpoint":"https://example.com/authorize",
"token_endpoint":"https://example.com/token"})JSON")};
std::move(document), "https://example.com")};
assert(metadata.has_value());
assert(metadata.value().token_endpoint().value() ==
"https://example.com/token");
static auto from(JSON &&data, const std::string_view issuer) -> std::optional< OAuthServerMetadata >

Public Member Functions

 OAuthServerMetadata (JSON &&data, const std::string_view issuer)
auto issuer () const -> std::string_view
 The issuer identifier (RFC 8414 Section 2).
auto authorization_endpoint () const -> std::optional< std::string_view >
 The authorization endpoint (RFC 8414 Section 2).
auto token_endpoint () const -> std::optional< std::string_view >
 The token endpoint (RFC 8414 Section 2).
auto registration_endpoint () const -> std::optional< std::string_view >
 The dynamic client registration endpoint (RFC 8414 Section 2).
auto device_authorization_endpoint () const -> std::optional< std::string_view >
 The device authorization endpoint (RFC 8628 Section 4).
auto revocation_endpoint () const -> std::optional< std::string_view >
 The token revocation endpoint (RFC 8414 Section 2).
auto introspection_endpoint () const -> std::optional< std::string_view >
 The token introspection endpoint (RFC 8414 Section 2).
auto jwks_uri () const -> std::optional< std::string_view >
 The JWK Set document location (RFC 8414 Section 2).
auto pushed_authorization_request_endpoint () const -> std::optional< std::string_view >
 The pushed authorization request endpoint (RFC 9126 Section 5).
auto require_pushed_authorization_requests () const -> bool
auto authorization_response_iss_parameter_supported () const -> bool
auto supports_response_type (const std::string_view value) const -> bool
 Whether a response type is supported (RFC 8414 Section 2).
auto supports_grant_type (const std::string_view value) const -> bool
auto supports_code_challenge_method (const std::string_view value) const -> bool
auto supports_token_endpoint_auth_method (const std::string_view value) const -> bool
auto supports_protected_resource (const std::string_view value) const -> bool
auto data () const -> const JSON &
 The underlying document, for reaching members without a typed accessor.

Static Public Member Functions

static auto from (JSON &&data, const std::string_view issuer) -> std::optional< OAuthServerMetadata >

Constructor & Destructor Documentation

◆ OAuthServerMetadata()

sourcemeta::core::OAuthServerMetadata::OAuthServerMetadata ( JSON && data,
const std::string_view issuer )

Construct and validate a metadata document for an expected issuer, throwing when it is invalid. The document is moved in.

Member Function Documentation

◆ authorization_response_iss_parameter_supported()

auto sourcemeta::core::OAuthServerMetadata::authorization_response_iss_parameter_supported ( ) const -> bool
nodiscard

Whether the server signs authorization responses with an iss parameter, defaulting to false when absent (RFC 9207 Section 3).

◆ from()

auto sourcemeta::core::OAuthServerMetadata::from ( JSON && data,
const std::string_view issuer ) -> std::optional< OAuthServerMetadata >
staticnodiscard

Construct and validate a metadata document for an expected issuer, returning no value when it is invalid. The document is moved in.

◆ require_pushed_authorization_requests()

auto sourcemeta::core::OAuthServerMetadata::require_pushed_authorization_requests ( ) const -> bool
nodiscard

Whether the server accepts authorization request data only through the pushed authorization request endpoint, defaulting to false when absent (RFC 9126 Section 5).

◆ supports_code_challenge_method()

auto sourcemeta::core::OAuthServerMetadata::supports_code_challenge_method ( const std::string_view value) const -> bool
nodiscard

Whether a PKCE code challenge method is supported, defaulting to none when absent since an omitted list means PKCE is unsupported (RFC 8414 Section 2).

◆ supports_grant_type()

auto sourcemeta::core::OAuthServerMetadata::supports_grant_type ( const std::string_view value) const -> bool
nodiscard

Whether a grant type is supported, defaulting to the authorization code and implicit grants when absent (RFC 8414 Section 2).

◆ supports_protected_resource()

auto sourcemeta::core::OAuthServerMetadata::supports_protected_resource ( const std::string_view value) const -> bool
nodiscard

Whether a protected resource is listed as usable with this authorization server (RFC 9728 Section 4).

◆ supports_token_endpoint_auth_method()

auto sourcemeta::core::OAuthServerMetadata::supports_token_endpoint_auth_method ( const std::string_view value) const -> bool
nodiscard

Whether a token endpoint authentication method is supported, defaulting to client_secret_basic when absent (RFC 8414 Section 2).

◆ sourcemeta::core::OAuthResourceMetadata

class sourcemeta::core::OAuthResourceMetadata

A protected resource metadata document (RFC 9728), owning its JSON. The document is validated on construction against the resource it was retrieved for: resource must be present, a valid resource identifier (an https URL with no fragment, a query tolerated), and identical by code points to the expected resource (RFC 9728 Section 3.3). Pass the resource identifier the well-known URL was derived from, or, for the WWW-Authenticate resource_metadata flow, the URL the request was made to (the Section 3.3 second check). Only the plain JSON members are read, so a signed_metadata statement is not processed, which RFC 9728 Section 2.2 permits by making its precedence conditional on a consumer that "supports signed metadata". A string accessor returns a view into the owned document, valid for the lifetime of this object. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
auto document{sourcemeta::core::parse_json(R"JSON({
"resource": "https://api.example",
"authorization_servers": [ "https://auth.example" ]
})JSON")};
std::move(document), "https://api.example")};
assert(metadata.has_value());
assert(metadata.value().first_authorization_server().value() ==
"https://auth.example");
static auto from(JSON &&data, const std::string_view resource) -> std::optional< OAuthResourceMetadata >

Public Member Functions

 OAuthResourceMetadata (JSON &&data, const std::string_view resource)
auto resource () const -> std::string_view
 The resource identifier (RFC 9728 Section 2).
auto first_authorization_server () const -> std::optional< std::string_view >
auto supports_authorization_server (const std::string_view value) const -> bool
 Whether an authorization server issuer is listed (RFC 9728 Section 2).
auto jwks_uri () const -> std::optional< std::string_view >
auto supports_bearer_method (const std::string_view value) const -> bool
auto supports_scope (const std::string_view value) const -> bool
 Whether a scope is listed for the resource (RFC 9728 Section 2).
auto dpop_bound_access_tokens_required () const -> bool
auto resource_name () const -> std::optional< std::string_view >
auto resource_documentation () const -> std::optional< std::string_view >
 The developer documentation page location (RFC 9728 Section 2).
auto resource_policy_uri () const -> std::optional< std::string_view >
 The data usage policy page location (RFC 9728 Section 2).
auto resource_tos_uri () const -> std::optional< std::string_view >
 The terms of service page location (RFC 9728 Section 2).
auto tls_client_certificate_bound_access_tokens () const -> bool
auto supports_resource_signing_alg (const std::string_view value) const -> bool
auto supports_dpop_signing_alg (const std::string_view value) const -> bool
auto supports_authorization_details_type (const std::string_view value) const -> bool
auto data () const -> const JSON &

Static Public Member Functions

static auto from (JSON &&data, const std::string_view resource) -> std::optional< OAuthResourceMetadata >

Constructor & Destructor Documentation

◆ OAuthResourceMetadata()

sourcemeta::core::OAuthResourceMetadata::OAuthResourceMetadata ( JSON && data,
const std::string_view resource )

Construct and validate a metadata document for an expected resource, throwing when it is invalid. The document is moved in.

Member Function Documentation

◆ data()

auto sourcemeta::core::OAuthResourceMetadata::data ( ) const -> const JSON &
nodiscard

The underlying document, for reaching members without a typed accessor such as the internationalized names.

◆ dpop_bound_access_tokens_required()

auto sourcemeta::core::OAuthResourceMetadata::dpop_bound_access_tokens_required ( ) const -> bool
nodiscard

Whether the resource requires DPoP-bound access tokens, defaulting to false when absent (RFC 9728 Section 2).

◆ first_authorization_server()

auto sourcemeta::core::OAuthResourceMetadata::first_authorization_server ( ) const -> std::optional< std::string_view >
nodiscard

The first authorization server that can issue tokens for the resource, which a client resolves to its metadata (RFC 9728 Section 5), or no value when none is listed.

◆ from()

auto sourcemeta::core::OAuthResourceMetadata::from ( JSON && data,
const std::string_view resource ) -> std::optional< OAuthResourceMetadata >
staticnodiscard

Construct and validate a metadata document for an expected resource, returning no value when it is invalid. The document is moved in.

◆ jwks_uri()

auto sourcemeta::core::OAuthResourceMetadata::jwks_uri ( ) const -> std::optional< std::string_view >
nodiscard

The JWK Set document location for the resource's own keys (RFC 9728 Section 2).

◆ resource_name()

auto sourcemeta::core::OAuthResourceMetadata::resource_name ( ) const -> std::optional< std::string_view >
nodiscard

The human-readable name of the resource without a language tag (RFC 9728 Section 2), reaching a language-tagged variant through the underlying document.

◆ supports_authorization_details_type()

auto sourcemeta::core::OAuthResourceMetadata::supports_authorization_details_type ( const std::string_view value) const -> bool
nodiscard

Whether an authorization details type is listed for the resource (RFC 9728 Section 2).

◆ supports_bearer_method()

auto sourcemeta::core::OAuthResourceMetadata::supports_bearer_method ( const std::string_view value) const -> bool
nodiscard

Whether a bearer token presentation method is listed (RFC 9728 Section 2), where an explicit empty list means none is supported. Absence is unspecified rather than unsupported, so this returns false then.

◆ supports_dpop_signing_alg()

auto sourcemeta::core::OAuthResourceMetadata::supports_dpop_signing_alg ( const std::string_view value) const -> bool
nodiscard

Whether a JWS algorithm is listed for validating DPoP proofs (RFC 9728 Section 2).

◆ supports_resource_signing_alg()

auto sourcemeta::core::OAuthResourceMetadata::supports_resource_signing_alg ( const std::string_view value) const -> bool
nodiscard

Whether a JWS algorithm is listed for signing resource responses (RFC 9728 Section 2).

◆ tls_client_certificate_bound_access_tokens()

auto sourcemeta::core::OAuthResourceMetadata::tls_client_certificate_bound_access_tokens ( ) const -> bool
nodiscard

Whether the resource supports mutual-TLS certificate-bound access tokens, defaulting to false when absent (RFC 9728 Section 2).

◆ sourcemeta::core::OAuthServerMetadataConfig

struct sourcemeta::core::OAuthServerMetadataConfig

The configuration an authorization server publishes as its metadata (RFC 8414 Section 2), each field a non-owning view. An empty scalar and a zero-element array are omitted, since RFC 8414 Section 3.2 forbids a zero-element array in the response.

Public Attributes

std::string_view issuer
 The issuer identifier (RFC 8414 Section 2), REQUIRED.
std::string_view authorization_endpoint
 The authorization endpoint (RFC 8414 Section 2).
std::string_view token_endpoint
 The token endpoint (RFC 8414 Section 2).
std::string_view registration_endpoint
 The dynamic client registration endpoint (RFC 8414 Section 2).
std::string_view jwks_uri
 The JWK Set document location (RFC 8414 Section 2).
std::span< const std::string_view > response_types_supported
 The supported response types (RFC 8414 Section 2), REQUIRED and non-empty.
std::span< const std::string_view > grant_types_supported
 The supported grant types (RFC 8414 Section 2).
std::span< const std::string_view > code_challenge_methods_supported
 The supported PKCE code challenge methods (RFC 8414 Section 2, RFC 7636).
std::span< const std::string_view > token_endpoint_auth_methods_supported
 The supported token endpoint authentication methods (RFC 8414 Section 2).
std::span< const std::string_view > token_endpoint_auth_signing_alg_values_supported
std::span< const std::string_view > scopes_supported
 The supported scopes (RFC 8414 Section 2).
std::string_view pushed_authorization_request_endpoint
bool require_pushed_authorization_requests {false}
std::span< const std::string_view > protected_resources

Member Data Documentation

◆ protected_resources

std::span<const std::string_view> sourcemeta::core::OAuthServerMetadataConfig::protected_resources

The protected resources usable with this authorization server, each a valid resource identifier (RFC 9728 Section 4).

◆ pushed_authorization_request_endpoint

std::string_view sourcemeta::core::OAuthServerMetadataConfig::pushed_authorization_request_endpoint

The pushed authorization request endpoint (RFC 9126 Section 5). New members are kept at the end so an existing positional initializer keeps mapping to the older fields.

◆ require_pushed_authorization_requests

bool sourcemeta::core::OAuthServerMetadataConfig::require_pushed_authorization_requests {false}

Whether authorization request data is accepted only through the pushed authorization request endpoint, emitted only when true (RFC 9126 Section 5).

◆ token_endpoint_auth_signing_alg_values_supported

std::span<const std::string_view> sourcemeta::core::OAuthServerMetadataConfig::token_endpoint_auth_signing_alg_values_supported

The supported JWS algorithms for the private_key_jwt and client_secret_jwt token endpoint authentication methods (RFC 8414 Section 2). REQUIRED and must exclude none when either of those methods is advertised.

◆ sourcemeta::core::OAuthResourceMetadataConfig

struct sourcemeta::core::OAuthResourceMetadataConfig

The configuration a protected resource publishes as its metadata (RFC 9728 Section 2), each field a non-owning view. An empty scalar and a zero-element array are omitted, since RFC 9728 Section 3.2 forbids a zero-element array in the response. The one exception is the bearer method list, whose engaged empty state is emitted as an empty array, the form RFC 9728 Section 2 gives for a resource that supports no bearer method, distinct from the unspecified absent state.

Public Attributes

std::string_view resource
 The resource identifier (RFC 9728 Section 2), REQUIRED.
std::span< const std::string_view > authorization_servers
std::string_view jwks_uri
std::span< const std::string_view > scopes_supported
std::optional< std::span< const std::string_view > > bearer_methods_supported
std::span< const std::string_view > resource_signing_alg_values_supported
std::string_view resource_name
std::string_view resource_documentation
 The developer documentation page location (RFC 9728 Section 2).
std::string_view resource_policy_uri
 The data usage policy page location (RFC 9728 Section 2).
std::string_view resource_tos_uri
 The terms of service page location (RFC 9728 Section 2).
bool tls_client_certificate_bound_access_tokens {false}
std::span< const std::string_view > authorization_details_types_supported
 The supported authorization details types (RFC 9728 Section 2).
std::span< const std::string_view > dpop_signing_alg_values_supported
bool dpop_bound_access_tokens_required {false}

Member Data Documentation

◆ authorization_servers

std::span<const std::string_view> sourcemeta::core::OAuthResourceMetadataConfig::authorization_servers

The authorization server issuer identifiers that can issue tokens for the resource (RFC 9728 Section 2).

◆ bearer_methods_supported

std::optional<std::span<const std::string_view> > sourcemeta::core::OAuthResourceMetadataConfig::bearer_methods_supported

The supported bearer token presentation methods (RFC 9728 Section 2), where no value omits the member and an engaged empty list advertises that no bearer method is supported.

◆ dpop_bound_access_tokens_required

bool sourcemeta::core::OAuthResourceMetadataConfig::dpop_bound_access_tokens_required {false}

Whether the resource requires DPoP-bound access tokens, emitted only when true since the default when absent is false (RFC 9728 Section 2).

◆ dpop_signing_alg_values_supported

std::span<const std::string_view> sourcemeta::core::OAuthResourceMetadataConfig::dpop_signing_alg_values_supported

The supported JWS algorithms for validating DPoP proofs (RFC 9728 Section 2), which must exclude none and the MAC algorithms a proof may never use (RFC 9449 Section 4.2).

◆ jwks_uri

std::string_view sourcemeta::core::OAuthResourceMetadataConfig::jwks_uri

The JWK Set document location for the resource's own keys (RFC 9728 Section 2).

◆ resource_name

std::string_view sourcemeta::core::OAuthResourceMetadataConfig::resource_name

The human-readable name of the resource without a language tag (RFC 9728 Sections 2 and 2.1), a language-tagged variant assigned by the caller on the returned document.

◆ resource_signing_alg_values_supported

std::span<const std::string_view> sourcemeta::core::OAuthResourceMetadataConfig::resource_signing_alg_values_supported

The supported JWS algorithms for signing resource responses (RFC 9728 Section 2), which must exclude none.

◆ scopes_supported

std::span<const std::string_view> sourcemeta::core::OAuthResourceMetadataConfig::scopes_supported

The scopes used in authorization requests for the resource (RFC 9728 Section 2).

◆ tls_client_certificate_bound_access_tokens

bool sourcemeta::core::OAuthResourceMetadataConfig::tls_client_certificate_bound_access_tokens {false}

Whether the resource supports mutual-TLS certificate-bound access tokens, emitted only when true since the default when absent is false (RFC 9728 Section 2).

◆ sourcemeta::core::OAuthMetadataProvider

class sourcemeta::core::OAuthMetadataProvider

A long-lived, cached resolver of authorization server metadata (RFC 8414). It derives the well-known URL from an issuer, retrieves and validates the document through an injected transport, and caches it with a freshness-aware refresh. It is meant to be constructed once per issuer at startup, since a per-request instance defeats the caching. Reads take a snapshot, so a returned document is immune to a concurrent refresh. The kind must be an authorization server kind, either AuthorizationServer or an OpenID Connect configuration form, since a protected resource document is not an authorization server metadata document and would never validate. For example:

#include <sourcemeta/core/oauth.h>
#include <optional>
"https://example.com",
[](std::string_view) -> std::optional<
.body =
R"JSON({"issuer":"https://example.com",
"response_types_supported":["code"]})JSON",
.max_age = std::nullopt};
}};
const auto metadata{provider.metadata()};
auto metadata() -> std::shared_ptr< const OAuthServerMetadata >
Definition oauth_metadata_provider.h:53
@ AuthorizationServer
Definition oauth_metadata.h:24
Definition oauth_metadata_provider.h:59

Public Types

using Fetcher
using Clock = std::function<std::chrono::system_clock::time_point()>

Public Member Functions

 OAuthMetadataProvider (std::string issuer, const OAuthWellKnownKind kind, Fetcher fetcher)
 OAuthMetadataProvider (std::string issuer, const OAuthWellKnownKind kind, Fetcher fetcher, Options options)
 Construct a provider overriding the caching policy.
 OAuthMetadataProvider (std::string issuer, const OAuthWellKnownKind kind, Fetcher fetcher, Options options, Clock clock)
 Construct a provider overriding the policy and the clock.
 OAuthMetadataProvider (const OAuthMetadataProvider &)=delete
 OAuthMetadataProvider (OAuthMetadataProvider &&)=delete
auto metadata () -> std::shared_ptr< const OAuthServerMetadata >
auto refresh () -> std::shared_ptr< const OAuthServerMetadata >

Member Typedef Documentation

◆ Clock

using sourcemeta::core::OAuthMetadataProvider::Clock = std::function<std::chrono::system_clock::time_point()>

A source of the current time, defaulting to the system clock and existing as an injection point so the refresh can be driven deterministically under test.

◆ Fetcher

Initial value:
std::function<std::optional<FetchResult>(std::string_view url)>

A pluggable transport that turns a URL into raw metadata bytes plus an optional freshness hint. Returns no value on a failed retrieval, such as a transport error, an unsuccessful response, or an oversized body. Injecting the transport keeps this module free of any networking dependency and makes the provider substitutable for testing. A refresh runs the transport while holding the cache lock, which serializes concurrent refreshes and blocks other readers for its duration, though a forced refresh still retrieves once per call, so the transport must bound its own wait with a timeout.

Constructor & Destructor Documentation

◆ OAuthMetadataProvider() [1/2]

sourcemeta::core::OAuthMetadataProvider::OAuthMetadataProvider ( std::string issuer,
const OAuthWellKnownKind kind,
Fetcher fetcher )

Construct a provider for an issuer with an injected transport, using the default policy and the system clock.

◆ OAuthMetadataProvider() [2/2]

sourcemeta::core::OAuthMetadataProvider::OAuthMetadataProvider ( const OAuthMetadataProvider & )
delete

The provider owns a lock guarding its cache, so it is neither copyable nor movable. Store it behind a pointer or construct it in place.

Member Function Documentation

◆ metadata()

auto sourcemeta::core::OAuthMetadataProvider::metadata ( ) -> std::shared_ptr< const OAuthServerMetadata >
nodiscard

The cached metadata, retrieving it on the first call and refreshing it once its freshness lifetime has elapsed. A failed refresh keeps serving the last good document, and no value is returned only when the document has never been retrieved successfully. The result is a snapshot immune to a concurrent refresh.

◆ refresh()

auto sourcemeta::core::OAuthMetadataProvider::refresh ( ) -> std::shared_ptr< const OAuthServerMetadata >
nodiscard

Force an immediate retrieval regardless of freshness, serving the RFC 9728 Section 5.2 recommendation to re-retrieve on a challenge. A failed retrieval keeps the last good document.

◆ sourcemeta::core::OAuthResourceMetadataProvider

class sourcemeta::core::OAuthResourceMetadataProvider

A long-lived, cached resolver of protected resource metadata (RFC 9728), the resource-side counterpart of the authorization server provider. It derives the well-known URL from a resource identifier, retrieves and validates the document through an injected transport, and caches it with a freshness-aware refresh. It is meant to be constructed once per resource at startup, since a per-request instance defeats the caching. Reads take a snapshot, so a returned document is immune to a concurrent refresh. For example:

#include <sourcemeta/core/oauth.h>
#include <optional>
"https://api.example",
[](std::string_view) -> std::optional<
.body = R"JSON({"resource":"https://api.example",
"authorization_servers":["https://auth.example"]})JSON",
.max_age = std::nullopt};
}};
const auto metadata{provider.metadata()};
OAuthMetadataProvider::FetchResult FetchResult
Definition oauth_metadata_provider.h:171
auto metadata() -> std::shared_ptr< const OAuthResourceMetadata >
Definition oauth_metadata_provider.h:167

Public Types

using FetchResult = OAuthMetadataProvider::FetchResult
using Fetcher = OAuthMetadataProvider::Fetcher
using Clock = OAuthMetadataProvider::Clock
using Options = OAuthMetadataProvider::Options

Public Member Functions

 OAuthResourceMetadataProvider (std::string resource, Fetcher fetcher)
 OAuthResourceMetadataProvider (std::string resource, Fetcher fetcher, Options options)
 Construct a provider overriding the caching policy.
 OAuthResourceMetadataProvider (std::string resource, Fetcher fetcher, Options options, Clock clock)
 Construct a provider overriding the policy and the clock.
 OAuthResourceMetadataProvider (const OAuthResourceMetadataProvider &)=delete
 OAuthResourceMetadataProvider (OAuthResourceMetadataProvider &&)=delete
auto metadata () -> std::shared_ptr< const OAuthResourceMetadata >
auto refresh () -> std::shared_ptr< const OAuthResourceMetadata >

Member Typedef Documentation

◆ Clock

A source of the current time, shared with the authorization server provider.

◆ Fetcher

A pluggable transport that turns a URL into raw metadata bytes plus an optional freshness hint, shared with the authorization server provider.

◆ FetchResult

The outcome of one metadata retrieval, shared with the authorization server provider.

◆ Options

Tunables for the caching policy, shared with the authorization server provider.

Constructor & Destructor Documentation

◆ OAuthResourceMetadataProvider() [1/2]

sourcemeta::core::OAuthResourceMetadataProvider::OAuthResourceMetadataProvider ( std::string resource,
Fetcher fetcher )

Construct a provider for a resource with an injected transport, using the default policy and the system clock.

◆ OAuthResourceMetadataProvider() [2/2]

sourcemeta::core::OAuthResourceMetadataProvider::OAuthResourceMetadataProvider ( const OAuthResourceMetadataProvider & )
delete

The provider owns a lock guarding its cache, so it is neither copyable nor movable. Store it behind a pointer or construct it in place.

Member Function Documentation

◆ metadata()

auto sourcemeta::core::OAuthResourceMetadataProvider::metadata ( ) -> std::shared_ptr< const OAuthResourceMetadata >
nodiscard

The cached metadata, retrieving it on the first call and refreshing it once its freshness lifetime has elapsed. A failed refresh keeps serving the last good document, and no value is returned only when the document has never been retrieved successfully. The result is a snapshot immune to a concurrent refresh.

◆ refresh()

auto sourcemeta::core::OAuthResourceMetadataProvider::refresh ( ) -> std::shared_ptr< const OAuthResourceMetadata >
nodiscard

Force an immediate retrieval regardless of freshness, serving the RFC 9728 Section 5.2 recommendation to re-retrieve on a challenge. A failed retrieval keeps the last good document.

◆ sourcemeta::core::OAuthPARResponse

class sourcemeta::core::OAuthPARResponse

A non-owning view over a pushed authorization request response (RFC 9126 Section 2.2) held in a caller-owned JSON value, which must outlive the view. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
const auto document{sourcemeta::core::parse_json(R"JSON({
"request_uri": "urn:ietf:params:oauth:request_uri:6esc",
"expires_in": 60
})JSON")};
const sourcemeta::core::OAuthPARResponse response{document};
assert(response.request_uri().value() ==
"urn:ietf:params:oauth:request_uri:6esc");
auto request_uri() const -> std::optional< std::string_view >
Definition oauth_par.h:90

Public Member Functions

 OAuthPARResponse (const JSON &data)
auto request_uri () const -> std::optional< std::string_view >
auto expires_in () const -> std::optional< std::chrono::seconds >
auto data () const -> const JSON &
 The underlying document.

Constructor & Destructor Documentation

◆ OAuthPARResponse()

sourcemeta::core::OAuthPARResponse::OAuthPARResponse ( const JSON & data)
explicit

Construct a view over a pushed authorization request response, which is borrowed.

Member Function Documentation

◆ expires_in()

auto sourcemeta::core::OAuthPARResponse::expires_in ( ) const -> std::optional< std::chrono::seconds >
nodiscard

The lifetime of the request URI, no value when non-positive (RFC 9126 Section 2.2).

◆ request_uri()

auto sourcemeta::core::OAuthPARResponse::request_uri ( ) const -> std::optional< std::string_view >
nodiscard

The request URI to use at the authorization endpoint (RFC 9126 Section 2.2).

◆ sourcemeta::core::OAuthClientMetadata

class sourcemeta::core::OAuthClientMetadata

A dynamic client registration metadata document (RFC 7591 Section 2), owning its JSON. The same document is exchanged in both roles: a client's registration request (RFC 7591 Section 3.1) and the server's registration response (RFC 7591 Section 3.2.1), so the response-only members carry a value only when read over a response. The document is validated on construction to reject a jwks and jwks_uri present together, and a grant_types, response_types, or token_endpoint_auth_method present with the wrong type, since each of those carries a default an accessor would otherwise substitute (RFC 7591 Section 2). Accessors apply the specification defaults, and any member without a typed accessor, such as an internationalized name (RFC 7591 Section 2.2), is reachable through the underlying document. A string accessor returns a view into the owned document, valid for the lifetime of this object, so a view taken before the object is moved from must not be used afterward. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
auto document{sourcemeta::core::parse_json(R"JSON({
"client_id": "s6BhdRkqt3",
"redirect_uris": [ "https://client.example.org/callback" ],
"token_endpoint_auth_method": "client_secret_basic"
})JSON")};
const auto metadata{
assert(metadata.has_value());
assert(metadata.value().client_id().value() == "s6BhdRkqt3");
static auto from(JSON &&data) -> std::optional< OAuthClientMetadata >

Public Member Functions

 OAuthClientMetadata (JSON &&data)
auto has_redirect_uri (const std::string_view value) const -> bool
 Whether a redirection URI is registered (RFC 7591 Section 2).
auto token_endpoint_auth_method () const -> std::string_view
auto supports_grant_type (const std::string_view value) const -> bool
auto supports_response_type (const std::string_view value) const -> bool
auto client_name () const -> std::optional< std::string_view >
 The human-readable client name (RFC 7591 Section 2).
auto client_uri () const -> std::optional< std::string_view >
 The client information page (RFC 7591 Section 2).
auto logo_uri () const -> std::optional< std::string_view >
 The client logo location (RFC 7591 Section 2).
auto scope () const -> std::optional< std::string_view >
 The space-separated scopes the client may request (RFC 7591 Section 2).
auto has_contact (const std::string_view value) const -> bool
 Whether a contact is listed (RFC 7591 Section 2).
auto tos_uri () const -> std::optional< std::string_view >
 The terms of service page (RFC 7591 Section 2).
auto policy_uri () const -> std::optional< std::string_view >
 The privacy policy page (RFC 7591 Section 2).
auto jwks_uri () const -> std::optional< std::string_view >
 The JWK Set document location for the client's keys (RFC 7591 Section 2).
auto software_id () const -> std::optional< std::string_view >
auto software_version () const -> std::optional< std::string_view >
 The client software version (RFC 7591 Section 2).
auto software_statement () const -> std::optional< std::string_view >
auto client_id () const -> std::optional< std::string_view >
auto client_secret () const -> std::optional< std::string_view >
auto client_id_issued_at () const -> std::optional< std::chrono::seconds >
auto client_secret_expires_at () const -> std::optional< std::chrono::seconds >
auto registration_access_token () const -> std::optional< std::string_view >
auto registration_client_uri () const -> std::optional< std::string_view >
auto data () const -> const JSON &
 The underlying document, for reaching members without a typed accessor.

Static Public Member Functions

static auto from (JSON &&data) -> std::optional< OAuthClientMetadata >

Constructor & Destructor Documentation

◆ OAuthClientMetadata()

sourcemeta::core::OAuthClientMetadata::OAuthClientMetadata ( JSON && data)
explicit

Construct and validate a client registration document, throwing when it is invalid. The document is moved in.

Member Function Documentation

◆ client_id()

auto sourcemeta::core::OAuthClientMetadata::client_id ( ) const -> std::optional< std::string_view >
nodiscard

The issued client identifier, present only in a registration response (RFC 7591 Section 3.2.1).

◆ client_id_issued_at()

auto sourcemeta::core::OAuthClientMetadata::client_id_issued_at ( ) const -> std::optional< std::chrono::seconds >
nodiscard

The time the client identifier was issued, present only in a response (RFC 7591 Section 3.2.1).

◆ client_secret()

auto sourcemeta::core::OAuthClientMetadata::client_secret ( ) const -> std::optional< std::string_view >
nodiscard

The issued client secret, present only in a response to a confidential client (RFC 7591 Section 3.2.1).

◆ client_secret_expires_at()

auto sourcemeta::core::OAuthClientMetadata::client_secret_expires_at ( ) const -> std::optional< std::chrono::seconds >
nodiscard

The time the client secret expires, zero meaning it never expires, present only in a response that issued a secret (RFC 7591 Section 3.2.1).

◆ from()

auto sourcemeta::core::OAuthClientMetadata::from ( JSON && data) -> std::optional< OAuthClientMetadata >
staticnodiscard

Construct and validate a client registration document, returning no value when it is invalid. The document is moved in.

◆ registration_access_token()

auto sourcemeta::core::OAuthClientMetadata::registration_access_token ( ) const -> std::optional< std::string_view >
nodiscard

The registration access token for managing the registration, present only in a response when management is offered (RFC 7592 Section 3).

◆ registration_client_uri()

auto sourcemeta::core::OAuthClientMetadata::registration_client_uri ( ) const -> std::optional< std::string_view >
nodiscard

The registration management location, present only in a response when management is offered (RFC 7592 Section 3).

◆ software_id()

auto sourcemeta::core::OAuthClientMetadata::software_id ( ) const -> std::optional< std::string_view >
nodiscard

The client software identifier, stable across instances (RFC 7591 Section 2).

◆ software_statement()

auto sourcemeta::core::OAuthClientMetadata::software_statement ( ) const -> std::optional< std::string_view >
nodiscard

The software statement asserting the metadata, echoed unmodified in a response (RFC 7591 Section 2.3).

◆ supports_grant_type()

auto sourcemeta::core::OAuthClientMetadata::supports_grant_type ( const std::string_view value) const -> bool
nodiscard

Whether a grant type is registered, defaulting to the authorization code grant when absent (RFC 7591 Section 2).

◆ supports_response_type()

auto sourcemeta::core::OAuthClientMetadata::supports_response_type ( const std::string_view value) const -> bool
nodiscard

Whether a response type is registered, defaulting to the code response type when absent (RFC 7591 Section 2).

◆ token_endpoint_auth_method()

auto sourcemeta::core::OAuthClientMetadata::token_endpoint_auth_method ( ) const -> std::string_view
nodiscard

The requested token endpoint authentication method, defaulting to client_secret_basic when absent (RFC 7591 Section 2).

◆ sourcemeta::core::OAuthClientRegistrationConfig

struct sourcemeta::core::OAuthClientRegistrationConfig

The client metadata a registration request carries (RFC 7591 Section 2), each field a non-owning view. An empty scalar and a zero-element array are omitted.

Public Attributes

std::span< const std::string_view > redirect_uris
std::string_view token_endpoint_auth_method
std::span< const std::string_view > grant_types
 The grant types the client will use (RFC 7591 Section 2).
std::span< const std::string_view > response_types
 The response types the client will use (RFC 7591 Section 2).
std::string_view client_name
 The human-readable client name (RFC 7591 Section 2).
std::string_view client_uri
 The client information page (RFC 7591 Section 2).
std::string_view logo_uri
 The client logo location (RFC 7591 Section 2).
std::string_view scope
 The space-separated scopes the client may request (RFC 7591 Section 2).
std::span< const std::string_view > contacts
 The ways to contact those responsible for the client (RFC 7591 Section 2).
std::string_view tos_uri
 The terms of service page (RFC 7591 Section 2).
std::string_view policy_uri
 The privacy policy page (RFC 7591 Section 2).
std::string_view jwks_uri
const JSONjwks {nullptr}
std::string_view software_id
 The client software identifier (RFC 7591 Section 2).
std::string_view software_version
 The client software version (RFC 7591 Section 2).
std::string_view software_statement
 The software statement asserting the metadata (RFC 7591 Section 2.3).

Member Data Documentation

◆ jwks

const JSON* sourcemeta::core::OAuthClientRegistrationConfig::jwks {nullptr}

The client's JWK Set carried inline for a client that cannot host one, mutually exclusive with its location, a non-owning pointer left null when absent (RFC 7591 Section 2).

◆ jwks_uri

std::string_view sourcemeta::core::OAuthClientRegistrationConfig::jwks_uri

The JWK Set document location for the client's keys, mutually exclusive with an inline key set (RFC 7591 Section 2).

◆ redirect_uris

std::span<const std::string_view> sourcemeta::core::OAuthClientRegistrationConfig::redirect_uris

The redirection URIs the client registers for redirect-based flows (RFC 7591 Section 2).

◆ token_endpoint_auth_method

std::string_view sourcemeta::core::OAuthClientRegistrationConfig::token_endpoint_auth_method

The requested token endpoint authentication method, omitted to take the client_secret_basic default (RFC 7591 Section 2).

◆ sourcemeta::core::OAuthClientRegistrationResult

struct sourcemeta::core::OAuthClientRegistrationResult

The values an authorization server assigns to a client at registration (RFC 7591 Section 3.2.1) and for its management (RFC 7592 Section 3), each a non-owning view. The client identifier is REQUIRED, a secret and its expiry are emitted together, and the management pair is emitted when registration management is offered.

Public Attributes

std::string_view client_id
 The issued client identifier (RFC 7591 Section 3.2.1), REQUIRED.
std::string_view client_secret
std::optional< std::chrono::seconds > client_id_issued_at {}
 The time the client identifier was issued (RFC 7591 Section 3.2.1).
std::optional< std::chrono::seconds > client_secret_expires_at {}
std::string_view registration_access_token
std::string_view registration_client_uri

Member Data Documentation

◆ client_secret

std::string_view sourcemeta::core::OAuthClientRegistrationResult::client_secret

The issued client secret, present for a confidential client (RFC 7591 Section 3.2.1).

◆ client_secret_expires_at

std::optional<std::chrono::seconds> sourcemeta::core::OAuthClientRegistrationResult::client_secret_expires_at {}

The time the client secret expires, zero meaning it never expires, REQUIRED alongside a secret (RFC 7591 Section 3.2.1).

◆ registration_access_token

std::string_view sourcemeta::core::OAuthClientRegistrationResult::registration_access_token

The registration access token for managing the registration, REQUIRED together with the management location when management is offered (RFC 7592 Section 3).

◆ registration_client_uri

std::string_view sourcemeta::core::OAuthClientRegistrationResult::registration_client_uri

The registration management location, REQUIRED together with the access token when management is offered (RFC 7592 Section 3).

◆ sourcemeta::core::OAuthTokenLookupRequest

struct sourcemeta::core::OAuthTokenLookupRequest

A non-owning view of a token revocation or introspection request (RFC 7009 Section 2.1, RFC 7662 Section 2.1). The token borrows from the input or the decode arena, and an absent hint is an empty view.

Public Attributes

std::string_view token
 The token to act on (RFC 7009 Section 2.1).
std::string_view token_type_hint

Member Data Documentation

◆ token_type_hint

std::string_view sourcemeta::core::OAuthTokenLookupRequest::token_type_hint

The hint about the token type, one of the hint vocabulary values, empty when absent (RFC 7009 Section 2.1).

◆ sourcemeta::core::OAuthTokenRequest

struct sourcemeta::core::OAuthTokenRequest

A non-owning view of a token request at the authorization server (RFC 6749 Section 4.1.3, Section 4.4.2, Section 6). Every field borrows from the input or the decode arena, and an absent parameter is an empty view. The grant type is surfaced as its raw value so a server can tell a missing grant from an unsupported one.

Public Attributes

std::string_view grant_type
 The grant type (RFC 6749 Section 4.1.3).
std::string_view code
std::string_view redirect_uri
std::string_view code_verifier
 The PKCE code verifier (RFC 7636 Section 4.5).
std::string_view refresh_token
 The refresh token, for the refresh grant (RFC 6749 Section 6).
std::string_view scope
 The space-delimited requested scope (RFC 6749 Section 3.3).

Member Data Documentation

◆ code

std::string_view sourcemeta::core::OAuthTokenRequest::code

The authorization code, for the authorization code grant (RFC 6749 Section 4.1.3).

◆ redirect_uri

std::string_view sourcemeta::core::OAuthTokenRequest::redirect_uri

The redirection endpoint echoed for the authorization code grant (RFC 6749 Section 4.1.3), surfaced unconditionally.

◆ sourcemeta::core::OAuthTokenResponse

class sourcemeta::core::OAuthTokenResponse

A non-owning view over a token endpoint success response (RFC 6749 Section 5.1) held in a caller-owned JSON value. The value must outlive the view, and the token accessors return views into it, which are secret and must not be logged. Extension members such as an OpenID Connect id_token are reached through the underlying document. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
const auto document{sourcemeta::core::parse_json(
R"JSON({"access_token":"2YotnFZFEjr1zCsicMWpAA","token_type":"Bearer",
"expires_in":3600})JSON")};
const sourcemeta::core::OAuthTokenResponse response{document};
assert(response.is_bearer_token_type());
assert(response.access_token().value() == "2YotnFZFEjr1zCsicMWpAA");
auto is_bearer_token_type() const -> bool
auto access_token() const -> std::optional< std::string_view >
The issued access token (RFC 6749 Section 5.1), or no value when absent.
Definition oauth_token.h:166

Public Member Functions

 OAuthTokenResponse (const JSON &data)
 Construct a view over a token response document, which is borrowed.
auto access_token () const -> std::optional< std::string_view >
 The issued access token (RFC 6749 Section 5.1), or no value when absent.
auto token_type () const -> std::optional< std::string_view >
 The access token type (RFC 6749 Section 5.1), or no value when absent.
auto is_bearer_token_type () const -> bool
auto expires_in () const -> std::optional< std::chrono::seconds >
auto refresh_token () const -> std::optional< std::string_view >
 The issued refresh token (RFC 6749 Section 5.1), or no value when absent.
auto scope () const -> std::optional< std::string_view >
 The granted scope (RFC 6749 Section 5.1), or no value when absent.
auto has_scope (const std::string_view value) const -> bool
auto data () const -> const JSON &

Member Function Documentation

◆ data()

auto sourcemeta::core::OAuthTokenResponse::data ( ) const -> const JSON &
nodiscard

The underlying document, for reaching extension members such as an OpenID Connect id_token.

◆ expires_in()

auto sourcemeta::core::OAuthTokenResponse::expires_in ( ) const -> std::optional< std::chrono::seconds >
nodiscard

The access token lifetime in seconds (RFC 6749 Section 5.1), or no value when absent or not a non-negative integer.

◆ has_scope()

auto sourcemeta::core::OAuthTokenResponse::has_scope ( const std::string_view value) const -> bool
nodiscard

Whether the granted scope contains a value, comparing the space-delimited unordered set (RFC 6749 Section 3.3).

◆ is_bearer_token_type()

auto sourcemeta::core::OAuthTokenResponse::is_bearer_token_type ( ) const -> bool
nodiscard

Whether the token type is Bearer, matched case insensitively (RFC 6749 Section 5.1).

◆ sourcemeta::core::OAuthTokenGrant

struct sourcemeta::core::OAuthTokenGrant

The token a server grants, for building a token endpoint success response (RFC 6749 Section 5.1). Every field borrows from the caller, an empty scalar is omitted, and the two scope fields decide whether a scope is emitted.

Public Attributes

std::string_view access_token
 The issued access token (RFC 6749 Section 5.1).
std::string_view token_type
 The token type, such as Bearer (RFC 6749 Section 7.1).
std::optional< std::chrono::seconds > expires_in
std::string_view refresh_token
 The issued refresh token, omitted when absent (RFC 6749 Section 5.1).
std::string_view scope
std::string_view requested_scope

Member Data Documentation

◆ expires_in

std::optional<std::chrono::seconds> sourcemeta::core::OAuthTokenGrant::expires_in

The lifetime of the access token, omitted when absent (RFC 6749 Section 5.1).

◆ requested_scope

std::string_view sourcemeta::core::OAuthTokenGrant::requested_scope

The scope the client requested, used to decide whether the granted scope must be emitted (RFC 6749 Section 5.1).

◆ scope

std::string_view sourcemeta::core::OAuthTokenGrant::scope

The granted scope (RFC 6749 Section 3.3). A scope has at least one token, so an empty granted scope is not representable and is not emitted. A server that would grant no scopes denies the request instead of issuing a token with an empty scope.

◆ sourcemeta::core::OAuthTokenExchangeRequest

struct sourcemeta::core::OAuthTokenExchangeRequest

The parameters of a token exchange request (RFC 8693 Section 2.1). Every field is a non-owning view, an empty scalar is omitted, and the spans carry the repeatable audience and resource indicator values, each emitted under its fixed parameter name.

Public Attributes

std::string_view subject_token
std::string_view subject_token_type
 The type of the subject token, REQUIRED (RFC 8693 Section 2.1).
std::string_view actor_token
std::string_view actor_token_type
 The type of the actor token, emitted only together with the actor token.
std::string_view requested_token_type
 The requested type for the issued token (RFC 8693 Section 2.1).
std::string_view scope
 The space-delimited requested scope (RFC 6749 Section 3.3).
std::span< const std::string_view > audiences
std::span< const std::string_view > resources

Member Data Documentation

◆ actor_token

std::string_view sourcemeta::core::OAuthTokenExchangeRequest::actor_token

The security token that represents the acting party, emitted only together with its type (RFC 8693 Section 2.1).

◆ audiences

std::span<const std::string_view> sourcemeta::core::OAuthTokenExchangeRequest::audiences

The repeatable logical audience names of the target service, each emitted as an audience parameter (RFC 8693 Section 2.1).

◆ resources

std::span<const std::string_view> sourcemeta::core::OAuthTokenExchangeRequest::resources

The repeatable resource indicators, each an absolute URI without a fragment emitted as a resource parameter (RFC 8707 Section 2).

◆ subject_token

std::string_view sourcemeta::core::OAuthTokenExchangeRequest::subject_token

The security token that represents the subject, REQUIRED (RFC 8693 Section 2.1).

◆ sourcemeta::core::OAuthTransactionSecrets

struct sourcemeta::core::OAuthTransactionSecrets

The secrets minted for one authorization code flow, each the base64url encoding of 32 random octets. Both are secret and are serialized by the caller, such as into a sealed cookie, and wiped once the flow completes. The 43 bytes of each are not null terminated.

Public Attributes

std::array< char, 43 > state
 The cross-site request forgery token (RFC 6749 Section 10.12).
std::array< char, 43 > code_verifier
 The PKCE code verifier (RFC 7636 Section 4.1).

◆ sourcemeta::core::OAuthTransaction

struct sourcemeta::core::OAuthTransaction

A non-owning view of the state a client retains between an authorization request and its callback. Every field borrows from the caller and must outlive any use of this struct.

Public Attributes

std::string_view state
 The state sent with the request, compared against the callback.
std::string_view code_verifier
 The PKCE code verifier, carried through to the token request.
std::string_view issuer
 The issuer identifier the request was sent to (RFC 9207 Section 2).
std::string_view redirect_uri
 The redirection URI the request was sent with (RFC 8252 Section 8.10).

Enumeration Type Documentation

◆ OAuthAssertionError

enum class sourcemeta::core::OAuthAssertionError : std::uint8_t
strong

The reason a JWT bearer assertion failed verification (RFC 7523 Section 3).

Enumerator
Malformed 

The assertion was not a well-formed JSON Web Token.

UnsupportedAlgorithm 

The algorithm was absent or outside the accepted set (RFC 7523 Section 5).

UnknownKey 

No key verified the signature.

Signature 

The signature did not verify.

Issuer 

The issuer claim was absent or did not match (RFC 7523 Section 3 check 1).

Subject 

The subject claim was absent or did not match (RFC 7523 Section 3 check 2, RFC 7521 Section 4.2).

Audience 

The audience claim did not identify this server (RFC 7523 Section 3 check 3).

Expired 

The assertion has expired (RFC 7523 Section 3 check 4).

NotYetValid 

The assertion is not yet valid (RFC 7523 Section 3 check 5).

IssuedInFuture 

The issue time lies in the future (RFC 7523 Section 3 check 6).

Replay 

The identifier was already seen within its window, a replay (RFC 7523 Section 3 check 7).

◆ OAuthAuthorizationError

enum class sourcemeta::core::OAuthAuthorizationError : std::uint8_t
strong

The error codes an authorization endpoint returns in its redirect (RFC 6749 Section 4.1.2.1).

Enumerator
InvalidRequest 

The request is missing a parameter, includes an invalid value, or is otherwise malformed.

UnauthorizedClient 

The client is not authorized to request a code using this method.

AccessDenied 

The resource owner or authorization server denied the request.

UnsupportedResponseType 

The authorization server does not support this response type.

InvalidScope 

The requested scope is invalid, unknown, or malformed.

ServerError 

The authorization server encountered an unexpected condition.

TemporarilyUnavailable 

The authorization server is temporarily unable to handle the request.

◆ OAuthBearerError

enum class sourcemeta::core::OAuthBearerError : std::uint8_t
strong

The error codes a protected resource returns in its WWW-Authenticate challenge (RFC 6750 Section 3.1), shared by the Bearer and DPoP schemes.

Enumerator
InvalidRequest 

The request is malformed (RFC 6750 Section 3.1).

InvalidToken 

The access token is expired, revoked, malformed, or otherwise invalid (RFC 6750 Section 3.1).

InsufficientScope 

The token does not carry the scope the request requires (RFC 6750 Section 3.1).

InvalidDPoPProof 

The DPoP proof accompanying the request is missing or invalid, returned only under the DPoP scheme (RFC 9449 Section 7.1).

UseDPoPNonce 

The request must be retried with a DPoP proof that carries a nonce the resource server supplies, returned only under the DPoP scheme (RFC 9449 Section 9).

◆ OAuthCallbackError

enum class sourcemeta::core::OAuthCallbackError : std::uint8_t
strong

The reason a callback was rejected, in the order the checks run. The first failing check decides the outcome (RFC 9700 Section 4).

Enumerator
State 

The state is missing or does not match, a possible cross-site request forgery (RFC 6749 Section 10.12).

ReceivedURI 

The callback arrived on a URI other than the one the request was sent with (RFC 8252 Section 8.10).

Issuer 

The iss is missing when required or does not match the expected issuer, a possible mix-up attack (RFC 9207 Section 2.4).

Declined 

The authorization server returned an error rather than a code (RFC 6749 Section 4.1.2.1).

MissingCode 

The response carries neither an error nor a code.

◆ OAuthClientAuthenticationMethod

enum class sourcemeta::core::OAuthClientAuthenticationMethod : std::uint8_t
strong

The client authentication mechanism a token request presented (RFC 6749 Section 2.3). Public is a bare client identifier with no secret, which is identification rather than an authentication mechanism (RFC 6749 Section 3.2.1).

Enumerator
None 

No client authentication and no identifier were presented.

Basic 

An HTTP Basic credential (RFC 6749 Section 2.3.1).

Post 

A client_secret in the request body (RFC 6749 Section 2.3.1).

Public 

A bare client_id in the request body, identifying a public client (RFC 6749 Section 3.2.1).

Assertion 

A client_assertion and its type (RFC 7521 Section 4.2).

◆ OAuthDevicePollDecision

enum class sourcemeta::core::OAuthDevicePollDecision : std::uint8_t
strong

What a device flow client does after a token endpoint error (RFC 8628 Section 3.5).

Enumerator
Continue 

Keep polling at the current interval.

RetryWithNonce 

The request needs a fresh DPoP nonce, so the client re-issues the proof with the server-supplied nonce and polls again without growing the interval (RFC 9449 Section 8).

Denied 

The end user denied the request.

Expired 

The codes expired before approval.

Error 

A terminal error other than pending, slow down, denial, expiry, or a nonce requirement.

◆ OAuthDPoPError

enum class sourcemeta::core::OAuthDPoPError : std::uint8_t
strong

The reason a DPoP proof failed verification (RFC 9449 Section 4.3), one per check performed, with a missing nonce kept distinct from a mismatched one because a server resupplies a nonce for the former (RFC 9449 Section 9).

Enumerator
ProofCount 

More or fewer than one DPoP header field was present (check 1).

Malformed 

The header value was not a single well-formed JSON Web Token (check 2).

MissingClaim 

A required header parameter or claim was absent (check 3).

UnexpectedType 

The token type header parameter was not dpop+jwt (check 4).

UnsupportedAlgorithm 

The algorithm was absent, symmetric, or outside the accepted set (check 5).

PrivateKey 

The embedded key carried private material (check 7).

Signature 

The signature did not verify with the embedded key (check 6).

MethodMismatch 

The method claim did not match the request method (check 8).

TargetMismatch 

The target claim did not match the request target (check 9).

MissingNonce 

A nonce was required but absent, the downgrade the server must reject (check 10, RFC 9449 Section 11.3).

NonceMismatch 

The nonce claim did not match the nonce the server issued (check 10).

Expired 

The creation time was outside the acceptable window (check 11).

AccessTokenMismatch 

The access token hash was absent or did not match the presented token (check 12).

KeyMismatch 

The proof key did not match the key the access token is bound to, or a token was presented with no binding to confirm it against (check 12).

◆ OAuthIssuerSupport

enum class sourcemeta::core::OAuthIssuerSupport : std::uint8_t
strong

Whether the authorization server is known to support the iss response parameter (RFC 9207 Section 2.4). This governs how a callback missing iss is treated.

Enumerator
Supported 

The server supports iss, so a callback missing it is rejected.

NotSupported 

The server is known not to support iss, so a present iss is ignored.

Unknown 

Support is unknown, so iss is validated only when present.

◆ OAuthPKCEMethod

enum class sourcemeta::core::OAuthPKCEMethod : std::uint8_t
strong

The PKCE code challenge transformation method (RFC 7636 Section 4.2).

Enumerator
S256 

The SHA-256 transformation, the only method the strict profile permits (RFC 7636 Section 4.2).

Plain 

The identity transformation, permitted only under the compatible profile (RFC 7636 Section 4.2).

◆ OAuthPKCEOutcome

enum class sourcemeta::core::OAuthPKCEOutcome : std::uint8_t
strong

The result of verifying a PKCE code verifier against a stored code challenge. Only Match and NotUsed let the exchange proceed. The remaining outcomes each name a distinct pairing failure the token endpoint rejects (RFC 7636 Section 4.6, RFC 9700 Section 2.1.1, OAuth 2.1 Section 4.1.3).

Enumerator
Match 

The verifier corresponds to the challenge.

NotUsed 

Neither a challenge nor a verifier is present, so PKCE was not used. The caller decides separately whether its profile required it.

MissingVerifier 

A challenge is stored but no verifier was presented (OAuth 2.1 Section 4.1.3).

MissingChallenge 

A verifier was presented but no challenge is stored, which signals a possible authorization code injection (RFC 9700 Section 2.1.1).

Mismatch 

Both are present, well formed, and permitted, but the verifier does not correspond to the challenge (RFC 7636 Section 4.6).

MethodNotAllowed 

The stored method is plain under the strict profile (RFC 9700 Section 2.1.1).

MalformedVerifier 

The presented verifier is not a valid code verifier (RFC 7636 Section 4.1).

MalformedChallenge 

The stored challenge violates the code challenge syntax, either the wrong length for its method or a character outside the allowed set (RFC 7636 Section 4.2). A syntactically valid challenge that simply does not correspond to the verifier is a Mismatch, not this.

◆ OAuthProfile

enum class sourcemeta::core::OAuthProfile : std::uint8_t
strong

The behavioural profile a parser or validator runs under. Strict applies the OAuth 2.1 and RFC 9700 hardening, and Compatible relaxes it for RFC 6749 interoperability where a specification still permits the older behaviour. For example:

#include <sourcemeta/core/oauth.h>
@ Strict
Definition oauth_profile.h:27
Enumerator
Strict 

The default, selecting the OAuth 2.1 and RFC 9700 hardening. Each function that takes a profile applies the part of that hardening it governs. Today that is the PKCE method check, where the strict profile rejects plain.

Compatible 

Selects the RFC 6749 behaviours the strict profile refuses, for interoperability with deployments that predate the hardening.

◆ OAuthRegistrationError

enum class sourcemeta::core::OAuthRegistrationError : std::uint8_t
strong

The error codes a dynamic client registration endpoint returns (RFC 7591 Section 3.2.2).

Enumerator
InvalidRedirectURI 

A redirect URI in the request is invalid.

InvalidClientMetadata 

A field in the client metadata is invalid.

InvalidSoftwareStatement 

The software statement is invalid.

UnapprovedSoftwareStatement 

The software statement is not approved by the authorization server.

◆ OAuthResponseMode

enum class sourcemeta::core::OAuthResponseMode : std::uint8_t
strong

The mechanism used for returning authorization response parameters from the authorization endpoint (OAuth 2.0 Multiple Response Types Section 2.1, OAuth 2.0 Form Post Response Mode Section 2).

Enumerator
Query 

Parameters are "encoded in the query string added to the redirect_uri when redirecting back to the Client" (OAuth 2.0 Multiple Response Types Section 2.1).

Fragment 

Parameters are "encoded in the fragment added to the redirect_uri when redirecting back to the Client" (OAuth 2.0 Multiple Response Types Section 2.1).

FormPost 

Parameters are "encoded as HTML form values that are auto-submitted in the User Agent" with the HTTP POST method (OAuth 2.0 Form Post Response Mode Section 2).

◆ OAuthRevocationOutcome

enum class sourcemeta::core::OAuthRevocationOutcome : std::uint8_t
strong

The outcome a client draws from a token revocation response (RFC 7009 Section 2.2).

Enumerator
Success 

The revocation succeeded, which an unknown token also produces (RFC 7009 Section 2.2).

Retry 

The server is temporarily unable to respond and the request may be retried, honoring any Retry-After (RFC 7009 Section 2.2.1).

Error 

The request failed, and the body carries a token endpoint error code (RFC 7009 Section 2.2.1).

◆ OAuthTokenError

enum class sourcemeta::core::OAuthTokenError : std::uint8_t
strong

The error codes a token endpoint returns (RFC 6749 Section 5.2), extended with the codes the device grant, resource indicators, token exchange, DPoP, and token revocation add to the same endpoint family.

Enumerator
InvalidRequest 

The request is missing a parameter, includes an unsupported value, or is otherwise malformed (RFC 6749 Section 5.2).

InvalidClient 

Client authentication failed (RFC 6749 Section 5.2).

InvalidGrant 

The grant or refresh token is invalid, expired, revoked, or mismatched (RFC 6749 Section 5.2).

UnauthorizedClient 

The authenticated client is not authorized to use this grant type (RFC 6749 Section 5.2).

UnsupportedGrantType 

The grant type is not supported by the authorization server (RFC 6749 Section 5.2).

InvalidScope 

The requested scope is invalid, unknown, or exceeds the grant (RFC 6749 Section 5.2).

AuthorizationPending 

The device authorization is still pending user approval (RFC 8628 Section 3.5).

SlowDown 

The client is polling too frequently and must slow down (RFC 8628 Section 3.5).

AccessDenied 

The end user denied the device authorization request (RFC 8628 Section 3.5).

ExpiredToken 

The device code expired before the user approved it (RFC 8628 Section 3.5).

InvalidTarget 

The requested resource or audience is invalid or unknown (RFC 8707 Section 2, RFC 8693 Section 2.2.2).

InvalidDPoPProof 

The DPoP proof is missing or invalid (RFC 9449 Section 5).

UseDPoPNonce 

The authorization server requires the client to use a DPoP nonce (RFC 9449 Section 8).

UnsupportedTokenType 

The token type is not supported by the revocation endpoint (RFC 7009 Section 2.2.1).

◆ OAuthWellKnownKind

enum class sourcemeta::core::OAuthWellKnownKind : std::uint8_t
strong

The kind of metadata document a well-known URL points at, which selects the suffix and whether it is inserted before the path or appended after it.

Enumerator
AuthorizationServer 

The oauth-authorization-server document, inserted before the path (RFC 8414 Section 3).

ProtectedResource 

The oauth-protected-resource document, inserted before the path (RFC 9728 Section 3).

OpenIDConfigurationInserted 

The openid-configuration document, inserted before the path (RFC 8414 Section 5).

OpenIDConfigurationAppended 

The openid-configuration document, appended after the path, the legacy OpenID Connect Discovery form (RFC 8414 Section 5).

Function Documentation

◆ oauth_apply_software_statement_claims()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_apply_software_statement_claims ( JSON & metadata,
const JSON & claims ) -> bool
nodiscard

Flatten the claims of a trusted software statement onto a registration record (RFC 7591 Section 3.1.1), returning false when the record or the claims are not a JSON object. A statement claim takes precedence over a directly supplied value of the same name, so it overwrites it, while the JSON Web Token structural claims (RFC 7519 Section 4.1) and the statement member itself are left out since they describe the statement rather than the client. Pass the claims a trusted statement was verified to carry. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
auto record{sourcemeta::core::parse_json(R"JSON({
"client_name": "Requested Name"
})JSON")};
const auto claims{sourcemeta::core::parse_json(R"JSON({
"iss": "https://statement-issuer.example",
"client_name": "Attested Name"
})JSON")};
assert(record.at("client_name").to_string() == "Attested Name");
assert(!record.defines("iss"));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_apply_software_statement_claims(JSON &metadata, const JSON &claims) -> bool

◆ oauth_bearer_error_status()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_bearer_error_status ( const OAuthBearerError error) -> HTTPStatus
noexcept

The HTTP status a protected resource returns for a bearer error, as the SHOULD-level recommendation of RFC 6750 Section 3.1: 400 for a malformed request, 401 for an invalid token, and 403 for insufficient scope. The DPoP resource codes accompany a 401 (RFC 9449 Section 7). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
403);
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_bearer_error_status(const OAuthBearerError error) noexcept -> HTTPStatus
@ InsufficientScope
Definition oauth_error.h:97

◆ oauth_bearer_header()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_bearer_header ( const std::string_view token,
std::string & sink ) -> bool

Append a Bearer credential (RFC 6750 Section 2.1) for an access token to the sink, returning whether the token is a well-formed b64token. Nothing is appended when it is not. The sink then holds the access token, which is secret, so a caller that keeps it should use wiping storage. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
std::string header;
assert(sourcemeta::core::oauth_bearer_header("mF_9.B5f-4.1JqM", header));
assert(header == "Bearer mF_9.B5f-4.1JqM");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_bearer_header(const std::string_view token, std::string &sink) -> bool

◆ oauth_build_assertion()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::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 >
nodiscard

Build a JWT bearer assertion (RFC 7523 Section 3) signed with the given key and algorithm, carrying the issuer, subject, and a single audience, an expiration a lifetime past the given time, an issue time, and a random identifier, or no value when the key cannot sign. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/jose.h>
#include <chrono>
#include <cassert>
assert(key.has_value());
"issuer", "subject", "https://server.example/token",
std::chrono::seconds{300}, std::chrono::system_clock::now(),
assert(assertion.has_value());
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 >

◆ oauth_build_authorization_error_form_post()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_error_form_post ( const std::string_view redirect_uri,
const OAuthAuthorizationResponse & response,
std::string & sink,
const std::string_view title = "Submit This Form" ) -> bool

Build the auto-submitting HTML page of a failed authorization response in the form post response mode (OAuth 2.0 Form Post Response Mode Section 2, RFC 6749 Section 4.1.2.1), returning whether it was produced, with the same validation as the error redirect builder and the page carrying the given title. The redirect URI, the response fields, and the title must not alias the sink. When serving the page, the authorization server "MUST instruct the User Agent (and any intermediaries) not to store or reuse the content of the response". For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
response.error = "access_denied";
std::string page;
"https://client.example/cb", response, page));
assert(page.find("access_denied") != std::string::npos);
std::string_view error
The error code of a failure response (RFC 6749 Section 4.1.2.1).
Definition oauth_authorization.h:205
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_authorization_error_form_post(const std::string_view redirect_uri, const OAuthAuthorizationResponse &response, std::string &sink, const std::string_view title="Submit This Form") -> bool
Definition oauth_authorization.h:197

◆ oauth_build_authorization_error_redirect() [1/2]

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_error_redirect ( const std::string_view redirect_uri,
const OAuthAuthorizationResponse & response,
const OAuthResponseMode mode,
std::string & sink ) -> bool

Build a failed authorization redirect at the authorization server in the given response mode (RFC 6749 Section 4.1.2.1, OAuth 2.0 Multiple Response Types Section 2.1), returning whether it was produced. The form post mode produces no value, as it emits an HTML page rather than a redirect. Every other behavior matches the query-only builder. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
response.error = "access_denied";
std::string url;
"https://client.example/cb", response,
assert(url == "https://client.example/cb#error=access_denied");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_authorization_error_redirect(const std::string_view redirect_uri, const OAuthAuthorizationResponse &response, std::string &sink) -> bool
@ Fragment
Definition oauth_authorization.h:311

◆ oauth_build_authorization_error_redirect() [2/2]

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_error_redirect ( const std::string_view redirect_uri,
const OAuthAuthorizationResponse & response,
std::string & sink ) -> bool

Build a failed authorization redirect at the authorization server (RFC 6749 Section 4.1.2.1), returning whether it was produced. The Error is required, error_description, error_uri, and state are emitted when present, and an iss is emitted when present and must be a valid issuer identifier (RFC 9207 Section 2). This must not be called when the redirect URI or client identifier failed validation, since the error is then shown to the resource owner rather than redirected. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
response.state = "xyz";
response.error = "access_denied";
std::string url;
"https://client.example/cb", response, url));
assert(url ==
"https://client.example/cb?error=access_denied&state=xyz");
std::string_view state
The state value echoed from the request (RFC 6749 Section 4.1.2).
Definition oauth_authorization.h:201

◆ oauth_build_authorization_form_post()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_form_post ( const std::string_view redirect_uri,
const OAuthAuthorizationResponse & response,
std::string & sink,
const std::string_view title = "Submit This Form" ) -> bool

Build the auto-submitting HTML page of a successful authorization response in the form post response mode (OAuth 2.0 Form Post Response Mode Section 2), returning whether it was produced. The action of the form is the client's redirection endpoint, the response parameters are the hidden form values, and the page carries the given title, with the same validation as the redirect builder. The redirect URI, the response fields, and the title must not alias the sink. When serving the page, the authorization server "MUST instruct the User Agent (and any intermediaries) not to store or reuse the content of the response". For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
response.code = "SplxlOBeZQQYbYS6WxSbIA";
std::string page;
"https://client.example/cb", response, page));
assert(page.find("<form method=\"post\"") != std::string::npos);
std::string_view code
The authorization code (RFC 6749 Section 4.1.2).
Definition oauth_authorization.h:199
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_authorization_form_post(const std::string_view redirect_uri, const OAuthAuthorizationResponse &response, std::string &sink, const std::string_view title="Submit This Form") -> bool

◆ oauth_build_authorization_redirect() [1/2]

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_redirect ( const std::string_view redirect_uri,
const OAuthAuthorizationResponse & response,
const OAuthResponseMode mode,
std::string & sink ) -> bool

Build a successful authorization redirect at the authorization server in the given response mode, encoding the parameters in the query (RFC 6749 Section 4.1.2) or in the fragment (OAuth 2.0 Multiple Response Types Section 2.1) of the client's redirection endpoint, returning whether it was produced. The form post mode produces no value, as it emits an HTML page rather than a redirect. Every other behavior matches the query-only builder. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
response.code = "SplxlOBeZQQYbYS6WxSbIA";
std::string url;
"https://client.example/cb", response,
assert(url == "https://client.example/cb#code=SplxlOBeZQQYbYS6WxSbIA");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_authorization_redirect(const std::string_view redirect_uri, const OAuthAuthorizationResponse &response, std::string &sink) -> bool

◆ oauth_build_authorization_redirect() [2/2]

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_redirect ( const std::string_view redirect_uri,
const OAuthAuthorizationResponse & response,
std::string & sink ) -> bool

Build a successful authorization redirect at the authorization server by appending the query to the client's redirection endpoint (RFC 6749 Section 4.1.2), returning whether it was produced. The code is required, state is echoed when present, and an iss is emitted when present and must be a valid issuer identifier (RFC 9207 Section 2). No value is produced when the redirect URI contains a fragment, which a redirection endpoint must not (RFC 6749 Section 3.1.2). Every value is percent-escaped, an existing query on the endpoint is honored, and the sink is appended to and never cleared. The redirect URI and the response fields must not alias the sink. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
response.code = "SplxlOBeZQQYbYS6WxSbIA";
response.state = "xyz";
std::string url;
"https://client.example/cb", response, url));
assert(url == "https://client.example/cb?code=SplxlOBeZQQYbYS6WxSbIA"
"&state=xyz");

◆ oauth_build_authorization_url()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_authorization_url ( const std::string_view endpoint,
const OAuthAuthorizationRequest & request,
std::string & sink ) -> void

Build an authorization request URL by appending the query to the endpoint (RFC 6749 Section 4.1.1). The response_type defaults to code and is honored when set, every value is percent-escaped, an existing query on the endpoint is honored, and the code challenge method is emitted only when a challenge is present. The sink is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
request.client_id = "s6BhdRkqt3";
request.redirect_uri = "https://client.example/cb";
std::string url;
"https://server.example/authorize", request, url);
assert(url ==
"https://server.example/authorize?response_type=code"
"&client_id=s6BhdRkqt3&redirect_uri=https%3A%2F%2Fclient.example%2Fcb");
std::string_view redirect_uri
Definition oauth_authorization.h:63

◆ oauth_build_challenge()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_challenge ( const std::string_view scheme,
const OAuthChallenge & challenge,
std::string & sink ) -> bool

Build a WWW-Authenticate challenge for a scheme and append it to the sink, returning whether a challenge was produced (RFC 7235 Section 4.1). Each present parameter is emitted as a quoted-string with the double quote and backslash escaped (RFC 9110 Section 5.6.4). A challenge with no parameter yields a bare scheme, which RFC 7235 Section 2.1 permits and a DPoP challenge may use (RFC 9449 Section 7.1), so the Bearer scheme's own rule that it carry at least one parameter (RFC 6750 Section 3) is the caller's responsibility. Nothing is appended and false is returned only when the scheme is not a token or a value carries a control character that would allow header injection. Only header safety is enforced, so keeping each value within the tighter character set its own attribute defines (RFC 6750 Section 3) is likewise the caller's responsibility. It is a pure function, so a resource server builds its fixed challenge once and caches it. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
challenge.realm = "example";
challenge.error = "invalid_token";
std::string header;
sourcemeta::core::oauth_build_challenge("Bearer", challenge, header);
assert(header == R"(Bearer realm="example", error="invalid_token")");
std::string_view error
The error code (RFC 6750 Section 3.1).
Definition oauth_bearer.h:70
std::string_view realm
The protection space the credentials apply to (RFC 6750 Section 3).
Definition oauth_bearer.h:66
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_challenge(const std::string_view scheme, const OAuthChallenge &challenge, std::string &sink) -> bool
Definition oauth_bearer.h:64

◆ oauth_build_client_assertion()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::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 >
nodiscard

Build a JWT bearer client authentication assertion (RFC 7523 Section 3), a self-issued assertion whose issuer and subject are both the client identifier (RFC 7521 Section 5.2), or no value when the key cannot sign. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/jose.h>
#include <chrono>
#include <cassert>
assert(key.has_value());
"s6BhdRkqt3", "https://server.example/token", std::chrono::seconds{300},
std::chrono::system_clock::now(), key.value(),
assert(assertion.has_value());
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 >

◆ oauth_build_device_authorization_request()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_device_authorization_request ( const std::string_view client_id,
const std::string_view scope,
const std::span< const OAuthParameter > resources,
std::string & sink ) -> void

Append a device authorization request body (RFC 8628 Section 3.1) to the sink. The client_id is required for a public client, the scope is emitted when present, and the repeatable resources follow. This request has no secret, so the sink is an ordinary string, appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
std::string body;
"1406020730", "read", {}, body);
assert(body == "client_id=1406020730&scope=read");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_device_authorization_request(const std::string_view client_id, const std::string_view scope, const std::span< const OAuthParameter > resources, std::string &sink) -> void

◆ oauth_build_introspection_request()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_introspection_request ( const std::string_view token,
const std::string_view token_type_hint,
SecureString & sink ) -> void

Append a token introspection request body (RFC 7662 Section 2.1) to the sink. The token is required, and the token_type_hint is emitted only when present. The authorization the endpoint requires is supplied separately, since RFC 7662 Section 2.1 mandates it but does not fix the method. The token is secret, so the sink is a wiping string, and it is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"mF_9.B5f-4.1JqM", "", body);
assert(body == "token=mF_9.B5f-4.1JqM");
Definition crypto_secure.h:162
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_introspection_request(const std::string_view token, const std::string_view token_type_hint, SecureString &sink) -> void

◆ oauth_build_par_authorization_url()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_par_authorization_url ( const std::string_view endpoint,
const std::string_view client_id,
const std::string_view request_uri,
std::string & sink ) -> void

Append the front-channel authorization request URL (RFC 9126 Section 4) to the sink, the reference form carrying only the client_id and the request_uri obtained from the pushed authorization request endpoint. Unlike a full authorization request it emits no response_type, since the pushed request holds it. For example:

#include <sourcemeta/core/oauth.h>
#include <string>
#include <cassert>
std::string url;
"https://server.example/authorize", "s6BhdRkqt3",
"urn:ietf:params:oauth:request_uri:6esc", url);
assert(url ==
"https://server.example/authorize?client_id=s6BhdRkqt3&request_uri="
"urn%3Aietf%3Aparams%3Aoauth%3Arequest_uri%3A6esc");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_par_authorization_url(const std::string_view endpoint, const std::string_view client_id, const std::string_view request_uri, std::string &sink) -> void

◆ oauth_build_par_request()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_par_request ( const OAuthAuthorizationRequest & request,
SecureString & sink ) -> void

Append a pushed authorization request body (RFC 9126 Section 2.1) to the sink. Every authorization request parameter is emitted except the request_uri, which a pushed request MUST NOT carry, and the client_id, which client authentication supplies, in the body for a public client or the client_secret_post method and in the Authorization header for the client_secret_basic method. The response_type defaults to the authorization code flow. The body may carry a client secret, so the sink is a wiping string, appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
request.redirect_uri = "https://client.example/cb";
request.scope = "read";
assert(std::string_view{body}.starts_with("response_type=code"));
std::string_view scope
The space-delimited requested scope (RFC 6749 Section 3.3).
Definition oauth_authorization.h:65
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_par_request(const OAuthAuthorizationRequest &request, SecureString &sink) -> void
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_client_id_only(const std::string_view client_id, SecureString &sink) -> void

◆ oauth_build_revocation_request()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_revocation_request ( const std::string_view token,
const std::string_view token_type_hint,
SecureString & sink ) -> void

Append a token revocation request body (RFC 7009 Section 2.1) to the sink. The token is required, and the token_type_hint is emitted only when present. No client_id is emitted, so the caller composes a client authentication builder into the same sink. The token is secret, so the sink is a wiping string, and it is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"45ghiukldjahdnhzdauz", "", body);
assert(body == "token=45ghiukldjahdnhzdauz");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_revocation_request(const std::string_view token, const std::string_view token_type_hint, SecureString &sink) -> void

◆ oauth_build_token_request_client_credentials()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_client_credentials ( const std::string_view scope,
const std::span< const OAuthParameter > resources,
SecureString & sink ) -> void

Append a client credentials grant token request body (RFC 6749 Section 4.4.2) to the sink. The requested scope is emitted only when present. No client_id is emitted, so the caller composes a client authentication builder into the same sink. The sink is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
body);
assert(body == "grant_type=client_credentials&scope=read");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_client_credentials(const std::string_view scope, const std::span< const OAuthParameter > resources, SecureString &sink) -> void

◆ oauth_build_token_request_code()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_code ( const std::string_view code,
const std::string_view redirect_uri,
const std::string_view code_verifier,
const std::span< const OAuthParameter > resources,
SecureString & sink ) -> void

Append an authorization code grant token request body (RFC 6749 Section 4.1.3) to the sink. The code is required, the redirect_uri is emitted only when the authorization request carried one, and the code_verifier is emitted only when PKCE is in use (RFC 7636 Section 4.5). No client_id is emitted, so the caller composes a client authentication builder into the same sink. The body carries secrets, so the sink is a wiping string, and it is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"SplxlOBeZQQYbYS6WxSbIA", "https://client.example/cb", "", {}, body);
assert(body == "grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA"
"&redirect_uri=https%3A%2F%2Fclient.example%2Fcb");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_code(const std::string_view code, const std::string_view redirect_uri, const std::string_view code_verifier, const std::span< const OAuthParameter > resources, SecureString &sink) -> void

◆ oauth_build_token_request_device()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_device ( const std::string_view device_code,
const std::span< const OAuthParameter > resources,
SecureString & sink ) -> void

Append a device grant token request body (RFC 8628 Section 3.4) to the sink. The device_code is required, and the repeatable resources follow. No client_id is emitted, so the caller composes a client authentication builder into the same sink. The device code is a credential, so the sink is a wiping string, appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS", {}, body);
assert(body == "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3A"
"device_code"
"&device_code=GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_device(const std::string_view device_code, const std::span< const OAuthParameter > resources, SecureString &sink) -> void

◆ oauth_build_token_request_exchange()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_exchange ( const OAuthTokenExchangeRequest & request,
SecureString & sink ) -> bool

Append a token exchange request body (RFC 8693 Section 2.1) to the sink, returning whether it is well formed. The grant_type is the token exchange URN, the subject token and its type are required, the actor token and its type are emitted only together, and the repeatable audiences and resources follow. No client_id is emitted, so the caller composes a client authentication builder into the same sink. The body carries a secret token, so the sink is a wiping string, and it is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
request.subject_token = "accVkjcJyb4BWCxGsndESCJQbdFMogUC5PbRDqceLTC";
std::string_view subject_token_type
The type of the subject token, REQUIRED (RFC 8693 Section 2.1).
Definition oauth_token_exchange.h:52
std::string_view subject_token
Definition oauth_token_exchange.h:50
constexpr std::string_view OAUTH_TOKEN_TYPE_ACCESS_TOKEN
Definition oauth_token_exchange.h:19
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_exchange(const OAuthTokenExchangeRequest &request, SecureString &sink) -> bool
Definition oauth_token_exchange.h:47

◆ oauth_build_token_request_jwt_bearer()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_jwt_bearer ( const std::string_view assertion,
const std::string_view scope,
SecureString & sink ) -> void

Append a JWT bearer authorization grant token request body (RFC 7523 Section 2.1) to the sink, the grant type, the assertion, and the scope when present. No client_id is emitted, so the caller composes a client authentication builder into the same sink when the client authenticates. The assertion is a credential, so the sink is a wiping string, appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
body);
assert(std::string_view{body}.starts_with("grant_type="));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_jwt_bearer(const std::string_view assertion, const std::string_view scope, SecureString &sink) -> void

◆ oauth_build_token_request_refresh()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_build_token_request_refresh ( const std::string_view refresh_token,
const std::string_view scope,
const std::span< const OAuthParameter > resources,
SecureString & sink ) -> void

Append a refresh token grant token request body (RFC 6749 Section 6) to the sink. The refresh_token is required, and the requested scope is emitted only when present and must not exceed the original grant. No client_id is emitted, so the caller composes a client authentication builder into the same sink. The body carries secrets, so the sink is a wiping string, and it is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"read", {}, body);
assert(body == "grant_type=refresh_token"
"&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA&scope=read");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_build_token_request_refresh(const std::string_view refresh_token, const std::string_view scope, const std::span< const OAuthParameter > resources, SecureString &sink) -> void

◆ oauth_challenge_parameter()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_challenge_parameter ( const std::string_view header,
const std::string_view scheme,
const std::string_view name ) -> std::optional< std::string >

Find the value of one authentication parameter within the challenge for a scheme in a WWW-Authenticate header value (RFC 7235 Section 4.1), returning no value when the scheme or parameter is absent, or the header is malformed before the parameter is reached. The scheme and parameter name are matched case insensitively, and a quoted-string value is unescaped (RFC 9110 Section 5.6.4). The full grammar is parsed so that adjacent challenges and parameters are told apart correctly. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
R"(Bearer realm="example", error="invalid_token")", "Bearer", "realm")};
assert(realm.has_value());
assert(realm.value() == "example");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_challenge_parameter(const std::string_view header, const std::string_view scheme, const std::string_view name) -> std::optional< std::string >

◆ oauth_client_assertion()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_client_assertion ( const std::string_view assertion,
SecureString & sink ) -> void

Append the client authentication assertion parameters (RFC 7521 Section 4.2) to the sink, the assertion and its JWT bearer type. No client_id is emitted, since the client is identified by the assertion subject. The assertion is a credential, so the sink is a wiping string, appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(std::string_view{body}.starts_with("client_assertion_type="));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_client_assertion(const std::string_view assertion, SecureString &sink) -> void

◆ oauth_client_id_only()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_client_id_only ( const std::string_view client_id,
SecureString & sink ) -> void

Append a public client identification parameter (RFC 6749 Section 3.2.1) to a token request body, emitting the identifier alone with no secret. This composes into the same sink as a grant builder. The sink is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(body == "client_id=s6BhdRkqt3");

◆ oauth_client_secret_basic()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_client_secret_basic ( const std::string_view client_id,
const std::string_view client_secret,
SecureString & sink ) -> void

Append an HTTP Basic authentication credential (RFC 6749 Section 2.3.1) to the sink, for use as an Authorization header value. The client identifier and secret are each percent-encoded, joined with a colon, and Base64 encoded. The credential is secret, so the sink is a wiping string, and it is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
header);
assert(header == "Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_client_secret_basic(const std::string_view client_id, const std::string_view client_secret, SecureString &sink) -> void

◆ oauth_client_secret_post()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_client_secret_post ( const std::string_view client_id,
const std::string_view client_secret,
SecureString & sink ) -> void

Append the client_secret_post client authentication parameters (RFC 6749 Section 2.3.1) to a token request body. Both the identifier and the secret are emitted, so this composes into the same sink as a grant builder. The body carries a secret, so the sink is a wiping string, and it is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(body == "client_id=id&client_secret=secret");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_client_secret_post(const std::string_view client_id, const std::string_view client_secret, SecureString &sink) -> void

◆ oauth_default_response_mode()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_default_response_mode ( const std::string_view response_type) -> std::optional< OAuthResponseMode >

Look up the default response mode of a response type (OAuth 2.0 Multiple Response Types Sections 2.1, 3, 4, and 5), returning no value unless the response type is registered. The response type "is compared as a space-delimited list of values in which the order of values does not matter" (Section 1.2). The lookup covers every registered response type, including token-bearing ones whose successful response this module does not encode, since requests are still built and response modes still negotiated for them. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(mode.has_value());
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_default_response_mode(const std::string_view response_type) -> std::optional< OAuthResponseMode >
@ Query
Definition oauth_authorization.h:307

◆ oauth_device_user_code()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_device_user_code ( ) -> std::array< char, 8 >

Mint a device flow user code, eight characters from the RFC 8628 Section 6.1 recommended twenty-character alphabet, drawn with rejection sampling for a uniform distribution. The code is shown to the end user, not kept secret. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(code.size() == 8);
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_device_user_code() -> std::array< char, 8 >

◆ oauth_device_user_code_matches()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_device_user_code_matches ( const std::string_view presented,
const std::string_view stored ) -> bool

Whether a user code the end user typed matches a stored one, comparing after discarding every non-alphanumeric character and folding to uppercase, so the separators and case a user adds do not matter (RFC 8628 Section 6.1). The final comparison is constant time. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"WDJBMJHT"));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_device_user_code_matches(const std::string_view presented, const std::string_view stored) -> bool

◆ oauth_dpop_confirmation()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_dpop_confirmation ( const std::string_view thumbprint) -> JSON
nodiscard

Build the confirmation value that binds an access token to a DPoP key (RFC 9449 Section 6.1), for a server to assign under the cnf claim of a JSON Web Token access token or a top-level cnf of a token introspection response (RFC 9449 Section 6.2). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"0ZcOCORZNYy-DWpqq30jZyJGHTN0d2HglBV3uiguA4I")};
assert(confirmation.at("jkt").to_string() ==
"0ZcOCORZNYy-DWpqq30jZyJGHTN0d2HglBV3uiguA4I");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_dpop_confirmation(const std::string_view thumbprint) -> JSON

◆ oauth_dpop_proof_thumbprint()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_dpop_proof_thumbprint ( const std::string_view proof) -> std::optional< std::string >
nodiscard

The JSON Web Key thumbprint of the key a DPoP proof is signed with (RFC 9449 Section 6.1), the value a server matches against an authorization code binding (RFC 9449 Section 10) or binds an issued token to, or no value when the proof or its embedded key cannot be read. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
const auto thumbprint{sourcemeta::core::oauth_dpop_proof_thumbprint(proof)};
assert(!thumbprint.has_value() || !thumbprint.value().empty());
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_dpop_proof_thumbprint(const std::string_view proof) -> std::optional< std::string >

◆ oauth_dpop_verify()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::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 >
nodiscard

Verify a DPoP proof against the request it accompanies (RFC 9449 Section 4.3), returning the first failing check or no value when every check passes. The checks are run in a fixed order though the specification permits any order, and replay is a separate concern the caller enforces after this passes. For example:

#include <sourcemeta/core/oauth.h>
#include <chrono>
#include <cassert>
proof, "POST", "https://server.example.com/token",
std::chrono::system_clock::now(), options)};
assert(!error.has_value() ||
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 >
@ Expired
The creation time was outside the acceptable window (check 11).
Definition oauth_dpop.h:173
Definition oauth_dpop.h:187

◆ oauth_error_code() [1/4]

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_error_code ( const OAuthAuthorizationError error) -> std::string_view
noexcept

The wire code for an authorization endpoint error (RFC 6749 Section 4.1.2.1). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"access_denied");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_error_code(const OAuthAuthorizationError error) noexcept -> std::string_view
@ AccessDenied
The resource owner or authorization server denied the request.
Definition oauth_error.h:27

◆ oauth_error_code() [2/4]

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_error_code ( const OAuthBearerError error) -> std::string_view
noexcept

The wire code for a protected resource challenge error (RFC 6750 Section 3.1). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"invalid_token");
@ InvalidToken
Definition oauth_error.h:94

◆ oauth_error_code() [3/4]

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_error_code ( const OAuthRegistrationError error) -> std::string_view
noexcept

The wire code for a dynamic client registration error (RFC 7591 Section 3.2.2). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"invalid_redirect_uri");
@ InvalidRedirectURI
A redirect URI in the request is invalid.
Definition oauth_error.h:112

◆ oauth_error_code() [4/4]

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_error_code ( const OAuthTokenError error) -> std::string_view
noexcept

The wire code for a token endpoint error (RFC 6749 Section 5.2 and its extensions). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"invalid_grant");
@ InvalidGrant
Definition oauth_error.h:50

◆ oauth_has_audience()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_has_audience ( const JSON & claims,
const std::string_view audience ) -> bool

Whether a set of access token claims names an audience, so that a resource server accepts only a token minted for it (RFC 9068 Section 4, RFC 7662 Section 2.2). The claims are the payload of a JWT access token or an introspection response, and the aud claim is honored whether it is a single string or an array of strings. Each value is treated as an opaque case-sensitive string (RFC 7519 Section 4.1.3) and compared by code points (RFC 3986 Section 6.2.1), with no normalization. An empty audience never matches. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
const auto claims{
sourcemeta::core::parse_json(R"JSON({"aud":"https://api.example"})JSON")};
assert(sourcemeta::core::oauth_has_audience(claims, "https://api.example"));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_has_audience(const JSON &claims, const std::string_view audience) -> bool

◆ oauth_has_scope()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_has_scope ( const JSON & claims,
const std::string_view value ) -> bool

Whether a set of access token claims grants a scope, so that a resource server admits only a caller whose token carries it (RFC 6749 Section 3.3, RFC 9068 Section 2.2.3, RFC 7662 Section 2.2). The claims are the payload of a JWT access token or an introspection response, and the scope claim is a single string of space-delimited case-sensitive tokens compared whole and by code points, with no normalization. An empty scope never matches. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
const auto claims{
sourcemeta::core::parse_json(R"JSON({"scope":"read write"})JSON")};
assert(sourcemeta::core::oauth_has_scope(claims, "read"));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_has_scope(const JSON &claims, const std::string_view value) -> bool

◆ oauth_is_dpop_bound()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_dpop_bound ( const JSON & claims) -> bool

Whether a set of access token claims carries the DPoP confirmation that binds the token to a proof-of-possession key, namely a jkt JWK thumbprint (RFC 9449 Section 6.1). A resource server that receives such a token under the Bearer scheme must reject it, since a key-bound token stripped of its proof is being replayed (RFC 9449 Section 7.2). Only the DPoP confirmation is detected, not other sender-constraining methods such as mutual-TLS. The claims are the payload of a JWT access token or an introspection response. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
const auto claims{sourcemeta::core::parse_json(
R"JSON({"cnf":{"jkt":"0ZcOCORZNYy-DWpqq30jZyJGHTN0d2HglBV3uiguA4I"}})JSON")};
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_is_dpop_bound(const JSON &claims) -> bool

◆ oauth_is_endpoint_url()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_endpoint_url ( const std::string_view value) -> bool

Whether a URL is usable as an endpoint a client sends requests to: the https scheme, compared case-insensitively per RFC 3986 Section 3.1, a non-empty host, and no fragment, which RFC 6749 Section 3.1 forbids on an endpoint. A query is permitted. This is the rule the metadata parsers apply, named for the endpoint case rather than as a general https test, since the fragment prohibition comes from the endpoint specifications and does not hold of https URLs at large. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(sourcemeta::core::oauth_is_endpoint_url("https://example.com/token"));
assert(!sourcemeta::core::oauth_is_endpoint_url("http://example.com/token"));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_is_endpoint_url(const std::string_view value) -> bool

◆ oauth_is_issuer_identifier()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_issuer_identifier ( const std::string_view value) -> bool

Whether a value is a valid authorization server issuer identifier: the https scheme by exact code points, a non-empty host, and no query or fragment (RFC 8414 Section 2). This is the rule the metadata builders apply to issuer and to authorization_servers entries, so a caller assembling a document can pre-filter with it. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"https://auth.example.com/tenant"));
"https://auth.example.com/?tenant=1"));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_is_issuer_identifier(const std::string_view value) -> bool

◆ oauth_is_private_use_scheme()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_private_use_scheme ( const std::string_view scheme) -> bool
noexcept

Whether a URI scheme is a private-use scheme suitable for a native app redirect, a reverse-domain name that must contain at least one period (RFC 8252 Section 7.1 and Section 8.4). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_is_private_use_scheme(const std::string_view scheme) noexcept -> bool

◆ oauth_is_resource_identifier()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_resource_identifier ( const std::string_view value) -> bool

Whether a value is a valid protected resource identifier: the https scheme by exact code points, a non-empty host, and no fragment, a query tolerated (RFC 9728 Section 1.2, RFC 8707 Section 2). This is the rule the resource metadata builder and parser apply, so a caller assembling a document can pre-filter with it. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"https://api.example.com/mcp?tenant=1"));
"http://api.example.com/mcp"));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_is_resource_identifier(const std::string_view value) -> bool

◆ oauth_is_response_mode_allowed()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_response_mode_allowed ( const std::string_view response_type,
const OAuthResponseMode mode ) -> bool

Check whether a response mode may encode the response of a response type, as "in no case should a set of Authorization Response parameters whose default Response Mode is the fragment encoding be encoded using the query encoding" (OAuth 2.0 Multiple Response Types Section 7). An unknown response type allows no mode. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_is_response_mode_allowed(const std::string_view response_type, const OAuthResponseMode mode) -> bool

◆ oauth_is_valid_dpop_nonce()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_is_valid_dpop_nonce ( const std::string_view value) -> bool
nodiscardnoexcept

Whether a value is a well-formed DPoP nonce, a non-empty string of the nonce character set (RFC 9449 Section 8.1, RFC 6749 Appendix A), so a client validates a received nonce before echoing it. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(sourcemeta::core::oauth_is_valid_dpop_nonce("eyJ7S_zG.eyJH0-Z.HX4w"));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_is_valid_dpop_nonce(const std::string_view value) noexcept -> bool

◆ oauth_issued_token_type()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_issued_token_type ( const JSON & response) -> std::optional< std::string_view >

The type of the token a token exchange response issued (RFC 8693 Section 2.2.1), or no value when absent. The result borrows from the response, which must outlive it. It is REQUIRED on a successful response, so its absence marks a malformed one. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
const auto document{sourcemeta::core::parse_json(R"JSON({
"access_token": "eyJ...", "token_type": "Bearer",
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token"
})JSON")};
assert(sourcemeta::core::oauth_issued_token_type(document).value() ==
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_issued_token_type(const JSON &response) -> std::optional< std::string_view >

◆ oauth_make_device_authorization_response()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_device_authorization_response ( const std::string_view device_code,
const std::string_view user_code,
const std::string_view verification_uri,
const std::string_view verification_uri_complete,
const std::chrono::seconds expires_in,
const std::chrono::seconds interval ) -> std::optional< JSON >

Build a device authorization response document (RFC 8628 Section 3.2), returning no value when a required part is missing: an empty device code, user code, or verification URI, or a non-positive expires_in, which is a REQUIRED positive lifetime. The verification URI complete is emitted when present, and the interval only when it is positive and differs from the default, so a client never sees a zero or negative polling delay. For example:

#include <sourcemeta/core/oauth.h>
#include <chrono>
#include <cassert>
const auto
"GmRh", "WDJB-MJHT", "https://example.com/device", "",
std::chrono::seconds{1800}, std::chrono::seconds{5})};
assert(response.value().at("user_code").to_string() == "WDJB-MJHT");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_device_authorization_response(const std::string_view device_code, const std::string_view user_code, const std::string_view verification_uri, const std::string_view verification_uri_complete, const std::chrono::seconds expires_in, const std::chrono::seconds interval) -> std::optional< JSON >

◆ oauth_make_introspection_inactive()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_introspection_inactive ( ) -> JSON

Build the minimal inactive introspection response { "active": false } (RFC 7662 Section 2.2). The minimality is a recommendation, while the field value is the requirement, so a caller may add members. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(!response.at("active").to_boolean());
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_introspection_inactive() -> JSON

◆ oauth_make_par_response()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_par_response ( const std::string_view request_uri,
const std::chrono::seconds expires_in ) -> std::optional< JSON >
nodiscard

Build a pushed authorization request response document (RFC 9126 Section 2.2), returning no value when the request URI is empty or the lifetime is non-positive, which is a REQUIRED positive value. For example:

#include <sourcemeta/core/oauth.h>
#include <chrono>
#include <cassert>
"urn:ietf:params:oauth:request_uri:6esc", std::chrono::seconds{60})};
assert(response.value().at("expires_in").to_integer() == 60);
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_par_response(const std::string_view request_uri, const std::chrono::seconds expires_in) -> std::optional< JSON >

◆ oauth_make_registration_error_response()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_registration_error_response ( const std::string_view error,
const std::string_view error_description ) -> JSON
nodiscard

Build a dynamic client registration error response body (RFC 7591 Section 3.2.2). The error is the wire error code, and the description is emitted only when present. The caller serializes the object as the application/json response body. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"The grant types are inconsistent with the response types")};
assert(body.at("error").to_string() == "invalid_client_metadata");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_registration_error_response(const std::string_view error, const std::string_view error_description) -> JSON
@ InvalidClientMetadata
A field in the client metadata is invalid.
Definition oauth_error.h:114

◆ oauth_make_registration_request()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_registration_request ( const OAuthClientRegistrationConfig & config) -> std::optional< JSON >
nodiscard

Build a dynamic client registration request body (RFC 7591 Section 3.1), returning no value when a present client_uri, logo_uri, tos_uri, policy_uri, jwks_uri, or redirection URI is not a valid URI, or an inline key set is not a JSON object or is given together with its location. Each present scalar and each non-empty array is emitted. The caller serializes the object as the application/json request body. For example:

#include <sourcemeta/core/oauth.h>
#include <array>
#include <cassert>
#include <string_view>
const std::array<std::string_view, 1> redirect_uris{
{"https://client.example.org/callback"}};
config.redirect_uris = redirect_uris;
config.client_name = "My Example Client";
const auto body{
assert(body.has_value());
assert(body.value().at("client_name").to_string() == "My Example Client");
std::span< const std::string_view > redirect_uris
Definition oauth_registration.h:165
std::string_view client_name
The human-readable client name (RFC 7591 Section 2).
Definition oauth_registration.h:174
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_registration_request(const OAuthClientRegistrationConfig &config) -> std::optional< JSON >
Definition oauth_registration.h:162

◆ oauth_make_registration_response()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_registration_response ( const JSON & metadata,
const OAuthClientRegistrationResult & result ) -> std::optional< JSON >
nodiscard

Build a dynamic client registration response body (RFC 7591 Section 3.2.1 and RFC 7592 Section 3) by returning the registered metadata with the server-assigned values overlaid, or no value when the client identifier is empty, only one of the secret and its expiry is given, a time is negative, only one of the management access token and location is given, or the management location is not a valid URI. The server-assigned members come only from the assigned values, never from the accepted record. The caller serializes the object as the application/json response body. For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
const auto metadata{sourcemeta::core::parse_json(R"JSON({
"redirect_uris": [ "https://client.example.org/callback" ]
})JSON")};
result.client_id = "s6BhdRkqt3";
const auto body{
assert(body.has_value());
assert(body.value().at("client_id").to_string() == "s6BhdRkqt3");
std::string_view client_id
The issued client identifier (RFC 7591 Section 3.2.1), REQUIRED.
Definition oauth_registration.h:317
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_registration_response(const JSON &metadata, const OAuthClientRegistrationResult &result) -> std::optional< JSON >
Definition oauth_registration.h:315

◆ oauth_make_registration_update_request()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_registration_update_request ( const OAuthClientRegistrationConfig & config,
const std::string_view client_id,
const std::string_view client_secret ) -> std::optional< JSON >
nodiscard

Build a dynamic client registration update request body (RFC 7592 Section 2.2), a full replacement of the client's metadata that MUST carry the current client identifier and MAY carry the current secret to match against, returning no value when the client identifier is empty or a URL field is not a valid URI. Every metadata field is emitted as in a registration request, and the four server-assigned members are excluded since the request MUST NOT carry them. An omitted field is a request to delete it, since the update replaces rather than augments. The caller serializes the object as the application/json request body. For example:

#include <sourcemeta/core/oauth.h>
#include <array>
#include <cassert>
#include <string_view>
const std::array<std::string_view, 1> redirect_uris{
{"https://client.example.org/callback"}};
config.redirect_uris = redirect_uris;
config.client_name = "My New Example";
config, "s6BhdRkqt3", "")};
assert(body.has_value());
assert(body.value().at("client_id").to_string() == "s6BhdRkqt3");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_registration_update_request(const OAuthClientRegistrationConfig &config, const std::string_view client_id, const std::string_view client_secret) -> std::optional< JSON >

◆ oauth_make_resource_metadata()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_resource_metadata ( const OAuthResourceMetadataConfig & config) -> std::optional< JSON >

Build a protected resource metadata document for the well-known endpoint (RFC 9728 Section 2), returning no value when the document would be unusable: the resource is not a valid resource identifier, an authorization server entry is not a valid issuer identifier, the JWK Set location is not a valid https URL, a human-readable page location is not a URL, the resource signing algorithm list contains none, or the DPoP algorithm list contains none or a MAC algorithm. Every produced document parses back through its own consumer for the same resource. For example:

#include <sourcemeta/core/oauth.h>
#include <array>
#include <cassert>
#include <string_view>
const std::array<std::string_view, 1> servers{{"https://auth.example.com"}};
config.resource = "https://api.example.com";
config.authorization_servers = servers;
assert(document.has_value());
assert(document.value().at("resource").to_string() ==
"https://api.example.com");
std::span< const std::string_view > authorization_servers
Definition oauth_metadata.h:447
std::string_view resource
The resource identifier (RFC 9728 Section 2), REQUIRED.
Definition oauth_metadata.h:444
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_resource_metadata(const OAuthResourceMetadataConfig &config) -> std::optional< JSON >
Definition oauth_metadata.h:442

◆ oauth_make_server_metadata()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_server_metadata ( const OAuthServerMetadataConfig & config) -> std::optional< JSON >

Build an authorization server metadata document for the well-known endpoint (RFC 8414 Section 2), returning no value when the document would be unusable: the issuer is not a valid issuer identifier, the required response types are empty, the required authorization endpoint or (unless only the implicit grant is offered) token endpoint is missing, any advertised endpoint or JWK Set location is not a valid https URL, the signing algorithm list contains none, or a JWT token endpoint authentication method is advertised without a non-empty signing algorithm list. Each present scalar and each non-empty array is emitted, and a zero-element array is omitted (RFC 8414 Section 3.2). For example:

#include <sourcemeta/core/oauth.h>
#include <array>
#include <cassert>
#include <string_view>
const std::array<std::string_view, 1> response_types{{"code"}};
config.issuer = "https://server.example";
config.response_types_supported = response_types;
const auto document{sourcemeta::core::oauth_make_server_metadata(config)};
assert(document.has_value());
assert(document.value().at("issuer").to_string() ==
"https://server.example");
std::span< const std::string_view > response_types_supported
The supported response types (RFC 8414 Section 2), REQUIRED and non-empty.
Definition oauth_metadata.h:375
std::string_view issuer
The issuer identifier (RFC 8414 Section 2), REQUIRED.
Definition oauth_metadata.h:365
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_server_metadata(const OAuthServerMetadataConfig &config) -> std::optional< JSON >
Definition oauth_metadata.h:363

◆ oauth_make_token_error_response()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_token_error_response ( const std::string_view error,
const std::string_view error_description,
const std::string_view error_uri ) -> JSON

Build a token endpoint error response document (RFC 6749 Section 5.2). The error code is always emitted, and the description and URI when present. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"invalid_grant", "", "")};
assert(response.at("error").to_string() == "invalid_grant");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_token_error_response(const std::string_view error, const std::string_view error_description, const std::string_view error_uri) -> JSON

◆ oauth_make_token_response()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_make_token_response ( const OAuthTokenGrant & grant) -> JSON

Build a token endpoint success response document (RFC 6749 Section 5.1). The access token and token type are always emitted, the lifetime and refresh token when present, and the scope only when it differs from the requested scope, which is when it is REQUIRED (RFC 6749 Section 5.1). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
grant.access_token = "2YotnFZFEjr1zCsicMWpAA";
grant.token_type = "Bearer";
const auto response{sourcemeta::core::oauth_make_token_response(grant)};
assert(response.at("token_type").to_string() == "Bearer");
std::string_view access_token
The issued access token (RFC 6749 Section 5.1).
Definition oauth_token.h:209
std::string_view token_type
The token type, such as Bearer (RFC 6749 Section 7.1).
Definition oauth_token.h:211
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_make_token_response(const OAuthTokenGrant &grant) -> JSON
Definition oauth_token.h:207

◆ oauth_par_dpop_binding()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_par_dpop_binding ( const std::string_view dpop_jkt,
const std::optional< std::string_view > proof_thumbprint ) -> std::optional< std::string_view >
nodiscard

Reconcile the two ways a DPoP key is communicated at the pushed authorization request endpoint (RFC 9449 Section 10.1): the dpop_jkt parameter and the thumbprint of a verified DPoP header proof. Returns the effective thumbprint to bind the authorization code to, an empty view when neither is present, or no value when both are present and disagree, which the server MUST reject. The returned view borrows from the arguments. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(sourcemeta::core::oauth_par_dpop_binding("abc", "abc").value() ==
"abc");
assert(!sourcemeta::core::oauth_par_dpop_binding("abc", "xyz").has_value());
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_par_dpop_binding(const std::string_view dpop_jkt, const std::optional< std::string_view > proof_thumbprint) -> std::optional< std::string_view >

◆ oauth_par_request_uri()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_par_request_uri ( ) -> std::string
nodiscard

Mint a request URI reference for a pushed authorization request response (RFC 9126 Section 2.2), the urn:ietf:params:oauth:request_uri form with a cryptographically strong random reference so a value cannot be guessed (RFC 9126 Section 7.1). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
const auto request_uri{sourcemeta::core::oauth_par_request_uri()};
assert(request_uri.starts_with("urn:ietf:params:oauth:request_uri:"));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_par_request_uri() -> std::string

◆ oauth_parse_authorization_request()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_authorization_request ( const std::string_view query,
std::string & storage,
OAuthAuthorizationRequest & result,
const std::function< void(std::string_view, std::string_view)> & on_other ) -> bool

Parse the query of an authorization request at the authorization server (RFC 6749 Section 4.1.1) into the result, returning whether it is well formed. Each recognized value is form-decoded, borrowing from the input when it carries no escape and otherwise from the storage arena, which the caller owns and reuses across parses. A duplicated parameter is a failure (RFC 6749 Section 3.1), and code_challenge_method defaults to plain when a challenge is present without one (RFC 7636 Section 4.3). Every repeatable resource and every unrecognized parameter is passed to the callback with its decoded value rather than stored on the result, so the caller collects them. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
std::string storage;
"response_type=code&client_id=s6BhdRkqt3", storage, request,
[](std::string_view, std::string_view) {}));
assert(request.response_type == "code");
assert(request.client_id == "s6BhdRkqt3");
std::string_view response_type
Definition oauth_authorization.h:84
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_parse_authorization_request(const std::string_view query, std::string &storage, OAuthAuthorizationRequest &result, const std::function< void(std::string_view, std::string_view)> &on_other) -> bool

◆ oauth_parse_authorization_response()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_authorization_response ( const std::string_view query,
std::string & storage,
OAuthAuthorizationResponse & result ) -> bool

Parse the query of an authorization response (RFC 6749 Section 4.1.2) into the result, returning whether the query is well formed. Each recognized value is form-decoded (RFC 6749 Appendix B), borrowing from the input when it carries no escape and otherwise from the storage arena, which the caller owns and which is reused across parses. A duplicated recognized parameter is a failure, and an unrecognized parameter is ignored. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
std::string storage;
"code=SplxlOBeZQQYbYS6WxSbIA&state=xyz", storage, response));
assert(response.code == "SplxlOBeZQQYbYS6WxSbIA");
assert(response.state == "xyz");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_parse_authorization_response(const std::string_view query, std::string &storage, OAuthAuthorizationResponse &result) -> bool

◆ oauth_parse_client_authentication()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_client_authentication ( const std::string_view authorization,
const std::string_view body,
SecureString & storage,
OAuthClientCredentials & credentials ) -> bool

Parse the client authentication a token request presented, from the Authorization header value and the request body, into the credentials (RFC 6749 Section 2.3). Returns whether the presentation is well formed. It is malformed when more than one mechanism is presented (RFC 6749 Section 2.3, RFC 7521 Section 4.2.1), when a Basic username conflicts with a body client_id (RFC 6749 Section 5.2), when the Basic credential is not a canonical Base64 of a colon-separated pair, or when only one of the assertion parameters is present. The caller chooses the error code for a rejection, which is invalid_client when a collision involves the assertion mechanism (RFC 7521 Section 4.2.1) and invalid_request otherwise (RFC 6749 Section 5.2). The decoded Basic credential is secret, so the arena is a wiping string, which the caller owns, should clear between independent parses, and must not alias the header or body inputs. This detects the mechanism and extracts the credentials, but does not verify the secret, which the caller does against its stored value in constant time, nor that an Assertion client_id identifies the same client as the assertion (RFC 7521 Section 4.2), which the caller checks when it verifies the assertion. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW", "", storage, credentials));
assert(credentials.method ==
assert(credentials.client_id == "s6BhdRkqt3");
OAuthClientAuthenticationMethod method
The mechanism the request presented.
Definition oauth_client_authentication.h:99
std::string_view client_id
The client identifier.
Definition oauth_client_authentication.h:101
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_parse_client_authentication(const std::string_view authorization, const std::string_view body, SecureString &storage, OAuthClientCredentials &credentials) -> bool
@ Basic
An HTTP Basic credential (RFC 6749 Section 2.3.1).
Definition oauth_client_authentication.h:83
Definition oauth_client_authentication.h:97

◆ oauth_parse_par_request()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_par_request ( const std::string_view body,
SecureString & storage,
OAuthAuthorizationRequest & result,
const std::function< void(std::string_view, std::string_view)> & on_other ) -> bool
nodiscard

Parse a pushed authorization request body (RFC 9126 Section 2.1) into the result, returning whether it is well formed. The parse follows the authorization request rules, and additionally rejects a request_uri parameter, which a pushed request MUST NOT provide, and every other parameter, such as the client authentication ones, is passed to the callback. The body may carry a client secret, so it is decoded into a wiping arena the caller owns and reuses. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"response_type=code&client_id=s6BhdRkqt3", storage, request,
[](std::string_view, std::string_view) {}));
assert(request.response_type == "code");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_parse_par_request(const std::string_view body, SecureString &storage, OAuthAuthorizationRequest &result, const std::function< void(std::string_view, std::string_view)> &on_other) -> bool

◆ oauth_parse_revocation_request()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_revocation_request ( const std::string_view body,
SecureString & storage,
OAuthTokenLookupRequest & result,
const std::function< void(std::string_view, std::string_view)> & on_other ) -> bool

Parse a token revocation request body (RFC 7009 Section 2.1) into the result, returning whether it is well formed. The token is required, a duplicated parameter fails (RFC 6749 Section 3.2), and every other parameter, such as the client authentication ones, is passed to the callback. The token is secret, so it is decoded into a wiping arena the caller owns and reuses, and which must not alias the body. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"token=45ghiukldjahdnhzdauz&token_type_hint=refresh_token", storage,
request, [](std::string_view, std::string_view) {}));
assert(request.token == "45ghiukldjahdnhzdauz");
std::string_view token
The token to act on (RFC 7009 Section 2.1).
Definition oauth_revocation.h:34
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_parse_revocation_request(const std::string_view body, SecureString &storage, OAuthTokenLookupRequest &result, const std::function< void(std::string_view, std::string_view)> &on_other) -> bool
Definition oauth_revocation.h:32

◆ oauth_parse_token_request()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_parse_token_request ( const std::string_view body,
SecureString & storage,
OAuthTokenRequest & result,
const std::function< void(std::string_view, std::string_view)> & on_other ) -> bool

Parse the body of a token request at the authorization server (RFC 6749 Section 4.1.3) into the result, returning whether it is well formed. Each recognized value is form-decoded into the storage arena and viewed there. The body carries the request's secrets, the authorization code, the code verifier, the refresh token, and the client authentication parameters, so the arena is a wiping string, which the caller owns, should clear between independent parses, and must outlive the result. A duplicated recognized parameter is a failure (RFC 6749 Section 3.2). Every repeatable resource and audience and every unrecognized parameter, including the client authentication parameters, is passed to the callback with its decoded value rather than stored on the result. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA", storage,
request, [](std::string_view, std::string_view) {}));
assert(request.grant_type == "authorization_code");
assert(request.code == "SplxlOBeZQQYbYS6WxSbIA");
std::string_view code
Definition oauth_token.h:103
std::string_view grant_type
The grant type (RFC 6749 Section 4.1.3).
Definition oauth_token.h:100
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_parse_token_request(const std::string_view body, SecureString &storage, OAuthTokenRequest &result, const std::function< void(std::string_view, std::string_view)> &on_other) -> bool
Definition oauth_token.h:98

◆ oauth_pkce_challenge()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_pkce_challenge ( const std::string_view verifier) -> std::array< char, 43 >

Derive the S256 code challenge for a code verifier, the base64url encoding of its SHA-256 digest (RFC 7636 Section 4.2). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string_view>
"dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk")};
assert((std::string_view{challenge.data(), challenge.size()} ==
"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_pkce_challenge(const std::string_view verifier) -> std::array< char, 43 >

◆ oauth_pkce_method_code()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_pkce_method_code ( const OAuthPKCEMethod method) -> std::string_view
noexcept

The wire value for a PKCE challenge method (RFC 7636 Section 4.3). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_pkce_method_code(const OAuthPKCEMethod method) noexcept -> std::string_view
@ S256
Definition oauth_pkce.h:22

◆ oauth_pkce_verifier()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_pkce_verifier ( ) -> std::array< char, 43 >

Mint a new PKCE code verifier, the base64url encoding of 32 cryptographically random octets (RFC 7636 Section 4.1). The 43 bytes are not null terminated, so pass them onward as a view of data() and size() rather than as a C string. The result is secret material, so wipe it once the exchange completes. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string_view>
const std::string_view view{verifier.data(), verifier.size()};
assert(view.size() == 43);
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_pkce_verifier() -> std::array< char, 43 >

◆ oauth_pkce_verify()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_pkce_verify ( const std::string_view verifier,
const std::string_view challenge,
const OAuthPKCEMethod method,
const OAuthProfile profile ) -> OAuthPKCEOutcome

Verify a presented code verifier against a stored code challenge and its method, under the given profile, returning the pairing outcome. An empty verifier or challenge means the value is absent. The final verifier against challenge comparison is constant time over their bytes once their lengths match. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk",
"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_pkce_verify(const std::string_view verifier, const std::string_view challenge, const OAuthPKCEMethod method, const OAuthProfile profile) -> OAuthPKCEOutcome
@ Match
The verifier corresponds to the challenge.
Definition oauth_pkce.h:36

◆ oauth_random_token()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_random_token ( ) -> std::array< char, 43 >

Mint a random token, the base64url encoding of 32 cryptographically random octets, for an unguessable but non-confidential value such as a state or nonce (RFC 6749 Section 10.10). The 43 bytes are not null terminated, so pass them onward as a view of data() and size() rather than as a C string. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string_view>
const std::string_view view{token.data(), token.size()};
assert(view.size() == 43);
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_random_token() -> std::array< char, 43 >

◆ oauth_redirect_uri_matches()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_redirect_uri_matches ( const std::string_view registered,
const std::string_view presented,
const OAuthProfile profile ) -> bool

Whether a redirection URI a client presents matches one it registered (RFC 6749 Section 3.1.2.3), by an exact byte comparison with one exception. When the registered URI is a loopback redirect, an HTTP URI whose host is literally 127.0.0.1 or [::1], only the port may differ (RFC 8252 Section 7.3). The strict profile keeps the OAuth 2.1 rule that localhost is not a loopback host (RFC 8252 Section 8.3). No URI is constructed, so the inputs are compared as given. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
"http://127.0.0.1:49152/cb", "http://127.0.0.1:51004/cb",
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_redirect_uri_matches(const std::string_view registered, const std::string_view presented, const OAuthProfile profile) -> bool

◆ oauth_registration_grant_response_consistent()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_registration_grant_response_consistent ( const OAuthClientMetadata & metadata) -> bool
nodiscard

Whether the registered grant types and response types are mutually consistent (RFC 7591 Section 2.1): the authorization_code grant pairs with the code response type and the implicit grant with the token response type. Only the explicitly registered lists are compared, so a document that omits either list registers no value that could contradict the other, and the server surfaces an inconsistency as invalid_client_metadata (RFC 7591 Section 3.2.2). For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/json.h>
#include <cassert>
auto document{sourcemeta::core::parse_json(R"JSON({
"grant_types": [ "authorization_code" ],
"response_types": [ "code" ]
})JSON")};
const auto metadata{
assert(metadata.has_value());
metadata.value()));
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_registration_grant_response_consistent(const OAuthClientMetadata &metadata) -> bool

◆ oauth_revocation_outcome()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_revocation_outcome ( const HTTPStatus status) -> OAuthRevocationOutcome
noexcept

Map a revocation response status code to its outcome: a 200 is a success, including for an unknown token (RFC 7009 Section 2.2), a 503 is retryable (RFC 7009 Section 2.2.1), and any other status is an error. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
constexpr HTTPStatus HTTP_STATUS_OK
Definition http_status.h:55
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_revocation_outcome(const HTTPStatus status) noexcept -> OAuthRevocationOutcome
@ Success
Definition oauth_revocation.h:93

◆ oauth_token_error_status()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_token_error_status ( const OAuthTokenError error,
const bool authenticated_via_header ) -> HTTPStatus
noexcept

The HTTP status for a token endpoint error response. It is 400 Bad Request in general, but 401 Unauthorized for a client authentication failure when the client authenticated through the Authorization header, since that response must then carry a WWW-Authenticate challenge (RFC 6749 Section 5.2). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
401);
400);
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_token_error_status(const OAuthTokenError error, const bool authenticated_via_header) noexcept -> HTTPStatus
@ InvalidClient
Client authentication failed (RFC 6749 Section 5.2).
Definition oauth_error.h:47

◆ oauth_token_exchange_valid()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_token_exchange_valid ( const OAuthTokenExchangeRequest & request) -> bool

Whether a token exchange request is well formed (RFC 8693 Section 2.1): the subject token and its type are present, and the actor token and its type are either both present or both absent. A malformed request is rejected as invalid_request (RFC 8693 Section 2.2.2), so a server applies this after collecting the parameters. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
request.subject_token = "eyJ...";
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_token_exchange_valid(const OAuthTokenExchangeRequest &request) -> bool

◆ oauth_transaction_check()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_transaction_check ( const OAuthTransaction & transaction,
const OAuthAuthorizationResponse & response,
const OAuthIssuerSupport issuer_support,
const std::string_view received_uri,
std::string_view & code ) -> std::optional< OAuthCallbackError >

Validate an authorization response against the retained transaction, returning the authorization code through code on success or the first failing check otherwise (RFC 9700 Section 4). The checks run in order: the state in constant time, the received URI when one is supplied, the issuer, whether the server declined, and finally the presence of a code. Pass an empty received_uri to skip that check. The state check always defends against cross-site request forgery. Guaranteed mix-up defense needs a non-empty received_uri (RFC 8252 Section 8.10) or an issuer_support of Supported, which makes a missing iss fatal (RFC 9207 Section 2.4). With Unknown the iss is validated only when present, so a server that omits it is not caught, and with NotSupported it is ignored entirely. A caller talking to more than one authorization server must therefore supply one of those two. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
std::string storage;
"code=SplxlOBeZQQYbYS6WxSbIA&state=xyz", storage, response);
.state = "xyz", .code_verifier = "", .issuer = "", .redirect_uri = ""};
std::string_view code;
"", code)};
assert(!error.has_value());
assert(code == "SplxlOBeZQQYbYS6WxSbIA");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_transaction_check(const OAuthTransaction &transaction, const OAuthAuthorizationResponse &response, const OAuthIssuerSupport issuer_support, const std::string_view received_uri, std::string_view &code) -> std::optional< OAuthCallbackError >
@ Unknown
Support is unknown, so iss is validated only when present.
Definition oauth_transaction.h:55
Definition oauth_transaction.h:34

◆ oauth_transaction_mint()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_transaction_mint ( ) -> OAuthTransactionSecrets

Mint the secrets for a new authorization code flow, a random state and a PKCE code verifier (RFC 7636 Section 4.1, RFC 6749 Section 10.12). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(secrets.state.size() == 43);
assert(secrets.code_verifier.size() == 43);
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_transaction_mint() -> OAuthTransactionSecrets

◆ oauth_verify_assertion_grant()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::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 >
nodiscard

Verify a JWT bearer authorization grant assertion (RFC 7523 Section 3), returning the first failing check or no value when it verifies. The issuer must match the expected one, the subject identifies the accessor and is only required to be present, and the audience must match one of the accepted values by Simple String Comparison without normalization (RFC 3986 Section 6.2.1). A failure is reported to the client as invalid_grant (RFC 6749 Section 5.2). For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/jose.h>
#include <array>
#include <chrono>
#include <cassert>
const std::array<std::string_view, 1>
audiences{{"https://server.example/token"}};
assertion, "https://issuer.example", audiences, keys,
std::chrono::system_clock::now(), options)};
assert(!error.has_value() ||
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 >
@ Issuer
The issuer claim was absent or did not match (RFC 7523 Section 3 check 1).
Definition oauth_assertion.h:139
Definition oauth_assertion.h:161

◆ oauth_verify_client_assertion()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::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 >
nodiscard

Verify a JWT bearer client authentication assertion (RFC 7523 Section 3, RFC 7521 Section 5.2), returning the first failing check or no value when it verifies. The issuer and subject must both be the client identifier, the subject must match a presented client_id when one is given (RFC 7521 Section 4.2), and the audience must match one of the accepted values by Simple String Comparison without normalization (RFC 3986 Section 6.2.1). A failure is reported to the client as invalid_client (RFC 7521 Section 4.2.1). For example:

#include <sourcemeta/core/oauth.h>
#include <sourcemeta/core/jose.h>
#include <array>
#include <chrono>
#include <cassert>
const std::array<std::string_view, 1>
audiences{{"https://server.example/token"}}; const std::array
sourcemeta::core::OAuthAssertionVerifyOptions options;
options.allowed_algorithms = allowed;
assertion, audiences, "s6BhdRkqt3", keys,
std::chrono::system_clock::now(), options)};
assert(!error.has_value() ||
std::span< const JWSAlgorithm > allowed_algorithms
Definition oauth_assertion.h:164
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 >
@ Expired
The assertion has expired (RFC 7523 Section 3 check 4).
Definition oauth_assertion.h:147

◆ oauth_well_known_url()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::oauth_well_known_url ( const std::string_view identifier,
const OAuthWellKnownKind kind,
std::string & sink ) -> bool

Derive a metadata well-known URL from an identifier and append it to the sink, returning whether the identifier is well formed (RFC 8414 Section 3, RFC 9728 Section 3). The identifier must use the https scheme and carry no fragment, and no query unless it is a protected resource. A terminating slash on the path is removed, and for the inserted kinds the well-known string is placed between the host and the path, preserving a protected resource query after it. The sink is appended to and never cleared. For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
#include <string>
std::string url;
"https://example.com/issuer1",
assert(url ==
"https://example.com/.well-known/oauth-authorization-server/issuer1");
SOURCEMETA_CORE_OAUTH_EXPORT auto oauth_well_known_url(const std::string_view identifier, const OAuthWellKnownKind kind, std::string &sink) -> bool

◆ to_oauth_authorization_error()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::to_oauth_authorization_error ( const std::string_view code) -> std::optional< OAuthAuthorizationError >
noexcept

Map an authorization endpoint error code to its value, returning no value for an unrecognized code (RFC 6749 Section 4.1.2.1). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
.has_value());
SOURCEMETA_CORE_OAUTH_EXPORT auto to_oauth_authorization_error(const std::string_view code) noexcept -> std::optional< OAuthAuthorizationError >

◆ to_oauth_bearer_error()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::to_oauth_bearer_error ( const std::string_view code) -> std::optional< OAuthBearerError >
noexcept

Map a protected resource challenge error code to its value, returning no value for an unrecognized code (RFC 6750 Section 3.1). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(sourcemeta::core::to_oauth_bearer_error("invalid_token").has_value());
SOURCEMETA_CORE_OAUTH_EXPORT auto to_oauth_bearer_error(const std::string_view code) noexcept -> std::optional< OAuthBearerError >

◆ to_oauth_pkce_method()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::to_oauth_pkce_method ( const std::string_view value) -> std::optional< OAuthPKCEMethod >
noexcept

Map a PKCE challenge method wire value to its type, returning no value for an unrecognized method (RFC 7636 Section 4.3). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(sourcemeta::core::to_oauth_pkce_method("S256").has_value());
assert(!sourcemeta::core::to_oauth_pkce_method("plaintext").has_value());
SOURCEMETA_CORE_OAUTH_EXPORT auto to_oauth_pkce_method(const std::string_view value) noexcept -> std::optional< OAuthPKCEMethod >

◆ to_oauth_registration_error()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::to_oauth_registration_error ( const std::string_view code) -> std::optional< OAuthRegistrationError >
noexcept

Map a dynamic client registration error code to its value, returning no value for an unrecognized code (RFC 7591 Section 3.2.2). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(sourcemeta::core::to_oauth_registration_error("invalid_redirect_uri")
.has_value());
SOURCEMETA_CORE_OAUTH_EXPORT auto to_oauth_registration_error(const std::string_view code) noexcept -> std::optional< OAuthRegistrationError >

◆ to_oauth_token_error()

SOURCEMETA_CORE_OAUTH_EXPORT auto sourcemeta::core::to_oauth_token_error ( const std::string_view code) -> std::optional< OAuthTokenError >
noexcept

Map a token endpoint error code to its value, returning no value for an unrecognized code (RFC 6749 Section 5.2 and its extensions). For example:

#include <sourcemeta/core/oauth.h>
#include <cassert>
assert(sourcemeta::core::to_oauth_token_error("slow_down").has_value());
SOURCEMETA_CORE_OAUTH_EXPORT auto to_oauth_token_error(const std::string_view code) noexcept -> std::optional< OAuthTokenError >

Variable Documentation

◆ OAUTH_CLIENT_ASSERTION_TYPE_JWT_BEARER

std::string_view sourcemeta::core::OAUTH_CLIENT_ASSERTION_TYPE_JWT_BEARER
inlineconstexpr
Initial value:
{
"urn:ietf:params:oauth:client-assertion-type:jwt-bearer"}

The client assertion type identifier of a JWT bearer client authentication assertion (RFC 7523 Section 2.2).

◆ OAUTH_GRANT_TYPE_JWT_BEARER

std::string_view sourcemeta::core::OAUTH_GRANT_TYPE_JWT_BEARER
inlineconstexpr
Initial value:
{
"urn:ietf:params:oauth:grant-type:jwt-bearer"}

The grant type identifier of a JWT bearer authorization grant (RFC 7523 Section 2.1).

◆ OAUTH_TOKEN_TYPE_ACCESS_TOKEN

std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_ACCESS_TOKEN
inlineconstexpr
Initial value:
{
"urn:ietf:params:oauth:token-type:access_token"}

The access_token token type identifier (RFC 8693 Section 3).

◆ OAUTH_TOKEN_TYPE_DPOP

std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_DPOP {"DPoP"}
inlineconstexpr

The token type of a DPoP-bound access token (RFC 9449 Section 5), the value a bound token response carries and a client confirms before use.

◆ OAUTH_TOKEN_TYPE_HINT_ACCESS_TOKEN

std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_HINT_ACCESS_TOKEN
inlineconstexpr
Initial value:
{
"access_token"}

The access_token token type hint (RFC 7009 Section 2.1), reused by token introspection (RFC 7662 Section 2.1).

◆ OAUTH_TOKEN_TYPE_HINT_REFRESH_TOKEN

std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_HINT_REFRESH_TOKEN
inlineconstexpr
Initial value:
{
"refresh_token"}

The refresh_token token type hint (RFC 7009 Section 2.1), reused by token introspection (RFC 7662 Section 2.1).

◆ OAUTH_TOKEN_TYPE_ID_TOKEN

std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_ID_TOKEN
inlineconstexpr
Initial value:
{
"urn:ietf:params:oauth:token-type:id_token"}

The id_token token type identifier (RFC 8693 Section 3).

◆ OAUTH_TOKEN_TYPE_JWT

std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_JWT
inlineconstexpr
Initial value:
{
"urn:ietf:params:oauth:token-type:jwt"}

The JWT token type identifier (RFC 8693 Section 3).

◆ OAUTH_TOKEN_TYPE_REFRESH_TOKEN

std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_REFRESH_TOKEN
inlineconstexpr
Initial value:
{
"urn:ietf:params:oauth:token-type:refresh_token"}

The refresh_token token type identifier (RFC 8693 Section 3).

◆ OAUTH_TOKEN_TYPE_SAML1

std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_SAML1
inlineconstexpr
Initial value:
{
"urn:ietf:params:oauth:token-type:saml1"}

The SAML 1.1 token type identifier (RFC 8693 Section 3).

◆ OAUTH_TOKEN_TYPE_SAML2

std::string_view sourcemeta::core::OAUTH_TOKEN_TYPE_SAML2
inlineconstexpr
Initial value:
{
"urn:ietf:params:oauth:token-type:saml2"}

The SAML 2.0 token type identifier (RFC 8693 Section 3).