Skip to main content

Accept your customers' personal agents

Become a Company in the Personal Agent Protocol: publish the discovery documents, and let a customer's own agent sign in.

RecipeDraftView source
This page is a draft. The code exists, and not all of it has been run for this page yet. The page says what was checked.
Works with
JavaScript / TypeScriptPlain HTTP

What it shows​

  1. The setup script switches the Personal Agent Protocol on for your domain, with two scopes, your website as interface, and the hosted tasks and feedback endpoints.
  2. LumoAuth builds the two discovery documents: poppy.json and the protected resource metadata of your domain. company.mjs serves both on your own domain.
  3. The discovery program reads your domain as a personal agent does. It finds your issuer, checks the link from both sides, and finds the address where the user signs in.
  4. A personal agent then signs its user in, directly or with a code on another device, and reads your tasks endpoint. LumoAuth handles both for you.

In the protocol's words, your organization is a Company, and LumoAuth is its issuer. A personal agent has no registration with you: its client_id is the address of a metadata document that it publishes.

Before you start​

  • A domain that you control, for example shop.example.com, with a web server or CDN where you can serve two files under /.well-known/.
  • An API key with the scope admin:settings:write, for the setup script. The same settings are on the portal page Personal agents, under AI Agents.
  • company.mjs runs behind https://<your domain>. A proxy rule of your web server does the same job: the docs show rules for nginx, Next.js, Vercel and Cloudflare in Serve the two documents. A redirect to LumoAuth does not work.
VariableValue
LUMOAUTH_URLThe address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region.
LUMOAUTH_ORG_IDYour organization, for example acme-corp.
LUMOAUTH_API_KEYFor the setup script only: an API key with the scope admin:settings:write.
COMPANY_DOMAINYour Company domain, for example shop.example.com. The setup script and company.mjs read it.
COMPANY_URLThe address of your website, for example https://shop.example.com. The discovery programs read it.

The setup script creates what the recipe needs, through the Admin API. You can run it again at any time.

node personal-agents/accept-personal-agents/setup.mjs
setup.mjs
// Switches the Personal Agent Protocol on for one Company domain, with two
// scopes, the website as interface, and the hosted tasks and feedback
// endpoints. Run it again at any time: it writes the same settings.
//
// node personal-agents/accept-personal-agents/setup.mjs
//
// The API key needs the scope admin:settings:write. COMPANY_DOMAIN is your
// domain, for example shop.example.com.
import { call, printEnv } from '../../_lib/admin.mjs';

const domain = process.env.COMPANY_DOMAIN ?? 'shop.example.com';

await call('PUT', '/admin/personal-agent-protocol', {
enabled: true,
organization: { name: 'Northwind Outdoor' },
domains: [domain],
// A personal agent reads each description to choose the scopes of a task.
scopes: {
'orders:read': {
description: 'See your orders and returns. Needed to track an order or to find one to return.',
changes: 'none',
personal_data: true,
},
'orders:write': {
description: 'Return or exchange items. Needed for any change to an order.',
changes: 'irreversible',
personal_data: true,
},
},
web: { listed: true },
tasks: {
mode: 'hosted',
excluded_tasks: [
{ task: 'Close an account' },
{
task: 'Pay with a gift card',
alternative: {
instructions: 'Gift cards are redeemed at the checkout of the website.',
references: [{ type: 'web', url: `https://${domain}/checkout` }],
},
},
],
feedback: 'hosted',
},
});

const { data } = await call('GET', '/admin/personal-agent-protocol');
console.log(`Personal Agent Protocol: ${data.active ? 'on' : 'off'} for ${data.settings.domains.join(', ')}`);
for (const document of data.documents) {
console.log(` serve ${document.serve_at.poppy_json}`);
console.log(` from ${document.hosted.poppy_json}`);
}
printEnv({ COMPANY_DOMAIN: domain });

Code​

Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization. The programs ran against an organization, with company.mjs on a local address in place of a public domain. The domain check of the portal and a sign-in by a real personal agent need a public HTTPS domain, so they were not run.

personal-agents/accept-personal-agents/js/company.mjs
// Serves the two discovery documents of the Personal Agent Protocol on your
// own domain. LumoAuth builds them; this server fetches and passes them on.
//
// node personal-agents/accept-personal-agents/js/company.mjs
//
// Put it behind https://<COMPANY_DOMAIN>. In production a proxy rule of your
// web server or CDN does the same job.
import { createServer } from 'node:http';

