🥋 Dojo Jutsu Docs docs.dojojutsu.com
← dojojutsu.com Launch Portal →

# Secure Phone Approval API

The phone approval service registers an account passkey and verifies signatures before approving a short-lived computer unlock request. It does not replace the authenticator verification required for protected cloud actions.

The endpoint is https://PROJECT.supabase.co/functions/v1/phone-security. The browser page lives at the configured HTTPS portal origin, at /phone-approve.html. This origin must match PHONE_APPROVAL_ORIGIN exactly. Ordinary LAN HTTP links are unsupported.

# Authentication and operations

All POST requests are JSON. Send a Supabase access token as Authorization: Bearer TOKEN for account operations. The function verifies the token with the authentication server. Registration and revocation additionally require a genuine second-factor verification within five minutes. Clients cannot create, modify, or approve records directly through database REST calls.

OperationAuthenticationRequest fields beyond operationResponse
availabilitySigned-in accountNoneavailable, approval_origin, approval_path
createSigned-in accountaction_title, requesting_device_labelid, nonce, expires_at, action/device labels
statusRequest ownerchallenge_idid, user_id, status, expires_at, verified method
cancelRequest ownerchallenge_idok
devicesSigned-in accountNonedevices: ID, label, creation and last-use timestamps
revokeFresh second-factor verificationdevice_idok
registration-optionsFresh second-factor verificationNoneWebAuthn options, ceremony_id
registration-verifySame verified accountceremony_id, standard WebAuthn registration response, labelok
authentication-optionsQR bearer; approval still requires enrolled passkeychallenge_id, nonceWebAuthn options, ceremony_id, action/device labels
authentication-verifyValid assertion from the request owner's registered passkeychallenge_id, nonce, ceremony_id, standard WebAuthn assertion responseok
authentication-cancelQR bearerchallenge_id, nonceok; a pending request becomes denied

GET ?operation=config returns only the public project URL/key and approved portal origin so the hosted pairing page can sign in. Never put service-role keys in the browser or app.

Requests expire after two minutes. Each ceremony is single-use. Authentication verifies origin, relying-party ID, challenge, credential ownership, signature, and required user verification. The database atomically checks expiry, pending state, revocation, and credential counter before consuming approval. Requests and ceremonies have account-scoped rate limits. An account may register up to ten active credentials.

Passkeys may be synchronized by the user's passkey provider; the registry identifies credentials rather than promising a credential can exist on only one physical handset. The user approves through the OS passkey prompt, which may use biometrics or the device passcode.

# Examples

Create an unlock request:

BASH
curl 'https://PROJECT.supabase.co/functions/v1/phone-security' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"operation":"create","action_title":"Unlock computer","requesting_device_label":"Front desk"}'

Build the QR URL from the configured approval page and the returned id/nonce. Hold the nonce in memory, omit it from logs, and cancel the request when the dialog closes or the account changes. Poll status with the original authenticated account. An approved phone request satisfies local computer unlock only; it must not manufacture an authentication token with higher assurance.

TS
type PhoneRequest = { id: string; nonce: string; expires_at: string };
export async function phoneOperation<T>(
  endpoint: string, accessToken: string, body: Record<string, unknown>,
): Promise<T> {
  const response = await fetch(endpoint, {
    method: 'POST',
    headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  });
  if (!response.ok) throw new Error('Phone approval is unavailable. Please try again.');
  return response.json() as Promise<T>;
}
// Use in a React event handler or a Next.js client component. Do not expose
// another user's access token or a service-role key through server props.
const request = await phoneOperation<PhoneRequest>(endpoint, accessToken, {
  operation: 'create', action_title: 'Unlock computer', requesting_device_label: 'Front desk',
});

Status and revocation:

BASH
curl 'https://PROJECT.supabase.co/functions/v1/phone-security' \
  -H "Authorization: Bearer $ACCESS_TOKEN" -H 'Content-Type: application/json' \
  -d '{"operation":"status","challenge_id":"REQUEST_UUID"}'
curl 'https://PROJECT.supabase.co/functions/v1/phone-security' \
  -H "Authorization: Bearer $FRESH_MFA_ACCESS_TOKEN" -H 'Content-Type: application/json' \
  -d '{"operation":"revoke","device_id":"REGISTERED_CREDENTIAL_ID"}'

Errors return a plain error message: 400 for invalid/failed/expired verification, 401 for an invalid account session, 403 for an unexpected browser origin, 404 for malformed/unavailable request IDs, 405 for unsupported methods, 409 when no passkey is registered, 413 for oversized input, and 503 when the secure origin is not configured. Failed verification never becomes approval. A browser cancellation requests denial; if the network fails, cancel on the computer or wait for expiry.

The complete machine-readable contract is phone-security.openapi.yaml. The operator must deploy the database changes, verifier function, and hosted phone page together before enabling phone approval.