# Access: permissions, asking and expiry

Use `https://api.decoys.me`. Every agent asks for access the same way: by permission name, on the connection it already has. The owner approves in the Decoy app and sees the words in the tables below.

## What you can do now

`GET /api/agent/policies` (`my_permissions` with the MCP bridge) answers what this connection may do right now. Read it at the start of every task, after every approval and whenever a call is refused for access. Decide from it, never from `scopes` and never from what you asked for: the owner may approve more or less than you asked, and changes access in the app at any time. What is granted is yours to use, including access the owner added; do not warn about it or suggest narrowing it.

- **`access`**, the first key: a plain summary. Read `access.summary` first (one sentence; when part of the access has an end date it ends with ` Part of this ends <time>.`). Its fields say the same in code: `accounts` (`allowed`, `which`, `count`, and `can.read`, `can.reveal_password`, `can.write`, `can.delete`), `mail` (the same, with `can.list`, `can.read`, `can.send`, `can.delete` and `personal_alias`), `personal_info` (`allowed`, `which`, `can.list`, `can.read`, `can.write`, `can.delete`), `create_accounts.allowed`, `create_addresses.allowed`, and `memories` (`save`, then `read`, `write`, `delete`). Each `can.*` and memory field is a reach word: `all`, `some`, `created_by_you`, `all_account_inboxes` (mail), `own_only` (memories you saved) or `none`; `which` is the widest of them. Then `ends_at`, `can_request_more` and `version`.
- **`policies[]`**: each approved grant, with its `expires_at` and `permissions[]`. Each entry's `permissions` lists the names it gives, beside its selection (`account_id`, `namespace_id`, `record_type`, `personal_id`, `datatypes`, `about`).
- **`access_version`** comes with every token and refresh answer and equals `access.version`. Keep it in your notes; when it differs, read `access` again.

## Permissions

Ask only for what the task needs. The owner sees each permission as its headline and the line below it; ⚑ marks the ones the phone flags as sensitive. What a permission needs is added for you: the answer's `permissions` is the full set the owner sees.

**Accounts**

| Permission | The owner sees | Needs |
| --- | --- | --- |
| `account.create` | Add accounts to Decoy · Saves details for new or existing accounts | Its own row, no selection |
| `account.read` | Read details from all accounts · Password, 2FA codes, notes, custom fields | |
| `account.edit` | Edit all accounts · Password, 2FA setup, notes, custom fields | `account.read` |
| `account.delete` ⚑ | Delete all accounts · Each account, its details and its Decoy email | `account.edit` |

**An account's Decoy email**

| Permission | The owner sees | Needs |
| --- | --- | --- |
| `acctmail.read` | Read all accounts’ email · Messages and attachments | |
| `acctmail.mark` | Mark read or unread · Read or unread state | `acctmail.read` |
| `acctmail.send` | Send and reply from them · From each account’s Decoy email | `acctmail.read` |
| `acctmail.edit` | Edit their addresses · Pause, forwarding, notifications | `acctmail.read` |
| `acctmail.delete` ⚑ | Delete emails · Removes messages from all accounts | `acctmail.read` |

**Memories about an account**

| Permission | The owner sees | Needs |
| --- | --- | --- |
| `acctmem.read` | Read memories about all accounts · Shared context and preferences | |
| `acctmem.edit` | Edit memories about all accounts · Change, re-file, share | `acctmem.read` |
| `acctmem.delete` ⚑ | Delete memories about all accounts · Removed for good | `acctmem.edit` |

**Personal Alias**

| Permission | The owner sees | Needs |
| --- | --- | --- |
| `alias.read` | Read email · Messages and attachments | |
| `alias.mark` | Mark read or unread · Read or unread state | `alias.read` |
| `alias.send` | Send and reply · As your aliases | `alias.read` |
| `alias.edit` | Edit your aliases · Pause, on or off, forwarding, new aliases | `alias.read` |
| `alias.delete` ⚑ | Delete emails · Removes messages from your aliases | `alias.read` |
| `alias.burn` ⚑ | Burn alias addresses · They stop receiving for good | `alias.edit` |

