pub struct DpopResourceGuard { /* private fields */ }Expand description
Enforces DPoP proof-of-possession on a protected route (the resource-server
side of RFC 9449). Reads the access token’s cnf.jkt (already decoded onto
RequestContext by the boundary), the request’s DPoP proof header, and
the method + reconstructed URI, then verifies the proof and confirms the
thumbprint binding.
§Not a sync Guard — an async guard, like DistributedRateLimit
The framework’s Guard trait is
synchronous and zero-I/O by design (it inspects already-decoded claims).
A DPoP check must do per-request I/O — the single-use jti replay lookup —
so it cannot be a Guard. It follows the same shape the framework already
uses for DistributedRateLimit: an async method awaited at the top of the
handler (dpop.enforce(&ctx).await?), returning an error that converts to an
HTTP response. This is an established pattern in the codebase, not a new one.
Default posture is downgrade-safe: a token without cnf.jkt (a plain
bearer token) passes — an attacker can’t strip cnf from a signed bound
token to bypass the check. Call require_bound to also
reject unbound tokens (all access tokens must be DPoP).
Implementations§
Source§impl DpopResourceGuard
impl DpopResourceGuard
pub fn new(verifier: Arc<DpopVerifier>) -> Self
Sourcepub fn default_scheme(self, scheme: &'static str) -> Self
pub fn default_scheme(self, scheme: &'static str) -> Self
Scheme used to reconstruct the request URI when X-Forwarded-Proto is
absent (default "https"). Set "http" for local development.
Sourcepub fn require_bound(self) -> Self
pub fn require_bound(self) -> Self
Reject access tokens that are not sender-constrained (no cnf.jkt),
so every request on the route must present a DPoP proof.
Sourcepub async fn enforce(&self, ctx: &RequestContext) -> Result<()>
pub async fn enforce(&self, ctx: &RequestContext) -> Result<()>
Enforce the binding for the current request.
Auto Trait Implementations§
impl !RefUnwindSafe for DpopResourceGuard
impl !UnwindSafe for DpopResourceGuard
impl Freeze for DpopResourceGuard
impl Send for DpopResourceGuard
impl Sync for DpopResourceGuard
impl Unpin for DpopResourceGuard
impl UnsafeUnpin for DpopResourceGuard
Blanket Implementations§
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request