# Verify an agent order

Verify an agent's order token for free, see a changed total fail, read how the person approved, and ask the shopper to approve an order that came with no token.

This quickstart gets your store accepting only the agent orders a person approved. Start with the middleware in a few lines, or follow the API step by step under the hood.

## Use the middleware

The fastest path to a store that accepts approved agent orders is the Identify middleware with hosted approvals and one webhook handler:

1. An agent that checks out gets the approve link.
2. The shopper approves the cart.
3. Your store hears back on the webhook and checks the order.

The console's **Set up agent checkout** (from [Get started](https://provenanceauth.com/docs/account/console.md#get-started), or `/authorize/setup`) fills in your key. The [five-minute checkout guide](https://provenanceauth.com/docs/authorize/guides/five-minute-checkout.md) has Express and FastAPI too.

**This package isn't on npm yet.** Until then, every request in these docs runs over HTTP against the [sandbox](https://provenanceauth.com/docs/get-started/sandbox.md).

With access to the private Provenance repository, which your Provenance contact grants, install from it:

```bash
git clone https://github.com/michaelnbane-jpg/provenance.git provenance
cd provenance && pnpm install && pnpm build
node scripts/check-publishable.mjs --out ../provenance-packs
cd ../your-project
npm install ../provenance-packs/provenanceauth-sdk-1.0.0.tgz ../provenance-packs/provenanceauth-rails-1.0.0.tgz ../provenance-packs/provenanceauth-identify-1.0.0.tgz
```

```ts
// middleware.ts: agents that check out get the approve link; people never see a change.
import { Identify } from "@provenanceauth/identify";
import { identifyNext } from "@provenanceauth/identify/next";
import { orderFor } from "./lib/orders";

export const identify = new Identify({ apiKey: "prv_test_…", baseUrl: "https://api.provenanceauth.com" });
export const middleware = identifyNext(identify, { approvals: "hosted", orderFor });

// app/api/provenance/webhook/route.ts: the confirmation, checked against your own order.
import { nextWebhook } from "@provenanceauth/identify/webhooks";
import { identify } from "../../../../middleware";
import { findOrder, markApproved } from "../../../../lib/orders";

export const POST = nextWebhook(
  identify.onApproved((a) => markApproved(a.order_id, a.approval_context), { secret: "whsec_…", orderFor: findOrder }),
);
```

## Under the hood

In this quickstart a shopping agent sends your store an order with a Provenance token. You verify it for free, see a changed total fail, and read how the person approved. Then an order arrives with no token, and you ask the shopper to approve it.

You use curl with `jq`, or Node, or Python, and published sandbox keys, so you don't need an account.

### 1. Get an order token

In production the shopper's agent sends this token with its order. Here you mint one in the sandbox with the published full-access key, standing in for that agent.

The token binds the order: its id, the total in minor units, the currency, your merchant id and your store's origin.

**curl**

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

curl -s $PROVENANCE_API/v1/mandate/intents \
  -H "Authorization: Bearer prv_test_full_K7mN3xQp9RbT2vWm8sYd4cFjLhXn6gAe" \
  -H "Content-Type: application/json" \
  -d '{
    "action_description": "Buy a desk lamp at Brindlecote Home",
    "action_payload": { "order_id": "ord_1042", "total": 4800, "currency": "usd", "merchant_id": "brindlecote-home", "origin": "https://brindlecote-home.example" },
    "agent_session_id": "sess_shopper_1",
    "device_id": "dev_00000000000000000000000000000001"
  }' | tee order-token.json
```

**Node**

```ts
import { Provenance } from "@provenanceauth/sdk";

const order = { order_id: "ord_1042", total: 4800, currency: "usd", merchant_id: "brindlecote-home", origin: "https://brindlecote-home.example" };
const shopperAgent = new Provenance({ apiKey: "prv_test_full_K7mN3xQp9RbT2vWm8sYd4cFjLhXn6gAe", baseUrl: process.env.PROVENANCE_API });
const { intentToken } = await shopperAgent.mandate.intents.create({
  actionDescription: "Buy a desk lamp at Brindlecote Home",
  actionPayload: order,
  agentSessionId: "sess_shopper_1",
  deviceId: "dev_00000000000000000000000000000001",
});
```

**Python**

```python
import os
from provenanceauth import Provenance

