Skip to main content

Ask the person on their phone

Before a risky action, the agent sends an approval request to the phone of the person it acts for, and waits for the answer.

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 / TypeScriptPythonGoPHPJavaC# / .NET

What it shows​

  1. The agent is about to send a wire transfer. It sends an approval request with a reason, an impact level and the person to ask.
  2. The phone of that person shows the request in the LumoAuth app: the name of the agent, the reason, the impact and the rows of detail.
  3. The agent waits for the answer, for 90 seconds at most.
  4. The agent sends the wire only when the answer is "approved". It stops on a denial, when nobody answers, and when the request could not be delivered.

The answer is a yes or a no. LumoAuth gives no token for the action, so your code decides what "approved" allows.

Before you start​

  • An agent with the switch May act on behalf of users turned on. The setup script registers the agent "Payments agent" with that switch.
  • A person with the LumoAuth app on a phone. The person opens My account, then Sign-in & security, clicks Add a sign-in method and chooses LumoAuth app. Put the email address of this person in APPROVER_EMAIL.
  • Check that your plan includes acting for users in the plans matrix.
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 scopes admin:agents:read and admin:agents:write. The agent itself needs no API key.
AGENT_CLIENT_IDThe client ID of the agent, which is its agent ID (agt_…). The setup script prints it.
AGENT_CLIENT_SECRETThe client secret of the agent. The setup script prints it.
APPROVER_EMAILThe email address of the person to ask. This person needs the LumoAuth app on a phone.

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

node approvals/push-approval/setup.mjs
setup.mjs
// Registers the agent of this recipe. It may act for users, which a request
// to the phone of a person needs. Run it again at any time.
//
// node approvals/push-approval/setup.mjs
//
// The API key needs the scopes admin:agents:read and admin:agents:write.
import { call, ensure, printEnv } from '../../_lib/admin.mjs';

const agent = await ensure('/admin/agents', (a) => a.name === 'Payments agent', {
name: 'Payments agent',
description: 'Prepares wire transfers, and asks the person before it sends one.',
identityType: 'client_secret',
capabilities: ['payments:prepare'],
// The switch "May act on behalf of users" of the portal.
canActOnBehalfOfUsers: true,
});

// LumoAuth shows a secret once, in the answer that creates it. On a second
// run the script therefore asks for a new secret, and the old one stops.
const secret =
agent.clientSecret ??
(await call('POST', `/admin/agents/${agent.agentId}/rotate-credentials`)).data.clientSecret;

console.log(`Agent "${agent.name}" is ready.`);
printEnv({ AGENT_CLIENT_ID: agent.agentId, AGENT_CLIENT_SECRET: secret });

LumoAuth shows a secret once. A second run of the setup script therefore asks for a new secret, and the old one stops at once.

Code​

Three of the SDKs return every answer as a status. The SDKs for Go, Java and .NET return only an approval, and report every other answer as an error. Each program turns both forms into the same lines.

Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every program was run against an organization with a person who has no phone with the LumoAuth app. Each one printed approval: not delivered (email_fallback_sent) and wire: not sent. The answers of a phone were not seen.

approvals/push-approval/js/agent.mjs
// Before a wire transfer, the agent asks a person on their phone and waits.
//
// node approvals/push-approval/js/agent.mjs
import { LumoAgent, LumoAuthApprovalNotDeliveredError } from '@lumoauth/agent';

// Reads LUMOAUTH_URL, LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
const agent = new LumoAgent();
const approver = process.env.APPROVER_EMAIL;

console.log(`asking ${approver} on the phone`);
let status;
try {
// The call waits until the person answers, for 90 seconds at most.
const approval = await agent.approvals.require({
taskId: 'wire-INV-7741',
reason: 'Wire 4,500 USD to Northwind Labs for INV-7741',
impact: 'high',
onBehalfOf: approver,
// The phone shows each entry as a row.
meta: { amount: '4,500 USD', vendor: 'Northwind Labs', invoice: 'INV-7741' },
});
// "pending" after the wait means that nobody answered in time.
status = approval.status;
} catch (error) {
if (!(error instanceof LumoAuthApprovalNotDeliveredError)) throw error;
// The person has no phone with the LumoAuth app. Nothing waits for an answer.
status = `not delivered (${error.reason})`;
}
console.log(`approval: ${status}`);

// Only "approved" lets the agent act. Every other answer stops it.
console.log(status === 'approved' ? 'wire: sent' : 'wire: not sent');
node approvals/push-approval/js/agent.mjs

Compiles. Not run against an organization. Ran against an organization up to the answer not delivered, because the test user has no phone with the LumoAuth app. An approval and a denial on a phone were not seen.

Check the result​

Output
asking maya.chen@example.com on the phone
approval: approved
wire: sent
  • Tap Deny on the phone: the program prints approval: denied and wire: not sent.
  • Do not answer: after 90 seconds the program prints approval: pending, or approval: expired when the request has ended on the server.
  • Name a person who has no phone with the app: the program prints approval: not delivered (email_fallback_sent). LumoAuth sends that person an email which says that an agent asked, and nothing waits for an answer. An address that no user has gets the same answer.
  • Turn off May act on behalf of users on the agent: the request is refused with 403 and the error delegation_not_permitted.

Limits​

  • An agent may send 10 requests in 5 minutes for one person.
  • A request waits for 120 seconds on the server. The SDKs wait for 90 seconds unless you set another timeout.
  • The detail (meta) holds at most 20 entries, and a text value is cut to 200 characters.
  • The approval gives no access token. When the API that runs the action needs proof of the approval, use a just-in-time permission or the backchannel flow: both end with a token.
  • A token that the agent narrowed with a scope cannot create a request. Use a token with all capabilities of the agent.