pub struct JwtAuthInterceptor { /* private fields */ }auth-jwt only.Expand description
A ServerInterceptor that authenticates requests with a signed JWT.
Reads Authorization: Bearer <jwt>, validates it with the configured
JwtValidator, and rejects the request (generically) on any failure.
Implementations§
Source§impl JwtAuthInterceptor
impl JwtAuthInterceptor
Sourcepub fn new(validator: JwtValidator, jwks: Jwks) -> JwtAuthInterceptor
pub fn new(validator: JwtValidator, jwks: Jwks) -> JwtAuthInterceptor
Creates an interceptor with a fixed key set.
Use an empty Jwks when validating HS256-only (the secret lives on
the validator).
Sourcepub fn from_jwks_url(
validator: JwtValidator,
jwks_url: impl Into<String>,
) -> JwtAuthInterceptor
pub fn from_jwks_url( validator: JwtValidator, jwks_url: impl Into<String>, ) -> JwtAuthInterceptor
Creates an interceptor that fetches keys from a JWKS URL, caching them
for ttl (default 1 hour) and refetching once on a key-id miss (key
rotation), at most once per
refetch interval.
The keys are not fetched here — the first request triggers the fetch.
jwks_url must be https://; http:// is refused (every token is,
with the reason logged) except to a loopback host (localhost or a
loopback address; not a name under .localhost, which can reach DNS),
since whoever can change the keys in transit can sign any identity
(audit SEC-06, NEW-b-5).
Sourcepub fn from_jwks_url_with_tls_config(
validator: JwtValidator,
jwks_url: impl Into<String>,
tls_config: ClientConfig,
) -> JwtAuthInterceptor
Available on crate feature tls-rustls only.
pub fn from_jwks_url_with_tls_config( validator: JwtValidator, jwks_url: impl Into<String>, tls_config: ClientConfig, ) -> JwtAuthInterceptor
tls-rustls only.Like from_jwks_url, but with a caller-supplied
rustls ClientConfig for the JWKS fetch —
for identity providers behind a private CA, where the default
webpki-roots trust store cannot verify the JWKS endpoint.
Sourcepub async fn from_oidc_issuer(
issuer: &str,
validator: JwtValidator,
) -> Result<JwtAuthInterceptor, A2aError>
pub async fn from_oidc_issuer( issuer: &str, validator: JwtValidator, ) -> Result<JwtAuthInterceptor, A2aError>
Discovers the issuer’s jwks_uri via OIDC discovery
({issuer}/.well-known/openid-configuration) and builds a
remote-JWKS interceptor for it.
The document’s issuer must be issuer (OpenID Connect Discovery 1.0
§4.3; a trailing / on either is ignored), and a validator that names
no issuer is bound to the document’s, the value its tokens carry, so a token from another issuer that shares
these keys (another tenant of a multi-tenant identity provider) is
refused (audit SEC-06). issuer and the jwks_uri must be
https://, except to a loopback host.
§Errors
Returns an A2aError when discovery fails, the document names
another issuer or has no jwks_uri, or a URL is plaintext.
Sourcepub async fn from_oidc_issuer_with_tls_config(
issuer: &str,
validator: JwtValidator,
tls_config: ClientConfig,
) -> Result<JwtAuthInterceptor, A2aError>
Available on crate feature tls-rustls only.
pub async fn from_oidc_issuer_with_tls_config( issuer: &str, validator: JwtValidator, tls_config: ClientConfig, ) -> Result<JwtAuthInterceptor, A2aError>
tls-rustls only.Like from_oidc_issuer, verifying the
identity provider (the discovery document and then the keys) against
tls_config instead of the default roots: an issuer behind a private
CA, or one that wants a client certificate. Until 2026-10-31 such an
issuer could not be discovered at all (audit B-04).
§Errors
As from_oidc_issuer.
Sourcepub fn with_jwks_ttl(self, ttl: Duration) -> JwtAuthInterceptor
pub fn with_jwks_ttl(self, ttl: Duration) -> JwtAuthInterceptor
Sets the remote-JWKS cache TTL. No-op for a static key set.
Sourcepub fn with_jwks_refetch_interval(
self,
interval: Duration,
) -> JwtAuthInterceptor
pub fn with_jwks_refetch_interval( self, interval: Duration, ) -> JwtAuthInterceptor
Sets the least time between one fetch of the key set and the refetch
a token whose key id is not in it asks for. Default:
DEFAULT_JWKS_REFETCH_INTERVAL (10 s). No-op for a static key set.
A token naming an unknown key id is refused, without a fetch, while the last fetch began less than this long ago; requests that arrive while a refetch is under way wait for it and use what it fetched. Until 2026-10-30 every such token, unsigned and unauthenticated, forced a fetch of its own, so anyone could make the agent send the identity provider one request per request it received (audit SEC-04). An identity provider publishes a new key before it signs with it, so a key rotation is seen at the first refetch after the key appears.
Sourcepub fn with_jwks_fetch_budget(self, budget: Duration) -> JwtAuthInterceptor
pub fn with_jwks_fetch_budget(self, budget: Duration) -> JwtAuthInterceptor
Bounds how long one request waits for keys, queueing behind another
request’s fetch included, and each fetch. Default
DEFAULT_JWKS_FETCH_BUDGET (30 s). A request whose wait runs out is
refused, as every request is while the keys cannot be had. No-op for a
static key set.
Trait Implementations§
Source§impl Debug for JwtAuthInterceptor
impl Debug for JwtAuthInterceptor
Source§impl ServerInterceptor for JwtAuthInterceptor
impl ServerInterceptor for JwtAuthInterceptor
Source§fn checks_scheme(&self, scheme: &SecurityScheme) -> Option<bool>
fn checks_scheme(&self, scheme: &SecurityScheme) -> Option<bool>
A bearer JWT: the HTTP bearer scheme, or an OAuth 2.0 or OpenID
Connect scheme, whose access tokens this validates.
Source§fn before<'a>(
&'a self,
ctx: &'a CallContext,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn before<'a>( &'a self, ctx: &'a CallContext, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Source§fn after<'a>(
&'a self,
_ctx: &'a CallContext,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn after<'a>( &'a self, _ctx: &'a CallContext, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Source§fn authenticates(&self) -> bool
fn authenticates(&self) -> bool
Source§fn on_complete<'a>(
&'a self,
ctx: &'a CallContext,
outcome: CallOutcome<'a>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>
fn on_complete<'a>( &'a self, ctx: &'a CallContext, outcome: CallOutcome<'a>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>
Auto Trait Implementations§
impl !RefUnwindSafe for JwtAuthInterceptor
impl !UnwindSafe for JwtAuthInterceptor
impl Forget for JwtAuthInterceptor
impl Freeze for JwtAuthInterceptor
impl Move for JwtAuthInterceptor
impl Send for JwtAuthInterceptor
impl Sync for JwtAuthInterceptor
impl Unpin for JwtAuthInterceptor
impl UnsafeUnpin for JwtAuthInterceptor
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].