> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart: Let Personal Agents Shop Your Store

> Start from a working store with Auth0 login, add the Personal Agent Protocol (Poppy) with the Auth0 SDKs and CLI, and watch a personal agent fill a cart, sign the customer in, and place an order.

> [!WARNING]
>
> **The Support for Personal Agent Protocol (Poppy) feature is in [Beta](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages.md).**
>
> By using this feature, you agree to the applicable Free Trial terms in Okta's [Master Subscription Agreement](https://www.okta.com/legal).

> [accordion] Use AI to integrate Personal Agent Protocol
>
> If you use an AI coding assistant like Claude Code, Cursor, or GitHub Copilot, install the Auth0 [agent skill](https://agentskills.io/home). It knows the Poppy SDK options, the CLI commands, and the errors in this guide.
>
> **Install:**
>
> ```bash theme={null}
> npx skills add auth0/agent-skills --skill auth0
> ```
>
> **Then ask your AI assistant:**
>
> ```text theme={null}
> Add Personal Agent Protocol (Poppy) to my store with Auth0
> ```
>
> [Full agent skills documentation →](https://auth0.com/docs/quickstart/agent-skills.md)

**Prerequisites:**

* An Auth0 tenant with the Personal Agent Protocol beta enabled. Use a development tenant: this quickstart changes tenant settings
* **[Node.js](https://nodejs.org/en/download)** 22 or newer, and **Git**
* **[ngrok](https://ngrok.com/download)** with a free account and its authtoken configured. Agents only call public HTTPS hosts

Verify installation: `node --version && git --version && ngrok --version`

Commands are for macOS and Linux shells. On Windows, use WSL.

## Get Started

You start from Drift Bean Demo, a sample coffee store with Auth0 login and guest carts already working. It has a Next.js website, an Express website, and one Node.js API that both websites use. You turn on the Personal Agent Protocol in your tenant, add it to the code with the Auth0 SDKs, and shop the store with a real personal agent, the [Poppy Playground](https://poppyplayground.dev/).

> [!TIP]
>
> Want to see the finished result first? Open the [Poppy Playground](https://poppyplayground.dev/) and enter `https://driftbeandemo.com`.

To get started, pick your website's stack in the stack selector on the right-hand menu. The steps follow your stack choice.

**Next.js**

**Next.js:** the website in `apps/web` uses `@auth0/nextjs-auth0`. The API uses `@auth0/auth0-api-js`. The starter already has both SDKs installed.

**Express**

**Express:** the website in `apps/web-express` uses `@auth0/auth0-express`. The API uses `@auth0/auth0-api-js`. The starter already has both SDKs installed.

**1. Install the Auth0 CLI and log in**

The beta build of the Auth0 CLI has the `poppy` and `agents` commands:

```shellscript Mac/Linux theme={null}
brew tap auth0/auth0-cli && brew install auth0-beta && auth0 login
```

```powershell Windows theme={null}
scoop bucket add auth0 https://github.com/auth0/scoop-auth0-cli.git; scoop install auth0-beta; auth0 login
```

Log in to the tenant that has the Personal Agent Protocol beta enabled. Every `auth0` command in this quickstart runs on the CLI's active tenant, so check that `auth0 tenants list` marks it as active, and that the build has the Poppy commands with `auth0 poppy --help`. If logging in as a user fails, log in with a [machine-to-machine application](https://auth0.com/docs/get-started/auth0-overview/create-applications/machine-to-machine-apps.md) instead:

```shellscript theme={null}
auth0 login --domain YOUR_AUTH0_DOMAIN --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRET
```

**2. Get the starter store**

Clone the `starter` branch, which contains the sample app without Auth0 configured:

```shellscript theme={null}
git clone --branch starter https://github.com/auth0-samples/auth0-poppy-sample.git && cd auth0-poppy-sample && npm run install:all
```

**3. Connect the store to Auth0**

Create the store's API and application, and turn on guest carts:

> [tab] Auth0 CLI
>
> ```shellscript theme={null}
> npm run tenant -- --yes --write-env
> ```
>
> `npm run tenant` makes its changes with your CLI login and writes `.env.local`. Run it without `--yes` to see the plan first. If your login lacks a permission, it prints the `auth0 login --scopes` command that adds it. If your tenant already has an application named Drift Bean Storefront, it updates that one: pass `--client-id` to use another.

> [tab] Management API
>
> Set your tenant's domain and a [Management API access token](https://auth0.com/docs/secure/tokens/access-tokens/management-api-access-tokens):
>
> ```shellscript theme={null}
> export AUTH0_DOMAIN=YOUR_AUTH0_DOMAIN MGMT_TOKEN=YOUR_MGMT_API_TOKEN
> ```
>
> Create the API, with an anonymous-user policy for guest carts:
>
> ```shellscript theme={null}
> curl --fail-with-body --request POST --url "https://$AUTH0_DOMAIN/api/v2/resource-servers" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data '{
>     "name": "Drift Bean Carts API",
>     "identifier": "http://localhost:4000",
>     "allow_offline_access": true,
>     "skip_consent_for_verifiable_first_party_clients": true,
>     "scopes": [
>       { "value": "cart:write", "description": "Add and remove items in your cart" },
>       { "value": "orders:read", "description": "See your orders and their status" },
>       { "value": "orders:write", "description": "Place orders with your saved address and payment method" }
>     ],
>     "subject_type_authorization": {
>       "user": { "policy": "allow_all" },
>       "client": { "policy": "require_client_grant" },
>       "anonymous_user": { "policy": "require_client_grant" }
>     }
>   }'
> ```
>
> Create the storefront application with anonymous sessions, and keep its client ID:
>
> ```shellscript theme={null}
> AUTH0_CLIENT_ID=$(curl --silent --fail-with-body --request POST --url "https://$AUTH0_DOMAIN/api/v2/clients" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data '{
>     "name": "Drift Bean Storefront",
>     "app_type": "regular_web",
>     "token_endpoint_auth_method": "client_secret_post",
>     "grant_types": ["authorization_code", "refresh_token"],
>     "callbacks": ["http://localhost:3000/auth/callback"],
>     "allowed_logout_urls": ["http://localhost:3000"],
>     "web_origins": ["http://localhost:3000"],
>     "anonymous_sessions": { "active": true }
>   }' | node -pe 'JSON.parse(require("fs").readFileSync(0)).client_id') && export AUTH0_CLIENT_ID && echo "$AUTH0_CLIENT_ID"
> ```
>
> Create two client grants that let your application call your API: one for signed-in customers, with cart and order scopes, and one for guests, with `cart:write` only:
>
> ```shellscript theme={null}
> for GRANT in '"subject_type": "user", "scope": ["cart:write", "orders:read", "orders:write"]' \
>              '"subject_type": "anonymous_user", "scope": ["cart:write"]'; do
>   curl --fail-with-body --request POST --url "https://$AUTH0_DOMAIN/api/v2/client-grants" \
>     --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>     --data "{ \"client_id\": \"$AUTH0_CLIENT_ID\", \"audience\": \"http://localhost:4000\", $GRANT }"
> done
> ```
>
> Copy `.env.example` to `.env.local`, and fill in `AUTH0_DOMAIN`, `AUTH0_CLIENT_ID`, the application's `AUTH0_CLIENT_SECRET`, and an `AUTH0_SECRET` from `openssl rand -hex 32`.

Start the store:

**Next.js**

```shellscript theme={null}
npm run dev
```

**Express**

```shellscript theme={null}
npm run dev:express
```

Open [http://localhost:3000](http://localhost:3000), add something to the cart, and sign up. The cart follows you into your account. Leave the store running.

**4. Give the store public URLs**

In a second terminal in the `auth0-poppy-sample` folder, open tunnels to the store and its API, and leave it running:

```shellscript theme={null}
npm run tunnel
```

It writes the public URLs to `.env.local`. In the first terminal, stop the store with `Ctrl+C` and start it again, so it reads them.

In a third terminal in the same folder, load the URLs into your shell, and run the rest of this quickstart there:

**Next.js**

```shellscript theme={null}
export $(grep -E '^(AUTH0_DOMAIN|AUTH0_CLIENT_ID|APP_BASE_URL|POPPY_DOMAIN|PUBLIC_ORIGIN)=' .env.local | xargs) POPPY_FILE=apps/web/poppy.json WEB_UNSCOPED=false && echo "Store: $APP_BASE_URL  API: $PUBLIC_ORIGIN"
```

**Express**

```shellscript theme={null}
export $(grep -E '^(AUTH0_DOMAIN|AUTH0_CLIENT_ID|APP_BASE_URL|POPPY_DOMAIN|PUBLIC_ORIGIN)=' .env.local | xargs) POPPY_FILE=apps/web-express/poppy.json WEB_UNSCOPED=true && echo "Store: $APP_BASE_URL  API: $PUBLIC_ORIGIN"
```

If your ngrok URLs change when you restart ngrok, repeat steps 5 and 6. A static domain from the ngrok dashboard avoids that.

**5. Turn on Personal Agent Protocol in your tenant**

Turn on Poppy for your tenant, API, and application, and write `poppy.json`, the discovery file your website serves:

> [tab] Auth0 CLI
>
> ```shellscript theme={null}
> auth0 poppy setup \
>   --company-domain "$POPPY_DOMAIN" \
>   --company-name "Drift Bean Demo" \
>   --app "Drift Bean Storefront" \
>   --api http://localhost:4000 \
>   --api-url "http://localhost:4000=$PUBLIC_ORIGIN/openapi.json" \
>   --login-uri "$APP_BASE_URL/auth/login" \
>   --hint "orders:read=changes:none,personal_data:true" \
>   --hint "orders:write=changes:irreversible,personal_data:true" \
>   --web-unscoped="$WEB_UNSCOPED" \
>   --always-issue-refresh-tokens=false \
>   --skip-doctor \
>   --out "$POPPY_FILE"
> ```
>
> `setup` shows every change before and after, and asks you to confirm. It marks the settings that affect every application in your tenant, and points the application's Login URI at this store. It also warns that `http://localhost:4000` isn't an `https` identifier: that's expected for this local sample.
>
> `WEB_UNSCOPED`, from step 4, is `false` for the Next.js website: it asks for the API's scopes at login, so the API can limit an agent to what the customer approved. It is `true` for the Express website: `@auth0/auth0-express` can't ask for API scopes, so an agent joined through it has the customer's full access there, and the discovery file says so.

> [tab] Management API
>
> In this terminal, set your Management API access token again:
>
> ```shellscript theme={null}
> export MGMT_TOKEN=YOUR_MGMT_API_TOKEN
> ```
>
> Turn on Poppy for the tenant. The request replaces the list of company domains, so include any your tenant already has. The default audience applies to every application in your tenant:
>
> ```shellscript theme={null}
> curl --fail-with-body --request PATCH --url "https://$AUTH0_DOMAIN/api/v2/tenants/settings" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data "{
>     \"personal_agent_protocol_company_domains\": [\"$POPPY_DOMAIN\"],
>     \"client_id_metadata_document_supported\": true,
>     \"authorization_response_iss_parameter_supported\": true,
>     \"resource_parameter_profile\": \"compatibility\",
>     \"default_audience\": \"http://localhost:4000\"
>   }"
> ```
>
> Turn it on for the API. `PATCH` replaces the whole `scopes` array, so the request lists every scope:
>
> ```shellscript theme={null}
> curl --fail-with-body --request PATCH --url "https://$AUTH0_DOMAIN/api/v2/resource-servers/http%3A%2F%2Flocalhost%3A4000" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data '{
>     "use_for_personal_agent_protocol": true,
>     "agent_subject_claims": "auth0-v1",
>     "allow_offline_access": true,
>     "scopes": [
>       { "value": "cart:write", "description": "Add and remove items in your cart" },
>       { "value": "orders:read", "description": "See your orders and their status" },
>       { "value": "orders:write", "description": "Place orders with your saved address and payment method" },
>       { "value": "poppy:browser-sign-in", "description": "Use the website on your behalf, with the permissions you approve" }
>     ]
>   }'
> ```
>
> Turn on the browser join for the storefront application:
>
> ```shellscript theme={null}
> curl --fail-with-body --request PATCH --url "https://$AUTH0_DOMAIN/api/v2/clients/$AUTH0_CLIENT_ID" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data "{ \"allow_personal_agent_browser_join\": true, \"initiate_login_uri\": \"$APP_BASE_URL/auth/login\" }"
> ```
>
> Write `poppy.json`. `auth.issuer` must match your tenant's issuer exactly with its trailing slash. If you use a custom domain, use it in `issuer` and `browser_session_endpoint`:
>
> ```shellscript theme={null}
> cat > "$POPPY_FILE" <<EOF
> {
>   "protocol_version": "1.0",
>   "organization": { "name": "Drift Bean Demo", "domain": "$POPPY_DOMAIN" },
>   "auth": {
>     "issuer": "https://$AUTH0_DOMAIN/",
>     "scopes": {
>       "cart:write": "Add and remove items in your cart",
>       "orders:read": "See your orders and their status",
>       "orders:write": "Place orders with your saved address and payment method",
>       "poppy:browser-sign-in": "Use the website on your behalf, with the permissions you approve"
>     },
>     "scope_hints": {
>       "orders:read": { "changes": "none", "personal_data": true },
>       "orders:write": { "changes": "irreversible", "personal_data": true }
>     }
>   },
>   "apis": [{ "type": "openapi", "url": "$PUBLIC_ORIGIN/openapi.json", "description": "Cart and orders" }],
>   "web": { "browser_session_endpoint": "https://$AUTH0_DOMAIN/poppy/$AUTH0_CLIENT_ID/browser-session", "unscoped": $WEB_UNSCOPED }
> }
> EOF
> ```

**6. Allow a personal agent**

Let your API accept [DPoP-bound tokens](https://auth0.com/docs/secure/sender-constraining/demonstrating-proof-of-possession-dpop.md), which the Playground's agent requires. Then register the agent, add the store's public URLs to its application, and let agents sign customers in with your database connection. Agents are third-party applications, which can only use [domain-level connections](https://auth0.com/docs/authenticate/identity-providers/promote-connections-to-domain-level.md). Making the connection domain-level opens it to every third-party application in your tenant.

> [tab] Auth0 CLI
>
> ```shellscript theme={null}
> auth0 apis update http://localhost:4000 \
>   --data '{"proof_of_possession": {"mechanism": "dpop", "required": false}}' && \
> auth0 agents register https://poppyplayground.dev/agent.json \
>   --api http://localhost:4000 \
>   --scopes "cart:write,orders:read,orders:write,poppy:browser-sign-in" \
>   --config "$POPPY_FILE" \
>   --require-dpop && \
> npm run tenant -- --store-url "$APP_BASE_URL" --yes && \
> CONNECTION_ID=$(auth0 connections list --query '{"name":"Username-Password-Authentication"}' --json | node -pe 'JSON.parse(require("fs").readFileSync(0))[0].id') && \
> auth0 connections update "$CONNECTION_ID" --data '{"is_domain_connection": true}'
> ```
>
> DPoP stays optional on the API, so the storefront's own bearer tokens keep working. `npm run tenant -- --store-url` adds the store's public URLs to the application and never removes existing ones.

> [tab] Management API
>
> ```shellscript theme={null}
> curl --fail-with-body --request PATCH --url "https://$AUTH0_DOMAIN/api/v2/resource-servers/http%3A%2F%2Flocalhost%3A4000" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data '{ "proof_of_possession": { "mechanism": "dpop", "required": false } }' && \
> AGENT_APP_ID=$(curl --silent --fail-with-body --request POST --url "https://$AUTH0_DOMAIN/api/v2/clients/cimd/register" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data '{ "external_client_id": "https://poppyplayground.dev/agent.json" }' \
>   | node -pe 'JSON.parse(require("fs").readFileSync(0)).client_id') && \
> curl --fail-with-body --request PATCH --url "https://$AUTH0_DOMAIN/api/v2/clients/$AGENT_APP_ID" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data '{ "require_proof_of_possession": true }' && \
> curl --fail-with-body --request POST --url "https://$AUTH0_DOMAIN/api/v2/agents" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data "{ \"name\": \"Poppy Playground\", \"client_id\": \"$AGENT_APP_ID\" }" && \
> curl --fail-with-body --request POST --url "https://$AUTH0_DOMAIN/api/v2/client-grants" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data "{
>     \"client_id\": \"$AGENT_APP_ID\",
>     \"audience\": \"http://localhost:4000\",
>     \"subject_type\": \"user\",
>     \"scope\": [\"cart:write\", \"orders:read\", \"orders:write\", \"poppy:browser-sign-in\"]
>   }" && \
> curl --fail-with-body --request PATCH --url "https://$AUTH0_DOMAIN/api/v2/clients/$AUTH0_CLIENT_ID" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data "{
>     \"callbacks\": [\"http://localhost:3000/auth/callback\", \"$APP_BASE_URL/auth/callback\"],
>     \"allowed_logout_urls\": [\"http://localhost:3000\", \"$APP_BASE_URL\"],
>     \"web_origins\": [\"http://localhost:3000\", \"$APP_BASE_URL\"]
>   }" && \
> CONNECTION_ID=$(curl --silent --fail-with-body --url "https://$AUTH0_DOMAIN/api/v2/connections?name=Username-Password-Authentication&fields=id" \
>   --header "Authorization: Bearer $MGMT_TOKEN" | node -pe 'JSON.parse(require("fs").readFileSync(0))[0].id') && \
> curl --fail-with-body --request PATCH --url "https://$AUTH0_DOMAIN/api/v2/connections/$CONNECTION_ID" \
>   --header "Authorization: Bearer $MGMT_TOKEN" --header "Content-Type: application/json" \
>   --data '{ "is_domain_connection": true }'
> ```

**7. Serve discovery and accept agent browsers**

One SDK option serves `/.well-known/poppy.json` and `/.well-known/oauth-protected-resource`, and accepts the login that ends an agent's browser join.

**Next.js**

The SDK takes `apps/web/poppy.json`, which `auth0 poppy setup` wrote in step 5, as it is, and the starter's `proxy.ts` already lets `/.well-known/*` through. Pass the file to the client:

```ts apps/web/lib/auth0.ts highlight={2,6} theme={null}
import { Auth0Client } from "@auth0/nextjs-auth0/server";
import poppyConfig from "../poppy.json";

export const auth0 = new Auth0Client({
  // ...the starter's existing options
  poppy: { config: poppyConfig },
});
```

**Express**

With `poppy: true`, the SDK reads `poppy.json` from the folder the store runs in: `apps/web-express/poppy.json`, which `auth0 poppy setup` wrote in step 5. Add it to the SDK's options:

```js apps/web-express/src/app.js highlight={3} theme={null}
createAuth0({
  // ...the starter's existing options
  poppy: true,
})
```

**8. Show who is driving the browser**

After a join, the SDK tells a person from an agent, and an agent guest from a signed-in agent. A guest has no user, so route protection treats it as signed out.

**Next.js**

Create the banner, then import it in `apps/web/app/layout.tsx` with `import { AgentBanner } from "./components/AgentBanner";` and render `<AgentBanner />` at the top of `<body>`:

```tsx apps/web/app/components/AgentBanner.tsx theme={null}
import { auth0 } from "@/lib/auth0";

export async function AgentBanner() {
  const poppy = await auth0.poppy.getContext();
  if (poppy.kind !== "agent") return null;

  return (
    <p role="status" className="driving-banner">
      Shopping via {poppy.act.client_id ?? poppy.act.sub}: {poppy.state === "signed_in" ? "signed in" : "guest"}
    </p>
  );
}
```

**Express**

Replace the comment "Middleware that needs to know who is visiting goes here" in `apps/web-express/src/app.js`. The starter's layout already renders the banner when `res.locals.agent` is set:

```js apps/web-express/src/app.js theme={null}
app.use(async (req, res, next) => {
  const visitor = await req.auth0.client.poppy.getVisitor();
  const poppy = visitor.kind === 'guest' || visitor.kind === 'user' ? visitor.poppy : undefined;
  if (poppy) {
    res.locals.agent = {
      url: poppy.agent.id,
      signedIn: poppy.state === 'signed_in',
      // An agent guest calls the API with its own guest token.
      guestToken: visitor.kind === 'guest' ? (await req.auth0.client.poppy.getGuestAccessToken())?.accessToken : undefined,
    };
  }
  next();
});
```

**9. Verify agent requests at your API**

Agents send a signed `Poppy-Session` header, and an access token once the customer signs in. The SDK verifies both and returns the agent's Session. Key the cart by that Session, so a cart filled as a guest is still there after sign-in. Both websites use this API, so this step is the same for both stacks. For the Express API SDK, read [Add to Your API](https://auth0.com/docs/ai-agents-mcp/personal-agents/add-to-your-api.md).

Add the `poppy` options to the API client:

```ts apps/carts-api/src/auth0.ts highlight={6-10} theme={null}
import { ApiClient } from "@auth0/auth0-api-js";

export const apiClient = new ApiClient({
  domain: process.env.AUTH0_DOMAIN!,
  audience: process.env.AUTH0_AUDIENCE!,
  poppy: {
    verifySession: true,
    publicOrigin: process.env.PUBLIC_ORIGIN, // the https origin agents call
    agents: process.env.POPPY_AGENTS?.split(","), // the agents you accept
  },
});
```

Replace the starter's token check with `verifyPoppyRequest`:

```ts apps/carts-api/src/auth.ts theme={null}
import { toHttpErrorResponse } from "@auth0/auth0-api-js";
import type { RequestHandler } from "express";
import { apiClient } from "./auth0.js";

export const authenticate: RequestHandler = async (req, res, next) => {
  try {
    const { poppy, claims } = await apiClient.verifyPoppyRequest({
      method: req.method,
      url: `${process.env.PUBLIC_ORIGIN ?? process.env.CARTS_API_URL}${req.originalUrl}`,
      headers: req.headers,
    });
    if (!poppy && !claims) {
      // No Poppy-Session header and no access token.
      return res.status(401).set("WWW-Authenticate", 'Bearer realm="api"').json({ error: "unauthorized" });
    }
    res.locals.poppy = poppy;   // the agent's Session, when an agent calls
    res.locals.claims = claims; // the access token's claims, when there is one
    next();
  } catch (error) {
    const failure = toHttpErrorResponse(error);
    if (!failure) return next(error);
    res.status(failure.status).set(failure.headers);
    failure.body ? res.json(failure.body) : res.end();
  }
};
```

In `apps/carts-api/src/app.ts`, replace the `cartKey` helper near the top of the file, so it keys the cart by the Session:

```ts apps/carts-api/src/app.ts theme={null}
const cartKey = (res: Response) => (res.locals.poppy ? `poppy:${res.locals.poppy.key}` : `user:${res.locals.claims?.sub}`);
```

Then replace the `app.post("/orders", …)` route inside `createApp`, so a signed-out agent is asked to sign the customer in, and a signed-in agent needs `orders:write`:

```ts apps/carts-api/src/app.ts theme={null}
app.post("/orders", authenticate, async (req, res) => {
  const { poppy, claims } = res.locals;
  if (poppy && poppy.state !== "signed_in") {
    // A 401 that names the scope tells the agent what to ask the customer for.
    return res
      .status(401)
      .set("WWW-Authenticate", 'Bearer realm="api", scope="orders:write"')
      .json({ error: "unauthorized" });
  }
  // An agent needs orders:write. Its token carries what the customer approved for it, and so does the store's
  // token after a browser join: the Next.js starter asks for the API's scopes at login. A token with none of the
  // API's scopes (the Express starter can't ask for them) isn't checked.
  const scopes = String(claims?.scope ?? "").split(" ");
  const apiScopes = ["cart:write", "orders:read", "orders:write"];
  if (poppy && scopes.some((s) => apiScopes.includes(s)) && !scopes.includes("orders:write")) {
    return res
      .status(403)
      .set("WWW-Authenticate", 'Bearer realm="api", error="insufficient_scope", scope="orders:write"')
      .json({ error: "insufficient_scope" });
  }
  // placedVia records which agent placed the order.
  const order = await placeOrder(claims.sub, cartKey(res), { payment: req.body?.payment, placedVia: poppy?.agent.id });
  res.status(201).json(order);
});
```

The User ID in the `Poppy-Session` header is chosen by the agent. Act on the customer's account only with the `sub` of a verified access token.

**10. Shop with a personal agent**

In the first terminal, stop the store with `Ctrl+C` and start it again. Then check discovery, your tenant, and the agent end to end:

> [tab] Auth0 CLI
>
> ```shellscript theme={null}
> auth0 poppy doctor "$POPPY_DOMAIN"
> ```
>
> Every check should pass, apart from three warnings that are expected for this local sample: D5 and D16 about `poppy:browser-sign-in`, and D14 about the API's `localhost` identifier. Each failure prints a `FIX` line that tells you how to resolve it.

> [tab] Management API
>
> Each document must name the others exactly, including the issuer's trailing slash:
>
> ```shellscript theme={null}
> curl --silent "$APP_BASE_URL/.well-known/poppy.json" && \
> curl --silent "$APP_BASE_URL/.well-known/oauth-protected-resource" && \
> curl --silent "https://$AUTH0_DOMAIN/.well-known/oauth-authorization-server"
> ```

Open the [Poppy Playground](https://poppyplayground.dev/), enter your store's URL, `$APP_BASE_URL`, and ask the agent to buy a bag of beans. It adds them to the cart as a guest, and the store shows **Shopping via [https://poppyplayground.dev/agent.json](https://poppyplayground.dev/agent.json): guest**. At checkout, it asks you to sign in: log in on your Auth0 login page and approve the agent. The agent joins again as you, finds the guest cart still there, and places the order.

> [!TIP]
>
> **Checkpoint**
>
> Open `$APP_BASE_URL/orders` in your own browser. The order shows **Placed by agent**. A personal agent shopped your store as a guest, signed you in with your approval, and placed an order that names it.

***

## Troubleshooting

> [accordion] The agent ignores your store
>
> Run `auth0 poppy doctor "$POPPY_DOMAIN"`. Agents compare your discovery files with your tenant character for character, and skip your store without saying why. Most often the tunnel URL changed since you turned on Poppy, or the store wasn't restarted after `npm run tunnel`. Repeat steps 4 to 6.

> [accordion] invalid\_request: no connections enabled for the client
>
> The connection customers log in with isn't domain-level. Repeat step 6.

> [accordion] invalid\_request: Client configuration requires the use of Proof-of-Possession mechanism
>
> The agent requires DPoP-bound tokens and your API doesn't allow DPoP. Run the `proof_of_possession` command in step 6.

> [accordion] The agent is signed in, but the store still treats it as a guest
>
> Auth0's logs show `Prompts are not allowed for an impersonated session` for the storefront. The login that ends a browser join can't show any screen. Check that your API allows skipping consent for first-party applications, and that no post-login Action renders a form during the join.

> [accordion] The signed-in join fails
>
> The agent's grant must include `poppy:browser-sign-in`. Repeat step 6.

> [accordion] invalid\_session at your API
>
> The SDK compares the URL the agent signed with `PUBLIC_ORIGIN`. Check that `PUBLIC_ORIGIN` is the API's tunnel URL, and that the store restarted after `npm run tunnel`.

> [accordion] The Playground can't reach your store
>
> Check that the store and `npm run tunnel` are both still running, and that `$APP_BASE_URL` opens in your browser.

For more troubleshooting steps, read [Test Your Setup](https://auth0.com/docs/ai-agents-mcp/personal-agents/test-your-setup.md#troubleshoot).

## See the finished store

The `main` branch of the sample is the complete store. It marks each Poppy integration point `POPPY n/6` in the code, and adds a code tour, labs, a scripted agent for testing without a tenant, and deploy guides. Compare it with yours:

```shellscript theme={null}
git fetch origin main && git diff starter origin/main -- apps
```

> [card] [Drift Bean Demo reference app](https://github.com/auth0-samples/auth0-poppy-sample)
>
> The finished store and API, with a code tour, labs, and deploy guides.

> [card] [Live demo](https://driftbeandemo.com)
>
> The same store, deployed. Point the Poppy Playground at it.

## Add it to your own app

> [card] [Add to your web app](https://auth0.com/docs/ai-agents-mcp/personal-agents/add-to-your-web-app.md)
>
> Serve the discovery files, accept agent browsers, and tell a person from an agent, with the Next.js or Express SDK.

> [card] [Add to your API](https://auth0.com/docs/ai-agents-mcp/personal-agents/add-to-your-api.md)
>
> Verify agent requests, enforce scopes, and describe your API for agents, with the Node.js or Express API SDK.

## Learn more

* [How Personal Agent Protocol Works](https://auth0.com/docs/ai-agents-mcp/personal-agents/how-personal-agents-work.md)
* [What Your Apps and APIs Receive](https://auth0.com/docs/ai-agents-mcp/personal-agents/tokens-and-claims.md)
