How it works.
People, agents, sessions as a tree, needs, and approvals: the five ideas the rest of the docs build on.
People
A person signs in with a passkey, or with an email address and a password, and can add TOTP and recovery codes as second factors. The library owns every sign-in route and the browser client: you don’t write handlers for sign-in, sign-up, step-up, or sign-out. Sign-up, sign-in, and forgot-password answer the same for every address, nothing locks an account, and a code sent by email never signs anyone in.
A password alone is single-factor. On an account with a passkey or confirmed TOTP, a session that signed in with only a password is never fresh, so a phished password can’t change factors, create tokens, or end other sessions.
Agents
A person creates an agent with svc.CreateAgent, and gives it its own token, delegated from the person’s session, with svc.Delegate. The agent never uses the person’s cookie.
An agent’s Principal.User is the human it acts for. A scope check alone lets the agent do anything its human can within those scopes, so a route that only the person should call needs Human: true, or checks p.IsAgent().
An agent can also sign itself up. It gets a sandboxed token and a single-use claim code, and waits for a fresh, multi-factor person to claim it. Unclaimed agents are deleted at their claim deadline.
Sessions are a tree
Every session hangs from the session that delegated it, back to a person’s sign-in. Delegation only narrows: a child gets a subset of its parent’s scopes, never outlives its parent, and depth is capped.
repo:readrepo:readRevocation cascades and is immediate: revoking alice’s session ends Claude Code’s and the Test runner’s too. svc.SessionTree(ctx, user) returns each device with the agents and tokens delegated from it, for a “Where you’re signed in” page.
Needs
Each route declares what it needs, and the library decides, enforces, records, and explains. A need can ask for scopes, a level of assurance, a recent proof, or a person:
mux.HandleFunc("DELETE /repos/{id}", authhttp.Need(auth.Need{Assurance: auth.AssuranceMulti, Within: 10 * time.Minute, Human: true}), deleteRepo)A caller who doesn’t meet the need gets a challenge that names the need and lists only the factors this account has that would meet it:
{"code": "step_up_required", "title": "Confirm it's you", "fix": "Confirm it's you with a passkey, then try again.",
"challenge": {"action": "secrets.edit", "assurance": "multi", "within_seconds": 600, "human": true, "satisfy_with": ["passkey"]}}authhttp.Mux makes every route declare a rule, and mux.Check() refuses to start when something would weaken security.
Approvals
When your agent tries something risky, it gets a link instead of a yes; you tap your passkey on that exact action, and the agent continues, once, with a signed receipt.
- Agent asks. The route refuses the agent with
human_requiredand an approval: a link to show the person, the action’s summary, and a hint to wait. - You tap. The person opens the link and approves with a passkey, which signs the action’s digest.
- It runs once. The agent’s retry, held open with
Prefer: wait=60, runs the route once.
Everything is recorded
Every session start, delegation, rotation, revocation, agent change, and detected token reuse is recorded in the same transaction as the change. Failed sign-ins, throttled attempts, rejected tokens, and denied requests are recorded too. Events are sealed into a hash chain, so svc.VerifyAudit detects edits and deletions.