adk_core/request_context.rs
1use std::collections::HashMap;
2
3/// Identity and authorization context extracted from an HTTP request.
4///
5/// This struct carries authenticated identity fields (user_id, scopes, metadata)
6/// that flow from the server's auth middleware into the agent invocation context.
7/// It lives in `adk-core` so that both `adk-server` (which produces it) and
8/// `adk-runner` (which consumes it) can reference it without circular dependencies.
9///
10/// # Example
11///
12/// ```rust
13/// use adk_core::RequestContext;
14///
15/// let ctx = RequestContext {
16/// user_id: "user-123".to_string(),
17/// scopes: vec!["read".to_string(), "write".to_string()],
18/// metadata: [("tenant".to_string(), "acme".to_string())].into(),
19/// };
20/// assert_eq!(ctx.user_id, "user-123");
21/// assert_eq!(ctx.scopes.len(), 2);
22/// ```
23#[derive(Debug, Clone)]
24pub struct RequestContext {
25 /// Authenticated user ID (e.g. from JWT `sub` or `email` claim).
26 pub user_id: String,
27 /// Granted scopes (e.g. from JWT `scope` or `scp` claim).
28 pub scopes: Vec<String>,
29 /// Additional metadata for custom middleware use.
30 pub metadata: HashMap<String, String>,
31}