A key can say what it opens. It can't say who handed it over, how far it was meant to reach, when it stops working, or how to take it back.
Picture a signature stamp in a desk drawer at a clinic. Whoever opens the drawer signs as the doctor. The page looks the same either way, and nothing on it records whose hand was on the stamp.

Software has its own version of the stamp, and it's the default for anything non-human that needs to act: a service account, or an API key that behaves like one. Part one of this series said an agent's credential in a regulated setting has to be delegated, scoped, time-bound, and revocable, and gave each a paragraph or two. This part gives the reasoning behind each one, where it gets hard in practice, and how you can take it too far.
I've spent the last few years in pharma, where the DEA settled a version of this problem for people long before anyone wired a language model to a patient record. If anyone other than the registrant is going to order Schedule II controlled substances for a pharmacy, the registrant executes a power of attorney for that individual by name. To sign those orders electronically, the person holds their own digital certificate, and only the certificate holder may use it. The registrant can revoke the power of attorney at any time, and it's kept with the order records where an inspector can read it.
Nobody signs with the pharmacy's key.
I'm only borrowing the structure of that rule. It doesn't let software hold the certificate, and its power of attorney never expires on its own, which would be wrong for an agent. The three things worth copying are the named person, the revocation, and the record an inspector can find.
What a service account can't tell you
Part one's complaint was about the bare key, which says what the holder may call and stops there. A well-run service account fixes a lot of that. You can give it narrow roles, short-lived tokens, and an owner on file, and you can disable it in one call.
A nightly job that copies claims to a warehouse should keep its service account. The job is deterministic and the deploy history tells you who authorized it, so asking a person to approve each run buys you nothing.
What a service account can't do is act for a different person on each run. Every action it takes belongs to the account, and the account is not a human. That's fine for the nightly job. Once a model decides at runtime which tool to call and on which record, the deploy history can no longer tell you who authorized a given action.
The HIPAA Security Rule's access controls tell you to "assign a unique name and/or number for identifying and tracking user identity." A service account with its own ID can meet the letter of that. It still can't answer the next question I'd expect from an auditor: which person was this action for?
Why "whatever the user can do" is the wrong grant
The obvious fix is to let the agent borrow a person's identity. It runs as the clinician, with the clinician's permissions. The OAuth token exchange standard, RFC 8693, has precise words for what you're choosing between. "When principal A impersonates principal B, A is given all the rights that B has within some defined rights context and is indistinguishable from B in that context." Under delegation, A keeps its own identity and acts for B: "In a sense, A is an agent for B."
Read the end of that first quote again. Under impersonation, the audit log shows the clinician opening a chart the clinician never saw. That alone should rule it out.
It's also far more access than the agent needs. A clinician's permissions were sized for a person who opens one chart at a time and brings judgment to each one. A person's access also keeps changing as they join a care team or cover for a colleague, and an agent that inherits "whatever the user can do" picks up each change without anyone approving it.
An agent also takes direction from what it reads. A chart note or an inbound message can contain text that a model treats as an instruction. You already accept the risk of a person having that much access. An agent that a chart note can redirect needs a tighter limit.
So the agent inherits nothing. An agent's authority is exactly the set of grants on its credential, and anything not written there doesn't exist. Every credential traces back to a named person, and that person can't grant access they don't have themselves. The grant also has to stay within limits the organization sets. If an admin has ruled that agents may only call tools on an approved list, the issuer refuses anything outside it and records the refusal.
You can take this too far. If the grants get granular enough, a simple workflow needs dozens of them, the consent screen turns into a wall of JSON, and the person approving it stops reading. If nobody reads the consent screen, the approval is just a click, and you're back to the stamp in the drawer. Limit how many grants one credential can have, and show each grant as a plain sentence the person can compare to what they meant to approve.
A scope has to be something you can check on every call
A scope string can say "read access." It can't say which fields or which rows. OAuth's Rich Authorization Requests spec, RFC 9396, treats the scope string as enough for coarse requests and says it "is not sufficient to specify fine-grained authorization requirements." It adds a list of typed objects that you send alongside the string. Here are three grants as they'd appear on a credential.
[
{
"type": "records.read",
"entities": ["intake_form", "patient_profile"],
"fields": ["reason_for_visit", "insurance_status", "preferred_location"],
"filter": { "assigned_clinician": "user_7f3a91" }
},
{
"type": "records.write",
"entities": ["scheduling_request"],
"fields": ["specialty", "earliest_date", "notes"]
},
{
"type": "tool.invoke",
"tool": "calendar.find_openings",
"max_calls_per_hour": 60
}
]Read never implies write, even on the same entity. This agent has to read the intake form to make a routing decision, and nothing on its credential lets it change that form. The gate is the check that runs before any call executes. It lets a call through if one grant covers it, and a grant covers a call only when the call meets every constraint in that grant.
HIPAA's minimum necessary standard asks for "reasonable efforts to limit protected health information to the minimum necessary." The rule exempts disclosures to a provider for treatment, among others. I hold the agent to that limit anyway, and a structured grant is one way to make it checkable on every call.
Keep the list of grant types closed. Whoever runs the gate defines the types, and nobody building on top gets to invent one, because the gate can't enforce a type it doesn't understand. Apply the same rule to every field inside a grant. If nothing checks a field at the moment of the call, take the field out. A constraint that's validated at issuance and ignored at execution is worse than no constraint, because the consent record now promises a limit that was never enforced.
Sooner or later someone will need a grant that none of your types cover. They'll either wait for a new type or reach for the widest one that works, and the second choice is the dangerous one.
Tool grants have their own gap. Permission to call a tool says nothing about what data the tool touches once it runs, so limit what each tool can access when you register it.
Resolve the variables once, at issuance
Look at the filter on the first grant. Whoever configured the workflow didn't type a user ID. They wrote a rule: records where the assigned clinician is the delegating user. Resolve every variable in a grant once, when you issue the credential, and hand the agent the literal ID.
When you resolve at issuance, the consent record contains exactly what the gate will enforce. An auditor reads one object and doesn't have to work out what a variable meant at the time of each call. What the agent may do also can't change after the person approved it. A variable evaluated at call time takes its value from the runtime context, and a chart note or an inbound message can influence that context. Keep the list of things a variable can refer to short: the delegating user, the organization, the application, the time of issuance.
Resolving early locks in who the person is. It doesn't lock in the data. The filter still runs against current records on every call, so a patient reassigned at noon drops out of the agent's view at noon. What the credential won't pick up is a change to the person. If they hand off the role or lose access, the grant still names them until it expires or someone revokes it.
No refresh tokens, because every credential needs its own consent
Part one ruled out the refresh token by asking which consent covers an action after the third refresh. OAuth's own answer is the original grant, since a refreshed token can't exceed the scope first approved. That holds on paper. In an audit, it means an action in March points back through a string of renewals to an approval from November, given by a person who stopped thinking about it in December.
So issue each credential once, against one consent record, with an explicit expiry. When you need continuity, revoke the old credential, issue a new one, and write a single event that links the two. An auditor can follow that in the record.
You don't have to leave the standards to do this. RFC 6749 says "issuing a refresh token is optional at the discretion of the authorization server," and the authorization spec for MCP, the Model Context Protocol, tells clients they "MUST NOT assume refresh tokens will be issued."
Pick the token format with revocation in mind. A self-contained signed token is valid wherever it's checked until it expires. That makes it fast, and it makes instant revocation impossible without a lookup. The lookup is worth paying for. Make the token an opaque string, store only a hash of it, and resolve every use against the live credential.
An opaque token is still a bearer token. Whoever copies it can use it until it expires or someone revokes it, and a short lifetime limits that damage without removing it. The next step up is to bind the token to a key the agent holds, which is how the DEA's certificate rule already works for people.
If you set the lifetime to a few minutes, people approve reissue prompts all day without reading them, or they ask for the longest lifetime the policy allows. Tie the lifetime to something that already has an end, like a shift or a single run of a workflow. Then the credential expires when the person would expect their delegation to end anyway.
Whose authority, when nobody clicked approve?
Everything so far assumes a person issued the credential deliberately. A lot of agent work doesn't start that way. A form gets submitted, a webhook lands, a schedule fires, and a workflow needs a credential right now. You have to decide which human's authority that run carries, and there are three reasonable answers.
- On behalf of the author. The person who built and deployed the workflow. There's always a person to name, and it fits back-office automation where that person is the responsible party. It also puts the liability on someone who may have built the thing months ago. On the day they leave, everything running under their name should stop, so put the handoff to a named successor on the offboarding checklist.
- On behalf of the active user. The person whose action triggered the run. This is the tightest link you can get between a human decision and an agent action. It has no answer for work that starts without a human, like a schedule or an inbound message.
- On behalf of a role. Whoever holds a named role when the run starts, such as the on-call clinician. The authority sits with whoever is responsible today. It's only as good as your role data, and the credential should record the person it resolved to.
Nobody clicks approve in any of these, so be clear about what counts as consent. For the author, it's deploying the workflow. For the active user, it's the action that triggered the run. For a role, it's taking on that role, and that only counts if the person in the role can see what runs in their name.
Each run still gets its own credential and expiry, and its own record naming the person. The standing setup behind those runs is a grant too, and it needs the same things any grant does. The person it names can see it and revoke it, and it ends when they leave. Without that, one deployment keeps authorizing runs for as long as nobody looks, which is the refresh token problem again.
Choose the pattern in configuration when you deploy the workflow, and don't let the system guess one at runtime. A workflow set to act for the active user and then triggered by a webhook has no active user, so it refuses to start. It doesn't fall back to the author. If the configured pattern can't name a person, nothing runs.
Delegated authority can only get narrower
Agents hand work to other agents, and the credential can't get broader along the way. When one agent issues a credential to another, the child gets only what it asked for and the parent already has. It can't outlive the parent, and the person the chain traces back to doesn't change. The right to delegate is itself a grant that names which agent can receive authority and how many levels deep the chain can go.
Two implementation details make those rules hold. The issuer reads the parent from the credential the calling agent authenticated with, never from a field in the request, so an agent can't claim a parent it doesn't have. It counts depth from the stored chain for the same reason. RFC 8693 already defines how to record this: "A chain of delegation can be expressed by nesting one act claim within another."
The narrowing rule has a side effect. If a child can never have what its parent lacks, people give the top agent everything any agent below it might need, and the root credential ends up as broad as the key it was meant to replace. Review the root credential more carefully than anything below it.
Revocation: drain, kill, and what's missing from both
Revocation takes effect immediately, but what "immediately" means depends on which of two modes you chose. Drain lets a call that's already executing finish and refuses the next one. Kill refuses the next one and also cancels what's in flight.
Set the mode when the credential is issued, while the person granting the authority still knows what the work is. The middle of an incident is a bad time to decide what revoking should mean.
Neither mode is safe by default. Kill can cancel a call partway through, so the outside system received the request and the agent never saw the response. Drain lets a misbehaving agent finish the call it had already started. And both stop a multi-step run between steps, so the workflow has to be able to resume or clean up after itself either way.
Drain is almost free to build. The gate already has to re-check the credential on every call, because someone can revoke a credential between the start of a request and the tool call inside it. Kill costs more to build. It has to cancel work everywhere work can be running: an open model stream, a queued tool call, a child agent three levels down. Work out which of those you can actually interrupt before you promise "kill" in a contract.
Both modes cascade. When you revoke a credential, every credential delegated from it is revoked too, regardless of the mode each child was issued with. And neither mode undoes anything. A write that finished before the revocation stays written and stays in the record, and nothing removes what the agent already read into a model's context.
Build it from standard parts
None of this needs a private protocol. The consent screen is the OAuth authorization code flow with PKCE, and the grant format comes from RFC 9396. For agent frameworks, follow the MCP authorization spec, which treats the server as an OAuth resource server. An integrator who knows those can read your design without learning a new vocabulary, and a security reviewer starts from specs they already know.
The standard parts come with habits you shouldn't copy. The long-lived refresh token is a consumer-app habit, and it's the first one to leave out. The standards themselves are still changing: OAuth 2.1 is an IETF draft, and the MCP authorization spec has been revised more than once. Keep the four properties no matter what, and expect the token and request formats to change as the standards do. Where a standard doesn't cover something you need, add it and say so in your docs.
The credential is the consent record
A credential says what an agent may do. Something still has to check each action against it at the moment it happens, and a later part of this series covers that. Every one of those checks gets written to an audit log, and part three covers who that log has to hold up against. Here's the record you're left with after issuing one.
{
"credential": "cred_01jb2",
"agent": "referral_router",
"on_behalf_of": "user_7f3a91",
"issued_at": "2026-10-12T08:00:00Z",
"expires_at": "2026-10-12T17:00:00Z",
"on_revoke": "drain",
"parent": null,
"grants": ["records.read", "records.write", "tool.invoke"],
"consent_record": "evt_58c1d0"
}Go back to the stamp in the drawer. Every field in that record is something the stamp can't tell you. The credential is the consent, written so a machine can enforce it and an auditor can read it. The DEA already asks that much of a person signing a Schedule II order.
I ask the same of an agent that touches a patient record.