Skip to main content

Module auth_bridge

Module auth_bridge 

Source
Expand description

Auth middleware bridge for flowing authenticated identity into agent execution.

This module defines the RequestContextExtractor trait that server operators implement to extract identity from HTTP requests, and the RequestContextError enum for extraction failures.

The extracted RequestContext (re-exported from adk-core) carries user_id, scopes, and metadata into the [InvocationContext], making scopes available to tools via ToolContext::user_scopes().

§Example

use adk_server::auth_bridge::{RequestContextExtractor, RequestContextError};
use adk_core::RequestContext;
use async_trait::async_trait;

struct MyExtractor;

#[async_trait]
impl RequestContextExtractor for MyExtractor {
    async fn extract(
        &self,
        parts: &axum::http::request::Parts,
    ) -> Result<RequestContext, RequestContextError> {
        let auth = parts.headers
            .get("authorization")
            .and_then(|v| v.to_str().ok())
            .ok_or(RequestContextError::MissingAuth)?;
        // ... validate token, build RequestContext ...
    }
}

Structs§

RequestContext
Identity and authorization context extracted from an HTTP request.

Enums§

RequestContextError
Errors that can occur during request context extraction.

Traits§

RequestContextExtractor
Extracts authenticated identity from HTTP request headers.