INNER CODE UNIT · Python
_bearer_token_from_call_context
evalstate/fast-agent · src/fast_agent/a2a/server.py:135
def _bearer_token_from_call_context(context: RequestContext) -> str | None:
saved_token = context.call_context.state.get("fast_agent_bearer_token")
if isinstance(saved_token, str) and saved_token:
return saved_token
headers = context.call_context.state.get("headers")
if not isinstance(headers, dict):
return None
authorization = headers.get("authorization") or headers.get("Authorization")
token = _bearer_token_from_header(authorization if isinstance(authorization, str) else None)
if token is not None:
return token
hf_authorization = headers.get("x-hf-authorization") or headers.get("X-HF-Authorization")
return _bearer_token_from_header(
hf_authorization if isinstance(hf_authorization, str) else None
)