1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use HashMap;
/// Identity and authorization context extracted from an HTTP request.
///
/// This struct carries authenticated identity fields (user_id, scopes, metadata)
/// that flow from the server's auth middleware into the agent invocation context.
/// It lives in `adk-core` so that both `adk-server` (which produces it) and
/// `adk-runner` (which consumes it) can reference it without circular dependencies.
///
/// # Example
///
/// ```rust
/// use adk_core::RequestContext;
///
/// let ctx = RequestContext {
/// user_id: "user-123".to_string(),
/// scopes: vec!["read".to_string(), "write".to_string()],
/// metadata: [("tenant".to_string(), "acme".to_string())].into(),
/// };
/// assert_eq!(ctx.user_id, "user-123");
/// assert_eq!(ctx.scopes.len(), 2);
/// ```
/// 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
///
/// ```rust
/// 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() })
/// }
/// }
/// ```
/// Errors that can occur during request context extraction.