Agent-Safe Sign-In: Approve Link, Device Code or Vault
An agent should start a sign-in and a person should finish it. Three patterns do that without the agent ever holding a password.
Answer first
Let the agent start a sign-in and let a person finish it. Three patterns do this without the agent holding a password: an emailed approve link, an OAuth device code, and a vault reference that injects a secret the agent never reads. Pick by where the agent runs and what the service supports, and write the negative tests before the happy path: a link must work once, expire, stay bound to the device that asked, and refuse any approver who is not the account holder.
Why the agent should not hold the password
A password given to an agent travels through places nobody designed to protect it: the model's context, tool output, logs and saved transcripts. Once it is there, every later reader inherits it. The safer shape is a split of duties. The agent can request access. Only a person, or a system acting on the person's behalf, grants it. This is the same least-privilege idea as in Access Control Patterns for Enterprise Agents, applied to the moment of sign-in.
A refusal that stops at "no" wastes everyone's time. When an agent or a policy declines to type a password, it should say in the same breath which of these paths is available.
The three patterns
| Pattern | How it works | Best when | Main risk | | --- | --- | --- | --- | | Emailed approve link | Agent requests sign-in; a single-use link is emailed to the account holder; the person clicks while signed in; the agent redeems a session | You control the service and email is trusted for the account | A link reused, forwarded, or approved by the wrong person | | Device code | Service gives the agent a short code and a URL; the person enters the code on another device and approves; the agent polls for the token | The agent has no browser and the service speaks OAuth | Polling too fast, long-lived codes, phishing of the code entry page | | Vault reference | The agent names a stored credential by id; a trusted helper types it into the field or injects it; the agent receives only success or an error | The service only supports passwords and a person already enrolled the secret | The helper becomes the weak point; scope and origin checks matter |
The device flow is standardized in RFC 8628. It exists for clients that lack a usable browser: the person approves on a separate device, and the client polls the token endpoint at a minimum interval until the code is approved or expires. We read the RFC for this post and did not run a device-flow server.
A working approve-link flow
We built the approve link in under fifty lines of Python and ran it. The agent calls start with the account email and a device id and gets back only a request id. The token goes to an injected mailer, so in the lab only the mailbox sees it. The person's click calls approve with the token and the id of a session that the real login system issued; the identity comes from that session, not from an address typed into the call. The agent then calls redeem with the same device id and receives a session once.
The design rule behind this is that the agent should hold nothing it could approve with: no token, and no way to name an identity by typing it.
Twelve tests ran and passed. Among them:
test_agent_holding_only_the_request_id_cannot_approve ... ok
test_other_signed_in_person_cannot_approve ... ok
test_expired_cannot_be_revived ... ok
test_lookalike_address_gets_no_mail ... ok
test_typed_email_is_not_an_identity ... ok
test_every_refusal_looks_the_same ... ok
test_other_device ... ok
test_redeem_twice ... ok
test_start_returns_only_a_request_id ... ok
The token is stored only as a SHA-256 hash and compared with a constant-time function (hmac.compare_digest). An unknown or lookalike address gets the same reply from start as a real one and no mail is sent, so the reply does not reveal which accounts exist. Response time can still give it away: our lab sends the mail inside the call, so a real account takes longer than an unknown one, and a production service should queue the mail instead (the OWASP guidance linked below covers this). Every refusal from approve carries one identical message, so the caller cannot tell a wrong token from an unknown request or a wrong person. Four lookalikes were tried: the digit 1 for the letter l in the domain, a real domain with another domain glued on, a plus-tagged local part, and a domain ending in the Kelvin sign. None produced a mail. We then broke the code four ways to check that the tests could fail: removing the device check, removing the signed-in-person check, returning the token to the caller, and dropping the pending-state check. Each change made at least one test fail.
Steps to adopt an agent-safe sign-in
- Decide where the agent runs and which of the three patterns the service can support.
- Make the agent's request return a request id, never a credential or the emailed token.
- Send the grant to the account holder only, single use, with a short expiry.
- Bind the request to the device or session that asked.
- Issue the session once; mark the request used.
- Write the negative tests: reuse, expiry, wrong device, wrong person, lookalike address, approval before request.
- Log who approved and when, without logging the token.
Negative cases to put in the spec
These are the ones that are easiest to miss. Write them into the acceptance criteria up front.
- Pre-account hijack: someone registers the target email before the real owner does and waits.
- Lookalike address: a visually similar or suffixed address passes a loose comparison.
- Wrong device: the approval is valid but the session is handed to a different machine.
- Replay and reuse: a link or code works a second time.
- Late approval: an expired request is revived by a click.
- Self-approval: the calling code can approve its own request because the interface hands it the token or accepts an identity it typed.
Decision framing
Use the approve link when you own the service and the person is nearby. Use the device code when the service already supports it and the agent has no browser. Use a vault only when neither exists, and treat the helper that types the secret as the most security-sensitive component you have. If none of these fits, the honest answer is that this account is not suitable for unattended agent access.
Risks and limits
- If one agent holds both a mailbox tool and the person's signed-in browser, it can approve itself. Keep those capabilities apart.
- Email is only as secure as the mailbox. An approve link sent to a compromised inbox is a compromised sign-in.
- Our lab keeps state in memory, uses a fake clock, a fake mailer and a stand-in for the login system, and sends no email. It shows the logic, not a production service.
- Token length, expiry and rate limits here are examples. Choose them with your own threat model and the OWASP authentication guidance.
- We did not run a vault helper or a device-flow server.
Related reading
FAQ
- Should an AI agent ever type a password?
- Avoid it. A password in an agent's context can end up in logs, transcripts and tool output. Prefer a flow where the agent starts the sign-in and a person approves it, or where a vault injects the secret without the agent seeing it.
- What is the simplest agent-safe sign-in?
- An emailed approve link. The agent asks for a sign-in and gets a request id, a single-use link goes to the account holder, the person clicks once while signed in as themselves, and the agent receives a session. The agent never receives the link or a password, as long as the service sends the link only to the mailbox.
- When is the device code pattern the better choice?
- When the agent runs somewhere with no browser, such as a server or a command line tool, and the service already supports the OAuth device authorization grant. The person enters a short code on another device.
- What can go wrong with an approve link?
- A link that can be used twice, never expires, works from a different device than the one that asked, or can be approved by someone other than the account holder. Each of these needs an explicit negative test.