🔑 Zero-Trust Agent Auth • OAuth 2.1 • RFC 8707 • RFC 8693 OBO
Agent Identity: OAuth 2.1 On-Behalf-Of & RFC 8707
Stop deploying autonomous agents with static god-mode service keys. Learn how to implement OAuth 2.1 + PKCE, RFC 8707 Resource Indicators for remote MCP servers, and RFC 8693 Token Exchange (On-Behalf-Of) for multi-hop A2A delegation.
⚡ 30-Second Specification TL;DR
| RFC / Standard | Role in Agent Stack | Attack Vector Neutralized |
|---|---|---|
| OAuth 2.1 + PKCE | Initial user-to-agent authorization handshake for IDE / web clients. | Authorization code interception & implicit flow token leakage. |
| RFC 8707 Resource Indicators | Binds JWT aud claim to exact MCP URI (resource=https://mcp.db.internal). |
Malicious MCP server replaying a user's Bearer token against another MCP server. |
| RFC 8693 Token Exchange (OBO) | Exchanges parent agent token for a down-scoped child token (act claim preserves actor chain). |
Lateral privilege escalation during multi-hop A2A sub-agent delegation. |
01 Implementing RFC 8693 On-Behalf-Of (OBO) + RFC 8707 Audience Verification
When an orchestrator delegates a sub-task to a specialist agent or remote MCP server, it must perform an RFC 8693 Token Exchange to strip unused permissions and bind the child token's `aud` claim to the target resource URI:
import hmac, hashlib, json, time
class OAuth21AgentTokenService:
def __init__(self, signing_secret: str):
self.secret = signing_secret.encode("utf-8")
def exchange_obo_token(self, *, parent_claims: dict, agent_id: str, target_resource_uri: str, requested_scopes: set) -> dict:
# 1. Enforce strict scope narrowing (child scopes MUST be a subset of parent user scopes)
parent_scopes = set(parent_claims.get("scope", "").split())
if not requested_scopes.issubset(parent_scopes):
raise PermissionError(f"OBO_SCOPE_ESCALATION_BLOCKED: {requested_scopes - parent_scopes}")
# 2. Mint 10-minute audience-bound token (RFC 8707 Resource Indicator + RFC 8693 'act' claim)
now = int(time.time())
child_claims = {
"sub": parent_claims["sub"], # Human principal identity preserved
"act": {"sub": f"agent:{agent_id}"}, # Autonomous actor recorded for SOC2 audit log
"aud": target_resource_uri, # RFC 8707 Resource Indicator binding
"scope": " ".join(sorted(requested_scopes)),
"iat": now,
"exp": now + 600
}
sig = hmac.new(self.secret, json.dumps(child_claims, sort_keys=True).encode(), hashlib.sha256).hexdigest()
return {"claims": child_claims, "signature": sig}