You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BearerTokenAuthMiddleware does not construct AuthInfo — ctx.auth_info.kind unusable for bearer flows #576
BearerTokenAuthMiddleware (`src/adcp/server/auth.py`) authenticates requests, sets the framework-private `current_principal` ContextVar with the validated principal id, and short-circuits on auth failure. What it does not do: construct an `AuthInfo` object and thread it into the request context.
Net effect for bearer adopters reading `RequestContext`:
`ctx.auth_info` is `None` (or default-stub) — adopters can't read `auth_info.kind`, `auth_info.key_id`, `auth_info.credential`, etc.
Adopters who want to branch on "is this a bearer or signed-request flow?" have no typed read.
After #574, `ctx.auth_principal` is correctly populated for bearer flows — but the surrounding typed auth surface (`auth_info.*`) is still unusable.
Why it matters
The triage security-reviewer flagged this as a structural gap during the issue #571 review. PR #574 addressed the immediate `auth_principal is None` papercut; this issue tracks the deeper fix so it doesn't only live in PR-body prose.
For adopters writing transport-agnostic handlers, `ctx.auth_info` is meant to be the typed identity surface. Today bearer adopters either (a) read `ctx.auth_principal` (post-#574) and ignore everything else, or (b) reach into framework-private contextvars to reconstruct what they need.
Possible direction
Have `BearerTokenAuthMiddleware` construct an `AuthInfo` after `validate_token` succeeds, populate `AuthInfo.kind = "bearer"` (or similar), `AuthInfo.principal = principal.caller_identity`, and thread it into the request context alongside the ContextVar. Then `_build_request_context` already does the right thing for both flows, and adopters can read `ctx.auth_info.kind` to discriminate.
Open questions:
What goes into `AuthInfo.credential` for a bearer flow? Per CLAUDE.md, the typed credential classes (`ApiKeyCredential`, `OAuthCredential`, `HttpSigCredential`) are for upstream propagation. Bearer adopters typically don't propagate the inbound bearer token outward — what's the right shape?
`AuthInfo.kind` enum: does "bearer" exist today, or do we extend it?
Backward compatibility: any consumer that assumes `auth_info` is `None` for bearer flows will break. Worth auditing before shipping.
Surfaced by
PR #574 (closes #571). Security-reviewer notes captured in the issue #571 triage comment.
Classification: Bug Bucket:adcp.server.auth middleware + adcp.decisioning.handler Severity: Medium — ctx.auth_info always None for bearer flows; any handler calling ctx.auth_info.kind raises AttributeError
Root cause:auth_context_factory correctly populated caller_identity / tenant_id on ToolContext but never set metadata["adcp.auth_info"]. PlatformHandler._extract_auth_info reads that key — so it always returned None for bearer requests even though the principal was present.
Fix:
auth_context_factory now constructs AuthInfo(kind="bearer", principal=..., credential=None) and stores it at metadata["adcp.auth_info"] when authenticated
_build_ctx pops the key after extraction (mirrors the existing adcp.buyer_agent pop) so the AuthInfo object never reaches the context-echo/idempotency path
Pre-PR review: Security reviewer and code reviewer both approved. No ship-blockers.
Activity
fix(auth): synthesize AuthInfo(kind="bearer") in _build_request_conte…
fix(auth): synthesize AuthInfo(kind="bearer") in _build_request_conte…
fix(server): auth_context_factory populates adcp.auth_info for bearer…
bokelley commentedon May 4, 2026
Triage
Classification: Bug
Bucket:
adcp.server.authmiddleware +adcp.decisioning.handlerSeverity: Medium —
ctx.auth_infoalwaysNonefor bearer flows; any handler callingctx.auth_info.kindraisesAttributeErrorRoot cause:
auth_context_factorycorrectly populatedcaller_identity/tenant_idonToolContextbut never setmetadata["adcp.auth_info"].PlatformHandler._extract_auth_inforeads that key — so it always returnedNonefor bearer requests even though the principal was present.Fix:
auth_context_factorynow constructsAuthInfo(kind="bearer", principal=..., credential=None)and stores it atmetadata["adcp.auth_info"]when authenticated_build_ctxpops the key after extraction (mirrors the existingadcp.buyer_agentpop) so theAuthInfoobject never reaches the context-echo/idempotency pathPre-PR review: Security reviewer and code reviewer both approved. No ship-blockers.
Draft PR: #579
Generated by Claude Code
fix(server): auth_context_factory populates adcp.auth_info for bearer…
fix(server): BearerTokenAuthMiddleware now populates ctx.auth_info fo…