Skip to main content

Sample Company and test personal agent

The LumoAuth server repository holds a runnable sample for Personal Agent Protocol in examples/poppy/. It has two scripts and no dependencies beyond Node 20.

FileWhat it is
company.mjsA sample Company, "Example Shop": discovery documents, an API, and a website with a browser-session endpoint.
personal-agent.mjsA test personal agent for the command line.
lib/jose.mjsThe JWTs that a personal agent signs: client assertions, delegations, Session JWTs and DPoP proofs.

This sample is for agents of your users. For OpenClaw and Hermes agents on your own machine, see Secure OpenClaw and Hermes agents.

What you need​

  • A LumoAuth organization with the protocol switched on, a Company domain such as shop.example.com, and the scopes orders:read and orders:write.
  • A confidential application whose allowed scopes include poppy:verify.
  • A public HTTPS address for two small files of the test agent. LumoAuth fetches an agent's metadata document from its client_id address. Loopback and private addresses are rejected, so localhost does not work for these two files. Any static host works.

The sample Company​

company.mjs keeps only the Company's own parts: its catalog, its orders, its scope rules and its website cookie. One function sends every request of a personal agent to LumoAuth:

async function verifyPoppyRequest(req, requiredScope = '') {
const headers = {};
for (const name of FORWARDED_HEADERS) {
if (typeof req.headers[name] === 'string') headers[name] = req.headers[name];
}
const path = new URL(req.url, PUBLIC_ORIGIN).pathname;

const answer = await fetch(`${LUMO_API_BASE}/poppy/sessions/verify`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: BASIC },
body: JSON.stringify({
method: req.method,
url: `${PUBLIC_ORIGIN}${path}`,
headers,
...(requiredScope ? { required_scope: requiredScope } : {}),
}),
redirect: 'error',
});
if (answer.status !== 200) {
throw new Error(`LumoAuth verification endpoint answered ${answer.status}`);
}
return answer.json();
}

A route then reads as two lines of protocol and the Company's own code:

if (route === 'GET /api/orders') {
const who = await verifyPoppyRequest(req, 'orders:read');
if (!who.active) return relayRefusal(res, who);
return sendJson(res, 200, { orders: ordersOf(who.account.sub) });
}

Start it:

cd examples/poppy
export LUMO_ISSUER="https://app.lumoauth.dev/orgs/acme-corp/api/v1"
export LUMO_CLIENT_ID="shop-api"
export LUMO_CLIENT_SECRET="..."
export COMPANY_DOMAIN="shop.example.com"
node company.mjs
VariableMeaning
LUMO_ISSUERYour Company identifier.
LUMO_API_BASEBase address of your organization's API. Leave it out on the platform host. On a custom domain it is the domain plus /api/v1.
LUMO_CLIENT_ID, LUMO_CLIENT_SECRETThe application that has poppy:verify.
COMPANY_DOMAINThe Company domain as you entered it in LumoAuth.
PUBLIC_ORIGINThe address that personal agents call. The default is http://localhost:8787.
PORTThe port, 8787 by default.
RouteWhat it shows
GET /.well-known/poppy.json, GET /.well-known/oauth-protected-resourceThe two documents, served on the Company's own address from LumoAuth's copies.
GET /api/catalog, POST /api/cartA signed-out API with state for each Session.
GET /api/ordersAn operation that needs orders:read.
POST /api/orders/{id}/returnAn operation that needs orders:write.
GET /poppy/browser-session, POST /poppy/browser-session/authorize, POST /poppy/browser-sessionThe three steps of a browser join.
GET /ordersA page of the website that reads the Session's cookie.

The test personal agent​

Create an identity once:

node personal-agent.mjs self-test
node personal-agent.mjs keygen --client-id https://static.example.net/poppy-test/agent.json

keygen writes three files to .poppy-agent/. Host agent.json and jwks.json at the address that you gave, unchanged. Keep private-keys.json on your machine.

{
"client_id": "https://static.example.net/poppy-test/agent.json",
"client_name": "Test Personal Agent",
"jwks_uri": "https://static.example.net/poppy-test/jwks.json",
"redirect_uris": ["http://127.0.0.1:8976/callback"],
"token_endpoint_auth_method": "private_key_jwt"
}
A test identity

The key of this agent is a file on a developer's machine. Never add its client_id to a production allow-list.

1. Discover the Company​

node personal-agent.mjs discover shop.example.com

The command does what the specification asks of a personal agent in section 3:

  1. It fetches https://shop.example.com/.well-known/poppy.json and checks that organization.domain is the host that served it.
  2. It fetches the domain's protected resource metadata and reads the issuer from authorization_servers.
  3. It fetches the issuer's metadata. It checks that issuer matches exactly, and that protected_resources lists https://shop.example.com.
