# Let people connect

Add a Connect URL so a person can pick your agent in Provenance and finish in your app, or show a code they enter in Provenance. Both end in a network grant bound to that person.

A person can start connecting your agent from their side, in Provenance, two ways:

- **From the directory:** they pick your agent, sign in to your app, and set the limits in Provenance. This needs a **Connect URL**.
- **With a code:** your agent shows an 8-letter code, the person enters it in Provenance and sets the limits. This is the device-authorization pattern from RFC 8628.

Both end where [Connect an agent](https://provenanceauth.com/docs/mandate/guides/connect-an-agent.md) ends: a [network grant](https://provenanceauth.com/docs/mandate/concepts/network-grants.md) for your agent, bound to that person. Your agent gets the permission they approve and nothing else: never their name, email or what they do with other agents.

**Before you begin:** your agent is registered with an Identify signing key and listed in the agent directory (network grants are for verified agents).

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
```

## Add a Connect URL

[`PUT /v1/mandate/agents/{id}/connect_url`](https://provenanceauth.com/docs/api/agents.md#put-v1-mandate-agents-id-connect-url) sets where "Continue to your agent" lands. It must be https. You can also set it in the console under Agents.

**curl**

```bash
export AGENT_ID=$(curl -s -X POST $PROVENANCE_API/v1/mandate/agents -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" -d '{ "name": "cartwise", "category": "shopping_agent" }' | jq -r .id)
curl -s -X PUT $PROVENANCE_API/v1/mandate/agents/$AGENT_ID/connect_url \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "connect_url": "https://cartwise.example/connect" }'
```

**Node**

```ts
const headers = { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" };
await fetch(`${process.env.PROVENANCE_API}/v1/mandate/agents/${process.env.AGENT_ID}/connect_url`, {
  method: "PUT", headers, body: JSON.stringify({ connect_url: "https://cartwise.example/connect" }),
});
```

**Python**

```python
import os
import httpx

api, h = os.environ["PROVENANCE_API"], {"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"}
httpx.put(f"{api}/v1/mandate/agents/{os.environ['AGENT_ID']}/connect_url", headers=h, json={"connect_url": "https://cartwise.example/connect"})
```

```json
{
  "object": "agent_connect_url",
  "connect_url": "https://cartwise.example/connect"
}
```

When a person continues to your agent, Provenance opens your Connect URL with `?provenance_connect=…`, a single-use token that works for 10 minutes. Sign the person in to your app, then redeem the token with your key and the limits you ask for. You get a grant request already bound to that person; send them to its `grant_url`.

**curl**

```bash norun
curl -s -X POST $PROVENANCE_API/v1/mandate/connect_intents/redeem \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "token": "'$PROVENANCE_CONNECT'", "proposed": { "max_amount": 50, "budget_amount": 200, "budget_window": "month", "currency": "USD", "expires_at": "2027-06-30T00:00:00Z" } }'
```

**Node**

```ts
const request = await (await fetch(`${process.env.PROVENANCE_API}/v1/mandate/connect_intents/redeem`, {
  method: "POST", headers,
  body: JSON.stringify({ token: provenanceConnect, proposed: { max_amount: 50, budget_amount: 200, budget_window: "month", currency: "USD", expires_at: "2027-06-30T00:00:00Z" } }),
})).json();
// Send the person to request.grant_url
```

**Python**

```python
request = httpx.post(f"{api}/v1/mandate/connect_intents/redeem", headers=h, json={
    "token": provenance_connect,
    "proposed": {"max_amount": 50, "budget_amount": 200, "budget_window": "month", "currency": "USD", "expires_at": "2027-06-30T00:00:00Z"},
}).json()
# Send the person to request["grant_url"]
```

Only the account that owns the agent can redeem its tokens, and each token works once. Without a Connect URL, Provenance tells the person to ask your agent to connect.

## Connect with a code

[`POST /v1/mandate/connect_codes`](https://provenanceauth.com/docs/api/network.md#post-v1-mandate-connect-codes) returns a `user_code` to show the person, a `device_code` to keep, and how often to poll. Codes use letters only, last 10 minutes and work once.

**curl**

```bash norun
curl -s -X POST $PROVENANCE_API/v1/mandate/connect_codes \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "agent_id": "'$AGENT_ID'", "proposed": { "max_amount": 50, "budget_amount": 200, "budget_window": "month", "currency": "USD", "expires_at": "2027-06-30T00:00:00Z" } }'
```

**Node**

```ts
const code = await (await fetch(`${process.env.PROVENANCE_API}/v1/mandate/connect_codes`, {
  method: "POST", headers,
  body: JSON.stringify({ agent_id: process.env.AGENT_ID, proposed: { max_amount: 50, budget_amount: 200, budget_window: "month", currency: "USD", expires_at: "2027-06-30T00:00:00Z" } }),
})).json();
```

**Python**

```python
code = httpx.post(f"{api}/v1/mandate/connect_codes", headers=h, json={
    "agent_id": os.environ["AGENT_ID"],
    "proposed": {"max_amount": 50, "budget_amount": 200, "budget_window": "month", "currency": "USD", "expires_at": "2027-06-30T00:00:00Z"},
}).json()
```

```json
{
  "object": "connect_code",
  "user_code": "QSXT-BKLM",
  "device_code": "dvc_…",
  "verification_url": "https://app.provenanceauth.com/me/connect/code",
  "verification_url_complete": "https://app.provenanceauth.com/me/connect/code?code=QSXT-BKLM",
  "expires_in": 600,
  "interval": 5
}
```

Show the code and the address. The person enters it in Provenance, sees your agent, and sets its limits.

If your agent has a screen, also show `verification_url_complete` as a QR code. The person points their phone's camera at it and lands in the Provenance app, or on the same page, with the code filled in. It carries only the code, so they still check your agent and continue as if they had typed it.

While you wait, poll [`POST /v1/mandate/connect_codes/token`](https://provenanceauth.com/docs/api/network.md#post-v1-mandate-connect-codes-token) every `interval` seconds. The grant goes to the person who entered the code, once. Five wrong codes lock that person's entry for 15 minutes.

## When a person blocks your agent

A person can block an agent they haven't connected when it asks them for something. After that, its requests to them are denied with `blocked_by_person` (a routed approval comes back denied with `deny_reason: "blocked_by_person"`, a connect token or code answers 403), and you see only that reason. Only the person can unblock it.

## Errors you might see

| Code | What to do |
| --- | --- |
| `authorization_pending` | Keep polling. |
| `slow_down` | Wait 5 seconds longer between polls. |
| `expired_token` | The code expired or its grant was already handed over. Make a new code. |
| `access_denied` | The person declined. Stop. |
| `connect_token_invalid` | The token expired, was already redeemed, or belongs to another account's agent. Ask the person to continue to your agent again. |
| `network_agent_unverified` | Register a signing key for the agent first. |

A `200` from the poll carries `network_mandate`: keep it like a credential and buy under it.

## See also

- [Connect an agent](https://provenanceauth.com/docs/mandate/guides/connect-an-agent.md)
- [Network grants](https://provenanceauth.com/docs/mandate/concepts/network-grants.md)
- [Connect your own assistant](https://provenanceauth.com/help/personal/guides/connect-your-assistant)