const baseUrl = process.env.LUMOAUTH_URL ?? 'https://app.lumoauth.dev';
const orgId = process.env.LUMOAUTH_ORG_ID;
const domain = process.env.COMPANY_DOMAIN ?? 'shop.example.com';
const port = Number(process.env.PORT ?? 3000);

const documents = `${baseUrl}/orgs/${orgId}/api/v1/poppy/documents/${domain}`;
const paths = {
'/.well-known/poppy.json': `${documents}/poppy.json`,
'/.well-known/oauth-protected-resource': `${documents}/oauth-protected-resource`,
};

createServer(async (req, res) => {
const source = paths[new URL(req.url, 'http://localhost').pathname];
if (!source) {
res.writeHead(404).end();
return;
}
// Pass the document on. A redirect would not work: a poppy.json describes
// the host that serves it, so the agent must read it from your domain.
const answer = await fetch(source);
res.writeHead(answer.status, { 'Content-Type': 'application/json', 'Cache-Control': 'max-age=300' });
res.end(await answer.text());
}).listen(port, () => console.log(`Serving the documents of ${domain} on port ${port}`));
personal-agents/accept-personal-agents/js/discover.mjs
// Discovers a Company as a personal agent does: from its domain alone, to
// the address where the agent signs its user in.
//
// node personal-agents/accept-personal-agents/js/discover.mjs
//
// COMPANY_URL is the address of your website, for example
// https://shop.example.com.
const company = (process.env.COMPANY_URL ?? 'https://shop.example.com').replace(/\/+$/, '');

const getJson = async (url) => {
const answer = await fetch(url, { redirect: 'manual' });
if (answer.status !== 200) throw new Error(`${url} answered ${answer.status}`);
return answer.json();
};

// 1. The Company document names the company, its issuer and its scopes.
const poppy = await getJson(`${company}/.well-known/poppy.json`);
console.log(`company: ${poppy.organization.name} (${poppy.organization.domain})`);
console.log(`issuer: ${poppy.auth.issuer}`);
console.log(`scopes: ${Object.keys(poppy.auth.scopes).join(', ')}`);

// 2. The protected resource metadata of the domain names the same issuer.
const resource = await getJson(`${company}/.well-known/oauth-protected-resource`);
console.log(`resource metadata names the issuer: ${resource.authorization_servers.includes(poppy.auth.issuer)}`);

// 3. The issuer's own metadata lists the domain: the link holds from both
// sides, so another site cannot claim this issuer.
const issuer = new URL(poppy.auth.issuer);
const metadata = await getJson(`${issuer.origin}/.well-known/oauth-authorization-server${issuer.pathname}`);
console.log(`issuer lists the domain: ${(metadata.protected_resources ?? []).includes(`https://${poppy.organization.domain}`)}`);
console.log(`sign-in starts at: ${metadata.authorization_endpoint}`);

// 4. The tasks endpoint says which tasks the company does not offer. It
// answers only a request with a Poppy-Session header.
console.log(`tasks: ${poppy.tasks?.endpoint ?? 'none'}`);
node personal-agents/accept-personal-agents/js/discover.mjs

Start company.mjs behind your domain first.

Check the result​

Output
company: Northwind Outdoor (shop.example.com)
issuer: https://app.lumoauth.dev/orgs/acme-corp/api/v1
scopes: orders:read, orders:write
resource metadata names the issuer: true
issuer lists the domain: true
sign-in starts at: https://app.lumoauth.dev/orgs/acme-corp/api/v1/oauth/authorize
tasks: https://app.lumoauth.dev/orgs/acme-corp/api/v1/poppy/tasks
  • In the portal, open Personal agents, then Company and domains, and click Check next to the domain. LumoAuth fetches both documents from your domain, as a personal agent does, and checks the link to your issuer. Each check shows as passed.
  • GET on the tasks endpoint without a Poppy-Session header answers 400 invalid_session. A personal agent signs that header for each request.
  • After a personal agent sent feedback, the reports are under Feedback on the same page.

Limits​

  • A personal agent must publish its metadata document and keys on a public HTTPS address. LumoAuth fetches them without redirects. An agent on localhost cannot sign in.
  • Device Sign-In is off until you switch it on under Sign-in. It is easier to use for phishing than Direct Sign-In.
  • Mediated Sign-In, a hosted conversation endpoint and a hosted browser-session endpoint are not available.
  • Choose the issuer before personal agents start to use your organization. After a change, every agent sees a new company, and users sign in again.
  • Your own API checks each request of an agent through LumoAuth: see Verify a personal agent's session in your API.