pub trait RequestContextExtractor: Send + Sync {
// Required method
fn extract<'life0, 'life1, 'async_trait>(
&'life0 self,
parts: &'life1 Parts,
) -> Pin<Box<dyn Future<Output = Result<RequestContext, RequestContextError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
}Available on crate feature
server only.Expand description
Extracts authenticated identity from HTTP request headers.
Implementations typically parse a Bearer token from the Authorization
header, validate it, and map claims to a RequestContext. adk-server
re-exports it as adk_server::auth_bridge::RequestContextExtractor.
§Example
use adk_core::RequestContext;
use adk_core::request_context::{RequestContextError, RequestContextExtractor};
struct Header;
#[async_trait::async_trait]
impl RequestContextExtractor for Header {
async fn extract(
&self,
parts: &http::request::Parts,
) -> Result<RequestContext, RequestContextError> {
let user = parts
.headers
.get("x-user")
.and_then(|value| value.to_str().ok())
.ok_or(RequestContextError::MissingAuth)?;
Ok(RequestContext { user_id: user.to_string(), scopes: vec![], metadata: Default::default() })
}
}Required Methods§
Sourcefn extract<'life0, 'life1, 'async_trait>(
&'life0 self,
parts: &'life1 Parts,
) -> Pin<Box<dyn Future<Output = Result<RequestContext, RequestContextError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn extract<'life0, 'life1, 'async_trait>(
&'life0 self,
parts: &'life1 Parts,
) -> Pin<Box<dyn Future<Output = Result<RequestContext, RequestContextError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Extract identity from the request parts (headers, URI, etc.).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".