43using NowFn = std::function<std::int64_t()>;
113 template <
typename Request>
115 std::function<std::optional<std::string>(
const Request&)> extract_token)
const {
117 return [self, extract_token](
const Request& req) -> std::optional<AxiamUser> {
118 auto token = extract_token(req);
119 if (!token.has_value())
return std::nullopt;
126 std::string tenant_id_;
134 return TokenAuthenticator(client.
jwks(), std::move(expected_tenant_id), std::move(options));
std::function< std::optional< AxiamUser >(const Request &)> Authenticator
Definition guard.hpp:107
JwksVerifier & jwks()
Shared JWKS verifier bound to this client's transport + base URL.
Safe-by-default local verification of an AXIAM access token.
Definition authenticator.hpp:81
static std::optional< std::string > bearer_from_authorization(const std::string &header_value)
Extract a bearer token from an Authorization header value.
static std::optional< std::string > token_from_cookie_header(const std::string &cookie_header)
Extract the axiam_access token from a Cookie request header value.
std::optional< AxiamUser > try_authenticate(const std::string &token) const
Non-throwing twin, for wiring into AxiamGuard / framework adapters.
AxiamUser authenticate(const std::string &token) const
Verify token and build the authenticated identity.
const std::string & expected_tenant_id() const noexcept
The tenant every token is bound to.
Definition authenticator.hpp:101
TokenAuthenticator(JwksVerifier &jwks, std::string expected_tenant_id, AuthenticatorOptions options={})
AxiamGuard< Request >::Authenticator guard_authenticator(std::function< std::optional< std::string >(const Request &)> extract_token) const
Build a §10 guard authenticator: given a way to pull the raw credential out of a framework request,...
Definition authenticator.hpp:114
Definition authenticator.hpp:40
constexpr std::chrono::seconds kMaxClockSkew
Definition authenticator.hpp:56
TokenAuthenticator make_authenticator(Client &client, std::string expected_tenant_id, AuthenticatorOptions options={})
Convenience factory: an authenticator bound to a client's JWKS verifier.
Definition authenticator.hpp:132
constexpr std::chrono::seconds kDefaultClockSkew
CONTRACT §10.1 rule 7 — the leeway applied to exp and nbf must be a named, documented,...
Definition authenticator.hpp:55
std::function< std::int64_t()> NowFn
Clock seam: returns the current time as unix seconds. Injected in tests.
Definition authenticator.hpp:43
Tuning for TokenAuthenticator. The defaults are the safe ones.
Definition authenticator.hpp:59
std::chrono::seconds clock_skew
Tolerance applied to exp and nbf for small clock differences between this resource server and the AXI...
Definition authenticator.hpp:64
std::optional< std::string > expected_issuer
When set, the iss claim must be present and equal to this value.
Definition authenticator.hpp:67
std::optional< std::string > expected_audience
When set, the aud claim must be present and must contain this value (aud may be a string or an array ...
Definition authenticator.hpp:71
NowFn now
Time source. Empty => the system clock.
Definition authenticator.hpp:74
Authenticated identity injected by the §10 guard into the request context.
Definition guard.hpp:27