order = {"order_id": "ord_1042", "total": 4800, "currency": "usd", "merchant_id": "brindlecote-home", "origin": "https://brindlecote-home.example"}
shopper_agent = Provenance("prv_test_full_K7mN3xQp9RbT2vWm8sYd4cFjLhXn6gAe", base_url=os.environ["PROVENANCE_API"])
intent_token = shopper_agent.mandate.intents.create(
    action_description="Buy a desk lamp at Brindlecote Home",
    action_payload=order,
    agent_session_id="sess_shopper_1",
    device_id="dev_00000000000000000000000000000001",
)["intent_token"]
```

```json
{
  "object": "intent_authorization",
  "biometric_bound": false
}
```

```bash
export INTENT_TOKEN=$(jq -r .intent_token order-token.json)
```

`PROVENANCE_KEY` is now the Enterprise account key, which stands for your store in the next steps.

### 2. Verify the token for free

[`POST /v1/verify`](https://provenanceauth.com/docs/api/verify.md#post-v1-verify) needs no key. Send the token and the order as your own record has it. Build the order from your database, never from the request.

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/verify \
  -H "Content-Type: application/json" \
  -d '{ "token": "'"$INTENT_TOKEN"'", "expected": { "action_payload": { "order_id": "ord_1042", "total": 4800, "currency": "usd", "merchant_id": "brindlecote-home", "origin": "https://brindlecote-home.example" } } }'
```

**Node**

```ts
const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
const free = await prov.verify({ token: intentToken, expected: { actionPayload: order } });
```

**Python**

```python
prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])
free = prov.verify(token=intent_token, expected={"action_payload": order})
```

```json
{
  "object": "verification_result",
  "valid": true,
  "kind": "intent",
  "binding": "match",
  "revoked": false
}
```

`valid: true` checks the signature, the issuer, the expiry and revocation. `binding: "match"` means the token was issued for this exact order. The response carries the token's free claims and a coarse `risk`.

### 3. Change the total

Suppose the agent was steered after the approval and the order total went up. Verify the new total with the same token.

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/verify \
  -H "Content-Type: application/json" \
  -d '{ "token": "'"$INTENT_TOKEN"'", "expected": { "action_payload": { "order_id": "ord_1042", "total": 9800, "currency": "usd", "merchant_id": "brindlecote-home", "origin": "https://brindlecote-home.example" } } }'
```

**Node**

```ts
const changed = await prov.verify({ token: intentToken, expected: { actionPayload: { ...order, total: 9800 } } });
```

**Python**

```python
changed = prov.verify(token=intent_token, expected={"action_payload": {**order, "total": 9800}})
```

```json
{
  "object": "verification_result",
  "valid": false,
  "reason": "binding_mismatch",
  "binding": "mismatch"
}
```

Refuse the order: the person approved the first total, not this one.

### 4. Read how the person approved

The free check says the approval is real. [`POST /v1/authorize/verifications`](https://provenanceauth.com/docs/api/verifications.md#post-v1-authorize-verifications) with your Authorize key also says how the person approved: the method, whether it was biometric, the device's trust tier and the agent's registration.

It applies your [checkout rules](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md), and each call is one Authorize check on your bill.

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/authorize/verifications \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "intent_token": "'"$INTENT_TOKEN"'", "action_payload": { "order_id": "ord_1042", "total": 4800, "currency": "usd", "merchant_id": "brindlecote-home", "origin": "https://brindlecote-home.example" } }'
```

**Node**

```ts
const paid = await prov.authorize.verifications.create({ intentToken, actionPayload: order });
```

**Python**

```python
paid = prov.authorize.verifications.create(intent_token=intent_token, action_payload=order)
```

```json
{
  "object": "verification",
  "valid": true,
  "approval": {
    "biometric_bound": false,
    "hardware_attested": false,
    "device_trust_tier": "simulated"
  }
}
```

The sandbox token came from a simulated device with no person present, so `approval.method` is `null`. A token a person approved with a passkey says `passkey`, with `approved_at` and the approval's id.