**Personal info**

| Permission | The owner sees | Needs |
| --- | --- | --- |
| `personal.read` | Read all personal info · Identities, emails, cards (⚑ with `record_type: "cards"`) | |
| `personal.edit` | Edit all personal info · Edit and add identities, emails, cards | `personal.read` |
| `personal.delete` ⚑ | Delete all personal info · Identities, emails, cards | `personal.edit` |

**Memories**

| Permission | The owner sees | Needs |
| --- | --- | --- |
| `memory.read` | Read all memories · Shared context and preferences | |
| `memory.save` | Save new memories · Can read and edit its own | Its own row, no selection |
| `memory.edit` | Edit all memories · Change, re-file, share | `memory.read` |
| `memory.delete` ⚑ | Delete all memories · Removed for good | `memory.edit` |

A connection holds one set of memory permissions for all the categories and topics it is given: ask for the same permissions on each, and the owner changes them together.

**`everything`** ⚑ · Everything in your Decoy · Every account, email, info and memory. Always alone, with no selection ([when to ask for it](#everything)).

The headlines above are for all of a kind; with a selection the phone says "this account", "this alias", "selected accounts" and so on. Tell the person what you asked for in these words: "I asked for: Read details from this account."

## Selections

One selection per request. With none, the permission covers all of its kind, now and later.

| Permissions | Selection |
| --- | --- |
| `account.*`, `acctmail.*`, `acctmem.*` | `account_id`. Or, for `account.*` only, `domain` (such as `"netflix.com"`) when you know the site but not the id: the owner's phone matches it to their saved account privately. If the phone finds none, the request grants nothing; it never widens to all accounts. |
| `alias.*` | `namespace_id` for one Personal Alias. Pausing aliases, turning addresses on or off and claiming new aliases need `alias.edit` with no selection. |
| `personal.*` | `record_type` (`identities`, `emails` or `cards`) and/or `personal_id`. Verified addresses are personal info of type `emails`; `personal.edit` on them ("Add verified addresses") takes no `personal_id`. |
| `memory.*` | `datatypes` (memory categories) or `about` (`["topic:<topic id>"]`), never both. The MCP bridge also takes a topic name in `about`. Memories about one account are `acctmem.*` on its `account_id`. |

One request may name `account.*`, `acctmail.*` and `acctmem.*` together on one `account_id`. Several targets are several requests: they join the connection's one open request (the answer carries `combined: true`), and the owner answers them on one sheet. Send only these keys with `permissions`; never `resource_id`, `kind`, `level` or `actions`.

## Ask, wait, read back

```json
{"permissions":["account.read","acctmail.read"],"account_id":"3f1c2a4e-9b7d-4c1e-8a2f-5d6e7f809a1b","reason":"Sign in to Netflix and use the code it emails"}
```

Send it to `POST /api/agent/grant-request` with the connection's bearer token. With the MCP bridge: `request_access({ permissions, <selection>, reason })`, with the same fields. `reason` is one line the owner reads in the app. You cannot ask for a length of time: the owner chooses it.

| Answer | Do |
| --- | --- |
| `201`, `status: "pending"`, `request_id` | Tell the person once, in one sentence, to approve it in the Decoy app. Poll `GET /api/agent/grant-request?id=<request_id>` every few seconds, for up to about 10 minutes. |
| `200`, `status: "already_granted"` | You hold it. Make the call. |
| `201` or `200` with `renewal: true` | A renewal, asked in the last 7 days before access ends ([below](#when-access-ends)): wait on its `request_id`. |
| `409 GRANT_ALREADY_REQUESTED` | The same ask is open: poll its `request_id`. |
| `409 REVIEW_BUSY` | Send it again after `retry_after_seconds`. |
| `409 REVIEW_FULL` | The open request is full: wait for the owner to answer it. |
| `429 RATE_LIMITED` | Wait `retry_after_seconds`, then send it again. |
| `400` | The body is wrong (an unknown key is named, with the one to use): fix it. Never resend it unchanged. |

The poll answers `status`: `pending` (keep polling), `approved`, `resolved` (approved with changes), `denied`, `expired` or `revoked`. After `approved` or `resolved`, read `GET /api/agent/policies` and do what it allows: the poll does not list what was granted. After `denied`, do not ask again unless the person agrees.

### At pairing

The first approval carries the same rows in `authorization_details` (on `POST /oauth/par` or `POST /api/connect`), one row per selection. A first connection asks for these three (memory-only setup: the last two):

```json
{"client_id":"my-agent","authorization_details":[{"type":"https://decoys.me/oauth/types/unlock","permissions":["account.create"]},{"type":"https://decoys.me/oauth/types/unlock","permissions":["memory.save"]},{"type":"https://decoys.me/oauth/types/unlock","permissions":["memory.read"]}]}
```

A row takes `type`, `permissions` and one selection; any other key is refused. Do not add a scope string: the rows bring their own.

### More access later: the same connection

Ask with `POST /api/agent/grant-request` on the connection you have. Never pair again, and never open a second connection, for more access.

## Refusals

| Answer | Do |
| --- | --- |
| `403 INSUFFICIENT_GRANT`, `403 GRANT_EXPIRED` or `403 SCOPE_MISSING` | Every refusal you can ask about carries `permission_request`. Send `permission_request` as the body of `POST /api/agent/grant-request`, unchanged (add a `reason`), wait for the answer, then retry the call. `required_permission` names what is missing. Ignore `remediation`. |
| `200` from `POST /api/agent/context/memories/delete` with ids in `refused` | `permission_requests` maps each refused memory id to `{ required_permission, permission_request }`: send each `permission_request` unchanged, then delete again. |
| `can_request: false` | Nothing can be asked: tell the person what `message` says. |
| `403 ALERTS_OWNER_ONLY` | Alerts are not shared with agents. |
| `403 PASSKEYS_OWNER_ONLY` | Agents never add or remove passkeys. `account.edit` covers the password, 2FA codes, notes and custom fields. |
| `403 ACCOUNT_EMAIL_GOES_WITH_ACCOUNT` | An account's Decoy email is never burned, replaced or rotated on its own; it goes only with its account (`account.delete`). |
| `403 VAULT_KEY_REQUIRED`, `403 MAILBOX_KEY_REQUIRED` | The call needs `everything` ([below](#everything)). Use the sealed path instead where there is one. |

A `POST /api/agent/unlock` refusal that carries `granted_datatypes` is not an ask: retry with one of those kinds in `target.datatypes`.

### A list that is not everything

`GET /api/agent/decoys`, `/api/agent/inbox` and `/api/agent/accounts` answer with what this connection may see. When access leaves out some of the person's records, the first page says so with `hidden_by_access: true`: the list is not everything, never that the person has none, and never an error. Beside it:

- `access_requests`: the access that would show them, each the body of one `POST /api/agent/grant-request` (add a `reason`), for every record of its kind. Ask only for what the task needs: add `account_id` or `namespace_id` to narrow one to a single account or Personal Alias. When it is empty, no permission covers what was left out.
- `tell_the_person`: one sentence in everyday words, for when the person asks what is missing, or a list still says this after an approval. After you ask, the request's own answer says what to tell them.

When the task does not need the records left out, go on with what you can see.

## Details, email and memories are separate

Account details do not bring the account's email or its memories. When you know the site but not the account id, it takes two asks:

1. `{"permissions":["account.read"],"domain":"netflix.com"}`. Once approved, find the account in `GET /api/agent/accounts` (its `id`; the name is `service_name` or its `metadata_seal`).
2. `{"permissions":["acctmail.read","acctmail.send"],"account_id":"<that id>"}` (only the email permissions the task needs).

With the id already known, one request can carry both: `{"permissions":["account.read","acctmail.read"],"account_id":"<id>"}`, as in the example above.

## Reading and sending over HTTP

One path for each. Each answer that is still waiting follows [wait before you ask](/agent-recipes.md#wait-before-you-ask).

| Task | Call | Needs |
| --- | --- | --- |
| An account's password, 2FA code or custom fields | `GET /api/agent/sealed-secrets` (items with `kind: "account"` and `target_id` the account id; open `sealed_envelope` with your key). Not there yet: `POST /api/agent/unlock` with `{"target":{"kind":"account","id":"<account id>"},"reason":"<the task>"}` | `account.read` |
| An account's Decoy address (`decoy_id`, `decoy_email`) | `GET /api/agent/accounts/{id}` | `account.read`, or an account you created |
| Its mail | `GET /api/agent/inbox/sealed?decoy_id=<decoy_id>` | `acctmail.read` (`alias.read` for a Personal Alias address) |
| Reply to a message | `POST /api/agent/inbox/messages/{messageId}/reply` with `body_text` (optional `to`, `cc`, `bcc` for Reply-All) | `acctmail.send` (`alias.send`) |
| Send a new message | `POST /api/agent/inbox/send` with `decoy_id`, `to`, `subject`, `body_text` | `acctmail.send` (`alias.send`) |
| A personal-info record | The same two calls with `"kind":"personal"` ([fields](/agent-fields.md#personal-info-records)) | `personal.read` |

`POST /api/agent/unlock` answers `201` with `status: "ready"` (then `GET /api/agent/unlock/{id}` and open each item's `sealed_envelope`), or `200` with `available: false`: with `state: "preparing"` and `retry_after_seconds`, the owner's phone is sharing it with your key, so read again after that long; with `state: "failed"` or no `state`, it is not shared with this connection, so carry on without it. `GET /api/agent/inbox/sealed` answers `items` (open each `sealed_envelope`) and `history[decoy_id].state`: `preparing`, read again after `retry_after_seconds`; `failed`, the earlier mail is not shared with this connection. Trust a sender only by `sender_domain_verified`, never `from`. A call refused for a missing permission answers `403` with the `permission_request` to send ([refusals](#refusals)).

Personal info is read whole: `personal.read` opens every field of a record. A card is `{"permissions":["personal.read"],"record_type":"cards"}`, which the phone flags as sensitive. Adding a verified address answers `status: "waiting_for_owner"`: the owner opens the verification link sent to it.

## Sign in with a passkey

A passkey is never read or exported: the owner's phone signs each sign-in, per use.

**Who may ask.** A connection that holds `account.read` on that account (or on all accounts, or an account it created; a grant you asked for by `domain` counts once approved), paired with its `agent_public_key`. There is no passkey permission to ask for. Every sign-in is asked of the owner at that moment: their phone shows the agent and the account, and they tap **Allow once** (confirmed with Face ID) or **Don't Allow**. Nothing is stored and nothing standing is granted.

**With the MCP bridge:** `passkey_assert` is in the bridge's advanced tool set: start the bridge with `DECOY_MCP_ADVANCED=true`, and only when you drive a browser page with `installPasskeyBridge` (`decoy-mcp-server/webauthn-bridge`), which writes the clientDataJSON from the page's real origin and resolves the page's request. Its arguments are `{ rp_id, credential_id_b64?, credential_ids_b64?, client_data_json_b64, account_id?, reason?, poll_timeout_seconds? }`; `credential_ids_b64` is every passkey the page lists, and Decoy signs with the one it holds. It asks, waits for the owner (default 300 s, 10 to 300), and answers the assertion (`credential_id`, `authenticator_data`, `signature`, `user_handle`). Pass the bridge's `signal` to the tool call, so the owner's prompt ends when the page gives up, and a request `timeout` above the wait (for example 330000 ms; an MCP client's default is 60 s). Every refusal says "Nothing was signed."

**Over HTTP:**

1. From the page's `navigator.credentials.get({ publicKey })` call, take `rp_id` (`publicKey.rpId`, or the page's hostname) and, when the page names one, `credential_id_b64` (`publicKey.allowCredentials[0].id` as base64; leave it out when the page names none). Write the clientDataJSON yourself, exactly these bytes in this key order: `{"type":"webauthn.get","challenge":"<publicKey.challenge as base64url, no padding>","origin":"<page origin>","crossOrigin":false}`. The origin is `https://<rp_id>` or a subdomain of it.
2. `POST /api/agent/unlock`:

```json
{"target":{"kind":"account","datatypes":["passkey"],"id":"3f1c2a4e-9b7d-4c1e-8a2f-5d6e7f809a1b","passkey":{"rp_id":"example.com","credential_id_b64":"<base64>","client_data_json_b64":"<base64 of the exact clientDataJSON bytes>"}},"reason":"Sign in to check the order"}
```

   `target.id` (the account) is needed only when the owner has more than one passkey for the site and the page named none. `datatypes` is exactly `["passkey"]`. `reason` is plain text, at most 200 characters. The answer is `201` with `id`, `status: "pending"` and `expires_at`: the owner has been asked.
3. Poll `GET /api/agent/unlock?id=<id>` every 2 to 3 seconds: `pending`; `ready` with `items: [{ target_id, sealed_envelope }]`, returned once; `denied` (nothing was signed); `expired` (no answer within 5 minutes; nothing was signed).
4. Open `sealed_envelope` with your private key (the same envelope as sealed mail). It holds JSON, all base64: `credential_id`, `authenticator_data`, `signature`, `user_handle` (may be null).
5. Resolve the page's `navigator.credentials.get` with a PublicKeyCredential: `id` = `credential_id` as base64url, `rawId` its bytes, `type: "public-key"`, `response` with `clientDataJSON` (the **same bytes** you sent), `authenticatorData`, `signature` and `userHandle` from the envelope, and `getClientExtensionResults()` returning `{}`. The site verifies it like any passkey sign-in.

**The page gave up** (its timeout, or it was cancelled): withdraw the ask with `DELETE /api/agent/unlock/{id}`, so the owner is no longer asked to sign something nobody waits for. `200` with `status: "expired"`; `409` once it was answered.

**Page caution.** Many sites start a background passkey request when the page loads (`mediation: "conditional"`). Never forward that one: the owner would be asked before you did anything. Forward only the sign-in you trigger.

| Answer | Do |
| --- | --- |
| `403 INSUFFICIENT_GRANT` with `permission_request` (`account.read` on the account) | Send it unchanged to `POST /api/agent/grant-request`; after approval, try again. Each sign-in is then still asked. |
| `422 PASSKEY_AMBIGUOUS` | More than one passkey for the site: call again with `target.id` (bridge: `account_id`) set to the account, or the credential id the page asked for. If you already sent the account, ask the person which passkey or account to use; don't loop. |
| `404 PASSKEY_NOT_FOUND` | The owner has no passkey there. Do not retry. |
| `422 PASSKEY_ORIGIN_MISMATCH` | The clientDataJSON origin is not `rp_id` or a subdomain of it: fix the page context. |
| `422 PASSKEY_BAD_CLIENT_DATA` | Rebuild the clientDataJSON as in step 1. |
| `422 PASSKEY_ASSERT_REQUIRED` | Send `rp_id` and `client_data_json_b64`. |
| `400 PASSKEY_BAD_REQUEST` | `passkey` with other datatypes, kind not `account`, or a credential id that is not base64: fix the request. |
| `422 NO_AGENT_PUBLIC_KEY` | The connection was paired without an agent key; the signature cannot be sealed to it. |
| `429 RATE_LIMITED` | More than 20 asks a minute: wait `retry_after_seconds`. |
| Poll `denied` | The owner declined. Reject the page's pending `navigator.credentials.get` with a `NotAllowedError`, do not retry on your own, and ask the person what they want. |
| Poll `expired` | Reject the page's pending request the same way; ask again only if the person still wants it. |
| `401 TOKEN_REVOKED` while polling | The connection was revoked; the request cannot be signed. |

Agents never add or remove passkeys (`403 PASSKEYS_OWNER_ONLY`).

## What you create

You read, edit and send from the accounts and addresses this connection created, without asking. Deleting one needs `account.delete` (an account goes with its Decoy email); burning a Personal Alias address needs `alias.burn`.

A connection without the vault key creates an account **with its address** through `POST /api/agent/decoys` (`service_name`, optional `service_url`), and saves its password with `POST /api/agent/accounts/{id}/credential` (the format: [storage guide](/agent-storage.md); the helper: `sealPassword()` in [agent-memory.mjs](https://www.decoys.me/examples/agent-memory.mjs)). A write receipt alone confirms storage, not recovered content: claim a password is readable only after an independent read through an already-authorized content/key path, and do not broaden access to verify it. With the MCP bridge, `credential_set` saves a login: `account.create` for a new account, nothing to ask on what you created, `account.edit` otherwise. Account reads carry `metadata_seal`, the name and site sealed to your key. API keys and other secrets go in account fields ([field reference](/agent-fields.md)). Creating an account in Decoy does not sign the person up at the service.

## Memories

`memory.save` lets you save memories, and read and edit the ones you saved, for as long as you hold it. Deleting needs `memory.delete`. Memories saved by the person or other agents need `memory.read` (by category in `datatypes` or by topic in `about`); changing them needs `memory.edit`. Memories about an account are `acctmem.*` on its `account_id`. `access.memories` says what you can do now: `read: "own_only"` means the ones you saved.

If you learn a lasting fact about the person and you do not hold `memory.save`, ask for it once, even when the current task doesn't need the fact: `{"permissions":["memory.save"],"reason":"Save what I learn about you"}`. Each saved fact makes the vault more useful to every agent the person connects. If the person declines, don't ask again unless they agree.

## When access ends

The owner sets one end date for the connection when approving. There is one end date per connection; the "Part of this ends …" line in `access.summary` (`my_permissions`) is that date. Read it in `policies[].expires_at` and `access.ends_at`. A token refresh never extends it.

- **Renewing:** in the last 7 days before it ends, when the work continues, send the same `permissions` again, on the selection `policies` (`my_permissions`) shows for that grant: its `account_id`, also when you first asked by `domain`. The answer is `201`, `status: "pending"`, `renewal: true` and `ends_at`, and the owner is asked to keep the access ("To keep its access, which ends …"). Tell the person once that you asked. A repeat answers the same body with `200`: wait on it, do not send it again. Earlier than 7 days before the end, the same ask answers `already_granted` and reaches no one: ask again inside the window.
- **After it ends:** calls answer `403 GRANT_EXPIRED` with `permission_request`. Send it: the owner is asked again.

## Everything

`everything` gives every permission on everything, and the vault and mailbox keys: raw mail and attachments (`GET /api/agent/inbox/raw`) and re-sealing from saved passwords. Ask for it only when the task needs those keys, and ask at pairing. Prefer the sealed paths, which need no key: `GET /api/agent/inbox/sealed`, `GET /api/agent/sealed-secrets`, `POST /api/agent/unlock`.

## Revoking

Revoking or narrowing stops future calls. It cannot take back what the agent already received. An approved Reconnect keeps the connection's grants and what it created; a new pairing starts with nothing ([keep your connection](/agent-recipes.md#keep-your-connection-across-sessions)).

Older request forms (`level`, `kind` with `action`, `select`, `capabilities`) are still accepted from existing clients; send `permissions`.