Company Example Shop (shop.example.com)
Identifier https://app.lumoauth.dev/orgs/acme-corp/api/v1
Sign-in Direct Sign-In
scope orders:read: See your orders and returns. ... [changes: none, personal data: true]
scope orders:write: Exchange or return items. ... [changes: irreversible, personal data: true]
API openapi https://shop.example.com/openapi.json: Orders, returns and exchanges

While your Company still runs on your own machine, add --insecure-local http://localhost:8787. The command then reads the documents from that address and skips the host check. Use the flag for testing only.

2. A signed-out Session​

node personal-agent.mjs call POST https://shop.example.com/api/cart --data '{"sku":"trail-socks-3"}'
node personal-agent.mjs call GET https://shop.example.com/api/catalog
HTTP 200 (signed out)
{ "products": [ ... ], "cart": ["trail-socks-3"], "signed_in": false }

Each call carries a new Session JWT with the same sid. The sample Company stores the cart under the session.id of the verification result. The second call therefore returns the first call's item. Run node personal-agent.mjs new-session and the cart is empty again.

The agent sends a Session JWT only to addresses that the Company's poppy.json lists. For any other address the command stops.

3. An operation that needs the account​

node personal-agent.mjs call GET https://shop.example.com/api/orders
HTTP 401 (signed out)
This needs the user's account. Sign in for: orders:read

LumoAuth built that 401 with its WWW-Authenticate challenge. The sample Company only relayed it.

4. Sign in​

node personal-agent.mjs sign-in --scope "orders:read orders:write"

The command prints a link to your organization's authorization endpoint. Open it in a browser on the same computer and sign in as a user of your organization. The consent page names the agent and the host of its client_id, and it lists both scopes with your descriptions. Leave one out to see a partial grant.

Signed in. Granted scopes: orders:read

The command uses a loopback redirect, PKCE with S256 and a client assertion whose aud is your issuer. It checks state and iss on the redirect. With --device it uses Device Sign-In instead, when your organization offers it.

node personal-agent.mjs call GET https://shop.example.com/api/orders
# HTTP 200 (signed in)
node personal-agent.mjs call POST https://shop.example.com/api/orders/ord_1042/return
# HTTP 403 (signed in)
# The access token lacks a scope. Sign in again for every scope that you need, including: orders:write

5. Refresh and sign out​

node personal-agent.mjs refresh --scope orders:read
node personal-agent.mjs refresh --resource https://mcp.shop.example.com/mcp
node personal-agent.mjs sign-out

refresh --scope asks for an access token with fewer scopes. The refresh token keeps the scopes of the sign-in. refresh --resource asks for a token for one service; a value that your settings do not offer gets invalid_target. sign-out revokes the refresh token, and the Session continues signed out.

6. Tasks and feedback​

node personal-agent.mjs tasks
node personal-agent.mjs feedback --task "Pay with a gift card" \
--description "The user wanted to pay with a gift card. Neither the API nor the checkout page takes one."

Both commands need the hosted tasks and feedback endpoints. The report then appears under AI Agents → Personal agents → Feedback.

Browser join​

A browser join lets the agent's browser use your website in the same Session as its API calls. LumoAuth does not host this endpoint, because the endpoint sets your website's own cookie. The sample Company builds it in about 70 lines.

  1. The browser opens the page. GET /poppy/browser-session returns a form with a one-time code. The same response sets the cookie __Host-poppy_join (Secure, HttpOnly, SameSite=Strict, 60 seconds). The page is sent with Cache-Control: no-store, Content-Security-Policy: frame-ancestors 'none' and Cross-Origin-Opener-Policy: same-origin.

  2. The agent authorizes the code. POST /poppy/browser-session/authorize carries the Session header and, to sign the browser in, the access token. The sample verifies it like any API request:

    const who = await verifyPoppyRequest(req, req.headers.authorization ? 'poppy:browser-sign-in' : '');
    if (!who.active) return relayRefusal(res, who);

    A valid code gets 204. An unknown, expired or used code gets 400 with {"error": "invalid_request"}.

  3. The browser submits the form. The sample checks that the join cookie belongs to the code and that the code was authorized. It then sets the Session's cookie and answers 303. A code is used by its first submission, whatever the result.

Try it with the test agent, which has a small "browser" that keeps cookies:

node personal-agent.mjs browse
The browser joined the Session, signed in.
GET /orders -> HTTP 200
Example Shop Your orders Signed in through Test Personal Agent. ...

A signed-in join needs the scope poppy:browser-sign-in. LumoAuth offers that scope when your settings list a browser-session endpoint. Without that scope, the agent's browser joins signed out.

When the sign-in of a joined browser ends

The sample website asks LumoAuth for the state of the Session on every page request. The browser is signed out when the personal agent signs out, and when the user removes the agent under Authorized apps. The cookie is dropped when the Session ends.

What the sample leaves out​

  • A conversation endpoint. Build it like the API: verify every request, and own each conversation by client_id and user_id.
  • DPoP. The test agent uses Bearer tokens. lib/jose.mjs has a dpopProof() function for your own tests.
  • Durable state. Carts, orders and browser sessions are kept in memory.