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.
What it shows
- 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.
- LumoAuth builds the two discovery documents:
poppy.jsonand the protected resource metadata of your domain.company.mjsserves both on your own domain. - 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.
- 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.mjsruns behindhttps://<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.
| Variable | Value |
|---|---|
LUMOAUTH_URL | The address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region. |
LUMOAUTH_ORG_ID | Your organization, for example acme-corp. |
LUMOAUTH_API_KEY | For the setup script only: an API key with the scope admin:settings:write. |
COMPANY_DOMAIN | Your Company domain, for example shop.example.com. The setup script and company.mjs read it. |
COMPANY_URL | The 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.
- Node.js
- curl
// 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}`));
// 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.
#!/bin/sh
# Discovers a Company as a personal agent does: from its domain alone, to
# the address where the agent signs its user in.
#
# sh personal-agents/accept-personal-agents/http/discover.sh
#
# The script needs curl and jq. COMPANY_URL is the address of your website,
# for example https://shop.example.com.
set -eu
COMPANY="${COMPANY_URL:-https://shop.example.com}"
# 1. The Company document names the company, its issuer and its scopes.
POPPY=$(curl -sSf "$COMPANY/.well-known/poppy.json")
ISSUER=$(printf '%s\n' "$POPPY" | jq -r .auth.issuer)
DOMAIN=$(printf '%s\n' "$POPPY" | jq -r .organization.domain)
printf '%s\n' "$POPPY" | jq -r '"company: \(.organization.name) (\(.organization.domain))", "issuer: \(.auth.issuer)", "scopes: \(.auth.scopes | keys | join(", "))"'
# 2. The protected resource metadata of the domain names the same issuer.
curl -sSf "$COMPANY/.well-known/oauth-protected-resource" |
jq -r --arg issuer "$ISSUER" '"resource metadata names the issuer: \(.authorization_servers | index($issuer) != null)"'
# 3. The issuer's own metadata lists the domain: the link holds from both
# sides, so another site cannot claim this issuer.
ORIGIN=$(printf '%s\n' "$ISSUER" | sed -E 's#^(https?://[^/]+).*#\1#')
ISSUER_PATH=${ISSUER#"$ORIGIN"}
curl -sSf "$ORIGIN/.well-known/oauth-authorization-server$ISSUER_PATH" |
jq -r --arg resource "https://$DOMAIN" '"issuer lists the domain: \((.protected_resources // []) | index($resource) != null)", "sign-in starts at: \(.authorization_endpoint)"'
# 4. The tasks endpoint says which tasks the company does not offer. It
# answers only a request with a Poppy-Session header.
printf '%s\n' "$POPPY" | jq -r '"tasks: \(.tasks.endpoint // "none")"'
sh personal-agents/accept-personal-agents/http/discover.sh
Check the result
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.
GETon the tasks endpoint without aPoppy-Sessionheader answers400 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
localhostcannot 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.