Verifier library: agentic_auth.verify
For the owner of a tool or API. It admits a call only if the call carries a valid grant and a valid agent identity and, for a privileged tool, a valid transaction token.
It needs only the base install, pip install authzai (pyjwt[crypto]), plus httpx for the
Http* sources. It imports nothing from the control plane, FastAPI, SQLAlchemy or Redis. After
bootstrap(), admit() makes no network call.
from agentic_auth.verify import HttpAnchors, HttpJwks, InMemoryReplay, Verifier
verifier = Verifier(
issuer_jwks=HttpJwks(f"{CONTROL_PLANE}/.well-known/jwks.json"),
anchors=HttpAnchors(base_url=CONTROL_PLANE, token=AUDIT_READ_TOKEN,
agents=["balance-agent"]),
replay=InMemoryReplay(),
)
await verifier.bootstrap()
admission = verifier.admit(request.headers, target="mcp://accounts.internal/terminate_account",
params=body, privileged=True)
if not admission.ok:
return 403, admission.reason
For an ASGI app, RequireAgenticAuth wraps
this in middleware.
Verifier
| Field | Default | Notes |
|---|---|---|
issuer_jwks | required | A JwksSource: where the control plane's signing keys come from |
anchors | required | An AnchorStore: each agent's identity keys and revocation state |
replay | required | A ReplayStore: makes each transaction token single use |
identity_required | True | Require the Agent-Identity header. Turn it off only while agents are still enrolling. |
freshness_seconds | 30 | How old the anchor view may get before every identity is refused as IDENTITY_STALE |
issuer | agentic-auth | Expected iss; match AGENTIC_AUTH_ISSUER |
leeway_seconds | 60 | Clock skew allowed on exp |
metrics_registry | None | A Prometheus registry. When set, the verifier counts agentic_auth_admissions_total{result} and agentic_auth_transaction_rejections_total{cause}. |
telemetry | None | A TelemetrySink. In 0.3.0 and 0.4.0 the sink receives no spans, because of a bug in how the verifier reads the admission result. Use metrics_registry for now. |
await bootstrap() fetches the issuer keys, each configured agent's identity and the
revocation list, then starts refreshing in the background. It raises if anything fails: a
verifier that started with an empty view would refuse everything while looking healthy.
admit(headers, *, target, params=None, privileged=False) -> Admission checks a call. It
reads Authorization, Agent-Identity and Txn-Token from headers, case-insensitively.
Pass params, the parsed JSON body, whenever privileged=True.
await close() stops the background refresh.
Admission
| Attribute | Notes |
|---|---|
ok | True if the call is admitted |
reason | The refusal code, or None |
detail | A human-readable explanation |
grant, identity, transaction | What was verified, for logging or for your own checks |
Checks, in order
A refusal at any step stops the rest, and reason names the step.
| Step | Reasons |
|---|---|
Grant: the bearer is a hop token signed by the issuer, unexpired, with aud equal to target. A root grant is never valid at a resource. | GRANT_MISSING, GRANT_INVALID, GRANT_EXPIRED, GRANT_TARGET_MISMATCH |
Identity (when identity_required): Agent-Identity is signed by the key pinned for the agent holding the grant, names this target, and is bound to this exact grant | IDENTITY_MISSING, IDENTITY_STALE, IDENTITY_UNKNOWN_AGENT, IDENTITY_REVOKED, IDENTITY_INVALID |
Transaction (when privileged): Txn-Token is bound to this grant, this target and these exact parameters, and hasn't been used | TXN_MISSING, TXN_INVALID, TXN_EXPIRED, TXN_GRANT_MISMATCH, TXN_TARGET_MISMATCH, TXN_PARAMS_MISMATCH, TXN_UNSUPPORTED_BINDING, TXN_REPLAY, REPLAY_STORE_UNAVAILABLE |
Sources and stores
| Class | Use |
|---|---|
HttpJwks(url) | Fetches the control plane's /.well-known/jwks.json at bootstrap |
StaticJwks(jwks) | A JWKS you already hold, for tests or air-gapped deployments |
HttpAnchors(base_url, token, agents, freshness_seconds=30) | Reads GET /v1/identity/agents/{name} for each agent in agents and GET /v1/identity/revocations, refreshing every freshness_seconds. token needs only identity-reader rights (AGENTIC_AUTH_AUDIT_READ_TOKEN). An agent not listed is IDENTITY_UNKNOWN_AGENT. On a failed refresh it keeps the last view, which ages until IDENTITY_STALE refuses. |
StaticAnchors(reads) | Anchors shipped as data: a list of AgentIdentityRead bodies. Never stale; you own rotation. |
InMemoryReplay() | Single-process replay guard. Fine for one resource-server instance. |
RedisReplay(client) | SET NX EX on a synchronous Redis client. Use it behind more than one instance. If Redis is unreachable, the call is refused with REPLAY_STORE_UNAVAILABLE. |