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.
What it shows
- 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.
- 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.
- The agent waits for the answer, for 90 seconds at most.
- 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.
| 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 scopes admin:agents:read and admin:agents:write. The agent itself needs no API key. |
AGENT_CLIENT_ID | The client ID of the agent, which is its agent ID (agt_…). The setup script prints it. |
AGENT_CLIENT_SECRET | The client secret of the agent. The setup script prints it. |
APPROVER_EMAIL | The 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.
- Node.js
- Python
- Go
- PHP
- Java
- C#
// 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.
"""Before a wire transfer, the agent asks a person on their phone and waits.
python approvals/push-approval/python/agent.py
"""
import os
from lumoauth import LumoAuthAgent, require_approval
from lumoauth.errors import LumoAuthApprovalNotDeliveredError
# Reads LUMOAUTH_URL, LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
agent = LumoAuthAgent()
if not agent.authenticate():
raise SystemExit("The agent could not authenticate. Check its ID and its secret.")
approver = os.environ["APPROVER_EMAIL"]
print(f"asking {approver} on the phone")
try:
# The call waits until the person answers, for 90 seconds at most.
approval = require_approval(
agent,
task_id="wire-INV-7741",
reason="Wire 4,500 USD to Northwind Labs for INV-7741",
impact="high",
on_behalf_of=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
except LumoAuthApprovalNotDeliveredError as error:
# The person has no phone with the LumoAuth app. Nothing waits for an answer.
status = f"not delivered ({error.reason})"
print(f"approval: {status}")
# Only "approved" lets the agent act. Every other answer stops it.
print("wire: sent" if status == "approved" else "wire: not sent")
python approvals/push-approval/python/agent.py
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.
// Before a wire transfer, the agent asks a person on their phone and waits.
//
// go run ./approvals/push-approval/go
package main
import (
"context"
"errors"
"fmt"
"log"
"os"
lumoauth "github.com/lumoauth/lumo-auth-go"
)
func main() {
ctx := context.Background()
// Reads LUMOAUTH_URL, LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
agent, err := lumoauth.NewAgent(lumoauth.AgentConfig{})
if err != nil {
log.Fatal(err)
}
approver := os.Getenv("APPROVER_EMAIL")
fmt.Printf("asking %s on the phone\n", approver)
// The call waits until the person answers, for 90 seconds at most.
approval, err := agent.Approvals.Require(ctx, lumoauth.ApprovalParams{
TaskID: "wire-INV-7741",
Reason: "Wire 4,500 USD to Northwind Labs for INV-7741",
Impact: lumoauth.ImpactHigh,
OnBehalfOf: approver,
// The phone shows each entry as a row.
Meta: map[string]any{"amount": "4,500 USD", "vendor": "Northwind Labs", "invoice": "INV-7741"},
}, nil)
// Require returns an error for every answer that is not an approval.
var refused *lumoauth.ApprovalError
status := "approved"
switch {
case errors.Is(err, lumoauth.ErrApprovalNotDelivered) && errors.As(err, &refused):
// The person has no phone with the LumoAuth app. Nothing waits for an answer.
status = fmt.Sprintf("not delivered (%s)", refused.Reason)
case errors.Is(err, lumoauth.ErrApprovalDenied), errors.Is(err, lumoauth.ErrApprovalTimeout):
// "pending" after the wait means that nobody answered in time.
status = approval.Status
case err != nil:
log.Fatal(err)
}
fmt.Printf("approval: %s\n", status)
// Only "approved" lets the agent act. Every other answer stops it.
if status == "approved" {
fmt.Println("wire: sent")
} else {
fmt.Println("wire: not sent")
}
}
go run ./approvals/push-approval/go
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.
<?php
// Before a wire transfer, the agent asks a person on their phone and waits.
//
// php approvals/push-approval/php/agent.php
require __DIR__ . '/../../../php/vendor/autoload.php';
use LumoAuth\Error\LumoAuthApprovalNotDeliveredError;
use LumoAuth\LumoAuth;
// Reads LUMOAUTH_URL and LUMOAUTH_ORG_ID. The agent signs in with its ID and its secret.
$tokens = (new LumoAuth())->auth->clientCredentials(getenv('AGENT_CLIENT_ID'), getenv('AGENT_CLIENT_SECRET'));
$agent = new LumoAuth(tokenProvider: fn () => $tokens['access_token']);
$approver = getenv('APPROVER_EMAIL');
printf("asking %s on the phone\n", $approver);
try {
// The call waits until the person answers, for 90 seconds at most.
$approval = $agent->approvals->require(
taskId: 'wire-INV-7741',
reason: 'Wire 4,500 USD to Northwind Labs for INV-7741',
onBehalfOf: $approver,
impact: 'high',
// 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 (LumoAuthApprovalNotDeliveredError $error) {
// The person has no phone with the LumoAuth app. Nothing waits for an answer.
$status = sprintf('not delivered (%s)', $error->reason);
}
printf("approval: %s\n", $status);
// Only "approved" lets the agent act. Every other answer stops it.
echo $status === 'approved' ? "wire: sent\n" : "wire: not sent\n";
php approvals/push-approval/php/agent.php
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.
// Before a wire transfer, the agent asks a person on their phone and waits.
//
// java -cp "java/lib/*" approvals/push-approval/java/Agent.java
import io.lumoauth.LumoAgent;
import io.lumoauth.errors.LumoAuthApprovalDeniedException;
import io.lumoauth.errors.LumoAuthApprovalNotDeliveredException;
import io.lumoauth.errors.LumoAuthApprovalTimeoutException;
import io.lumoauth.model.ApprovalImpact;
import io.lumoauth.model.ApprovalRequest;
import java.util.Map;
public class Agent {
public static void main(String[] args) {
// Reads LUMOAUTH_URL, LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
LumoAgent agent = LumoAgent.fromEnvironment();
String approver = System.getenv("APPROVER_EMAIL");
System.out.printf("asking %s on the phone%n", approver);
String status;
try {
// The call waits until the person answers, for 90 seconds at most.
// It throws for every answer that is not an approval.
agent.approvals().require(
ApprovalRequest.builder("wire-INV-7741", "Wire 4,500 USD to Northwind Labs for INV-7741", approver)
.impact(ApprovalImpact.HIGH)
// The phone shows each entry as a row.
.meta(Map.of("amount", "4,500 USD", "vendor", "Northwind Labs", "invoice", "INV-7741"))
.build());
status = "approved";
} catch (LumoAuthApprovalDeniedException e) {
status = e.approval().status();
} catch (LumoAuthApprovalTimeoutException e) {
// "pending" after the wait means that nobody answered in time.
status = e.approval().status();
} catch (LumoAuthApprovalNotDeliveredException e) {
// The person has no phone with the LumoAuth app. Nothing waits for an answer.
status = "not delivered (" + e.reason() + ")";
}
System.out.printf("approval: %s%n", status);
// Only "approved" lets the agent act. Every other answer stops it.
System.out.println(status.equals("approved") ? "wire: sent" : "wire: not sent");
}
}
java -cp "java/lib/*" approvals/push-approval/java/Agent.java
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.
#:package LumoAuth@1.7.0
#:property PublishAot=false
// Before a wire transfer, the agent asks a person on their phone and waits.
//
// dotnet run approvals/push-approval/csharp/Agent.cs
using LumoAuth;
using LumoAuth.Errors;
using LumoAuth.Models;
// Reads LUMOAUTH_URL, LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
using var agent = LumoAgent.FromEnvironment();
var approver = Environment.GetEnvironmentVariable("APPROVER_EMAIL")!;
Console.WriteLine($"asking {approver} on the phone");
string status;
try
{
// The call waits until the person answers, for 90 seconds at most.
// It throws for every answer that is not an approval.
await agent.Approvals.RequireAsync(new ApprovalRequest
{
TaskId = "wire-INV-7741",
Reason = "Wire 4,500 USD to Northwind Labs for INV-7741",
Impact = ApprovalImpact.High,
OnBehalfOf = approver,
// The phone shows each entry as a row.
Meta = new { amount = "4,500 USD", vendor = "Northwind Labs", invoice = "INV-7741" },
});
status = "approved";
}
catch (LumoAuthApprovalDeniedException e)
{
status = e.Approval.Status!;
}
catch (LumoAuthApprovalTimeoutException e)
{
// "pending" after the wait means that nobody answered in time.
status = e.Approval.Status!;
}
catch (LumoAuthApprovalNotDeliveredException e)
{
// The person has no phone with the LumoAuth app. Nothing waits for an answer.
status = $"not delivered ({e.Reason})";
}
Console.WriteLine($"approval: {status}");
// Only "approved" lets the agent act. Every other answer stops it.
Console.WriteLine(status == "approved" ? "wire: sent" : "wire: not sent");
dotnet run approvals/push-approval/csharp/Agent.cs
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
asking maya.chen@example.com on the phone
approval: approved
wire: sent
- Tap Deny on the phone: the program prints
approval: deniedandwire: not sent. - Do not answer: after 90 seconds the program prints
approval: pending, orapproval: expiredwhen 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
403and the errordelegation_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
scopecannot create a request. Use a token with all capabilities of the agent.