### 5. Ask the shopper when there's no token

Another agent checks out with no token. Ask the shopper to approve this exact cart with [`POST /v1/authorize/checkout_approvals`](https://provenanceauth.com/docs/api/checkout-approvals.md#post-v1-authorize-checkout-approvals). By default the agent shows the approval link to its person, so Provenance sends nothing and nobody needs an account.

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/authorize/checkout_approvals \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "cart": { "order_id": "ord_1043", "total": 4800, "currency": "USD", "merchant_id": "brindlecote-home", "origin": "https://brindlecote-home.example",
              "items": [{ "sku": "lamp-desk", "name": "Desk lamp", "quantity": 1, "unit_amount": 4800 }] },
    "display": { "merchant_name": "Brindlecote Home" },
    "retry_url": "https://brindlecote-home.example/checkout",
    "expires_in": 900
  }' | tee checkout-approval.json
```

**Node**

```ts
const approval = await prov.authorize.checkoutApprovals.create({
  cart: { ...order, order_id: "ord_1043", items: [{ sku: "lamp-desk", name: "Desk lamp", quantity: 1, unit_amount: 4800 }] },
  display: { merchantName: "Brindlecote Home" },
  retryUrl: "https://brindlecote-home.example/checkout",
  expiresIn: 900,
});
console.log(approval.approveUrl);
```

**Python**

```python
approval = prov.authorize.checkout_approvals.create(
    cart={**order, "order_id": "ord_1043", "items": [{"sku": "lamp-desk", "name": "Desk lamp", "quantity": 1, "unit_amount": 4800}]},
    display={"merchant_name": "Brindlecote Home"},
    retry_url="https://brindlecote-home.example/checkout",
    expires_in=900,
)
print(approval["approve_url"])
```

```json
{
  "object": "checkout_approval",
  "status": "pending",
  "route": "agent_relay",
  "order_id": "ord_1043"
}
```

The response carries `approve_url`, the page the shopper opens, and `challenge`, the `401` your checkout returns to the agent. Read the approval back with [`GET /v1/authorize/checkout_approvals/{id}`](https://provenanceauth.com/docs/api/checkout-approvals.md#get-v1-authorize-checkout-approvals-id):

**curl**

```bash
export APPROVAL_ID=$(jq -r .id checkout-approval.json)
curl -s $PROVENANCE_API/v1/authorize/checkout_approvals/$APPROVAL_ID \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const pending = await prov.authorize.checkoutApprovals.get(approval.id);
```

**Python**

```python
pending = prov.authorize.checkout_approvals.get(approval["id"])
```

```json
{
  "object": "checkout_approval",
  "status": "pending",
  "decided_at": null
}
```

Open `approve_url` in a browser to approve it as the shopper: the page shows your store, the items and the total, and approves with a passkey on that device.

Once approved, the approval carries an intent token bound to this order, and the agent retries your checkout with it:

```json
{
  "object": "checkout_approval",
  "status": "approved",
  "decided_at": "2026-11-04T21:19:02.000Z",
  "intent_token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6..."
}
```

The approved response also carries `approval_context`: how the person approved, with the passkey, the device and the network. See [approval context](https://provenanceauth.com/docs/concepts/approval-context.md).

Verify that token exactly as in step 2, with the cart as your order: `valid: true` and `binding: "match"`.

## Try it

The [Authorize explorer](https://provenanceauth.com/authorize#endpoints) verifies a token in your browser against the sandbox. To check a token without any call, verify it offline against the published keys: [verify a token](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md).

## Next steps

- [Verify agent checkouts](https://provenanceauth.com/docs/authorize/guides/verify-agent-checkout.md): `verifyAgentCheckout` on your own checkout, with the grant's limits.
- [Ask your own customer](https://provenanceauth.com/docs/authorize/guides/ask-your-own-customer.md): send the approval link to your signed-in customer instead.
- [Assess an agent checkout](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md): one call that returns approved, challenged or rejected.
- [Example apps](https://provenanceauth.com/docs/get-started/example-apps.md): small working apps that use this product end to end.
