Approve on another device
Start a sign-in or an approval from a backend, for a person who is not at this browser, and wait for the answer from their phone.
What it shows
- A customer calls the support desk of Acme. The desk knows the email address of the customer, but the customer is not at its browser.
- The server of the desk starts a backchannel request with
login_hintand the binding message "Support call 4821". It receives anauth_req_id. - The customer confirms on another device. The agent of the desk reads the binding message on the phone, so that the customer can compare it.
- The server polls the token endpoint, never faster than the interval. It receives the tokens of the customer, or
access_denied, orexpired_token.
Before you start
- Check that your plan includes backchannel authentication in the plans matrix.
- An API key for the setup script, with the scopes
admin:clients:readandadmin:clients:write. - A confidential application with CIBA switched on. The setup script creates the application "Acme Support desk" with
cibaEnabled. - A user who can confirm the request on a device, for example with the LumoAuth app.
| 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. |
CLIENT_ID | The client ID of the application. The setup script prints it. |
CLIENT_SECRET | The secret of the application. The setup script prints it once, when it creates the application. |
CUSTOMER_EMAIL | The email address of the user who must confirm. The default is maya.chen@example.com. |
The setup script creates what the recipe needs, through the Admin API. You can run it again at any time.
node oauth/ciba/setup.mjs
setup.mjs
// Creates what the recipe needs: the confidential application "Acme Support
// desk", with CIBA switched on. Run it again at any time. The client secret is
// shown once, when the application is created: add --new-secret to replace a
// secret that you lost.
//
// node oauth/ciba/setup.mjs
//
// The API key needs the scopes admin:clients:read and admin:clients:write.
import { call, list, printEnv } from '../../_lib/admin.mjs';
const name = 'Acme Support desk';
let client = (await list('/admin/clients')).find((c) => c.name === name);
let secret;
if (!client) {
const created = await call('POST', '/admin/clients', {
name,
// Only a confidential application may start a backchannel request.
isConfidential: true,
grantTypes: ['urn:openid:params:grant-type:ciba'],
scopes: ['openid', 'profile', 'email'],
cibaEnabled: true,
});
client = created.data;
secret = client.secret;
} else if (process.argv.includes('--new-secret')) {
secret = (await call('POST', `/admin/clients/${client.id}/rotate-secret`)).data.secret;
}
console.log(`The application "${name}" is ready.`);
printEnv({ CLIENT_ID: client.clientId, ...(secret ? { CLIENT_SECRET: secret } : {}) });
if (!secret) console.log('# CLIENT_SECRET was printed when the application was created. Add --new-secret to get a new one.');
Code
Run each command from the recipes folder of the examples repository. Set the folder up once for your language. This output is from a run in which the user did not answer. After a confirmation, the last line shows the token answer: token_type, expires_in, scope, and whether an ID token came with it.
- curl
#!/bin/sh
# A support desk asks a customer to confirm a call on another device, and
# polls the token endpoint until the customer has answered, with curl.
#
# sh oauth/ciba/http/ciba.sh
#
# The script needs curl and jq.
set -eu
OAUTH="$LUMOAUTH_URL/orgs/$LUMOAUTH_ORG_ID/api/v1/oauth"
# The customer on the phone line. The desk knows the address, not a session.
CUSTOMER_EMAIL="${CUSTOMER_EMAIL:-maya.chen@example.com}"
# 1. Start the request. Both sides read the same binding message: the agent
# of the desk says it on the phone, and the customer sees it on the device.
START=$(curl --silent --show-error "$OAUTH/bc-authorize" \
--user "$CLIENT_ID:$CLIENT_SECRET" \
--data-urlencode "scope=openid profile email" \
--data-urlencode "login_hint=$CUSTOMER_EMAIL" \
--data-urlencode "binding_message=Support call 4821")
printf '%s' "$START" | jq -c 'if .error then {error, error_description} else {auth_req_id: (.auth_req_id[0:8] + "…"), expires_in, interval} end'
AUTH_REQ_ID=$(printf '%s' "$START" | jq -r .auth_req_id)
INTERVAL=$(printf '%s' "$START" | jq -r '.interval // 5')
# 2. Poll the token endpoint, never faster than the interval.
while :; do
sleep "$INTERVAL"
ANSWER=$(curl --silent --show-error "$OAUTH/token" \
--user "$CLIENT_ID:$CLIENT_SECRET" \
--data "grant_type=urn:openid:params:grant-type:ciba" \
--data "auth_req_id=$AUTH_REQ_ID")
ERROR=$(printf '%s' "$ANSWER" | jq -r '.error // empty')
case "$ERROR" in
authorization_pending) echo "waiting for the customer" ;;
slow_down) INTERVAL=$((INTERVAL + 5)); echo "slow_down: polling every $INTERVAL s" ;;
"")
# 3. The customer approved: the desk now holds tokens for that person.
printf '%s' "$ANSWER" | jq -c '{token_type, expires_in, scope, id_token: (.id_token != null)}'
break ;;
*)
# access_denied (the customer refused) or expired_token (no answer in time).
printf '%s' "$ANSWER" | jq -c '{error, error_description}'
break ;;
esac
done
sh oauth/ciba/http/ciba.sh
Compiles. Not run against an organization. Ran against an organization up to the polling. Nobody could confirm the request: LumoAuth sent the user no prompt, so the polling ended with expired_token.
No SDK has a call for CIBA, so the recipe uses curl. The two requests are the same in any language.
Check the result
{"auth_req_id":"16919b18…","expires_in":120,"interval":5}
waiting for the customer
waiting for the customer
{"error":"expired_token","error_description":"The authentication request (auth_req_id) has expired"}
- The answer of
bc-authorizehas the same shape for an address that has no account. Polling such a request never returns tokens. - Each poll before the answer gets
authorization_pending. A client that polls too fast getsslow_down, and the script then waits five seconds longer. - A request expires after 120 seconds unless you send
requested_expiry. The polling then ends withexpired_token.
Limits
- LumoAuth delivers the result in poll mode only. It never calls your server back.
- The binding message holds at most 255 characters, without control characters.
- The confirmation step was not seen when this page was checked: the user received no prompt for the request of an application. The page stays a draft until it is.
- An agent can ask a person to approve one action with CIBA too, through the approvals of LumoAuth. See Ask a person who is not in the conversation.