View as Markdown

Mandate · Guide

CIBA authorization server

Available on Pro, Growth and Enterprise

Provenance implements OpenID Connect CIBA core (Client-Initiated Backchannel Authentication) in poll and ping modes, with Rich Authorization Requests (RFC 9396) of type provenance_action.

A client that already speaks CIBA asks a person to approve an action out of band. The account's policy decides whether a person is needed, and the person approves on their phone. The client then gets an intent token bound to that exact action, a receipt for each decision, and an id token describing the approver.

Every CIBA request goes through the same path as POST /v1/mandate/intents and POST /v1/mandate/assessments: the same policy, the same approval routing and delivery, the same decision ledger.

Before you begin: CIBA clients are on Pro and up (one client on Free). The person you ask must already be on the account: the owner, a member with the approver role or above, or an outside approver with an active link. Add an approval rule for the actions you'll send, as in policies.

  1. bc_authorize
    client authenticated, hint, authorization_details
  2. Policy decides
    allow, approval to the person, or deny
  3. Poll the token endpoint
    authorization_pending, then tokens

1. Create an OAuth client

In the console, open Developers → OAuth clients and create a client, or call POST /v1/oauth/clients. private_key_jwt is preferred: the client signs a short assertion with its own key (ES256 or EdDSA), and you register the public key inline or as a JWKS URL. client_secret_basic returns a secret once.

curl -s $PROVENANCE_API/v1/oauth/clients \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Acme Payables",
    "auth_method": "private_key_jwt",
    "jwks_uri": "https://payables.acme.example/.well-known/jwks.json"
  }'
{
  "id": "occ_01M6H9QK2B7Q9V3N8K4T6W1Y0R",
  "object": "oauth_client",
  "name": "Acme Payables",
  "auth_method": "private_key_jwt",
  "jwks_uri": "https://payables.acme.example/.well-known/jwks.json",
  "jwks": null,
  "allowed_scopes": ["openid"],
  "allowed_details_types": ["provenance_action"],
  "delivery_modes": ["poll"],
  "status": "active"
}

The client's name is what the person sees on the approval page. In live mode, a developer's change to a client waits for an owner or admin.

2. Discover the endpoints

Clients read the endpoints from OpenID discovery (the same CIBA fields are in the RFC 8414 metadata at /.well-known/oauth-authorization-server).

curl -s $PROVENANCE_API/.well-known/openid-configuration

The fields a CIBA client reads:

FieldValue
backchannel_authentication_endpointWhere to send the request
backchannel_token_delivery_modes_supported["poll", "ping"]
backchannel_user_code_parameter_supportedfalse
authorization_details_types_supported["provenance_action"]
token_endpointWhere to poll
token_endpoint_auth_methods_supportedprivate_key_jwt, client_secret_basic
jwks_uriThe keys that sign the access token and the id token

3. Ask the person

POST /v1/oauth/bc_authorize is form-encoded. Authenticate the client, send scope=openid, exactly one hint, and the action in authorization_details:

FieldWhat it is
login_hintThe person's email (the owner, a member or an outside approver), or the pairwise sub from an earlier id token
id_token_hintAn id token Provenance issued to this client (login_hint_token takes the same)
binding_messageUp to 64 characters, shown to the person on the approval page so they can match it to your app
requested_expirySeconds the request may wait (default 600, at most 1800)
authorization_detailsA JSON array of 1 to 5 provenance_action objects

Each provenance_action is decided as its own action and gets its own receipt:

FieldWhat it isPolicy fact
action_typeRequired: what kind of action (pay_invoice)action_type
descriptionRequired: what the person reads
amount, currencyThe amount and its ISO 4217 currencytransaction_amount, currency
counterpartyWho the action is withcounterparty
payload_hashThe SHA-256 of your own exact payload
mandate_idA grant the action runs under (the only detail then)the grant's limits
run_idAn agent-team runthe run facts

The policy also reads oauth_client_id, so a rule can apply to one client.

curl -s $PROVENANCE_API/v1/oauth/bc_authorize \
  -d scope=openid \
  -d login_hint=ana@acme.example \
  -d binding_message="Code 7Q4-K2" \
  --data-urlencode 'authorization_details=[{"type":"provenance_action","action_type":"pay_invoice","description":"Pay invoice INV-1042 to Brindlecote Supplies for $2,400","amount":2400,"currency":"USD","counterparty":"brindlecote.example"}]' \
  -d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer \
  -d client_assertion=$CLIENT_ASSERTION
{ "auth_req_id": "cba_Vq7m2KxT9nB4wC1zD3fG6hJ0kL5pSrY8aE1uR8oI2tY", "expires_in": 600, "interval": 5 }

What happens depends on the policy:

  • allow: the action is approved at once (it's still a decision in the ledger). The first poll returns tokens.
  • require_approval: an approval goes to the hinted person, by their delivery channels, with the description, amount, counterparty and binding message. The first poll returns authorization_pending.
  • deny: the request answers access_denied with the reason in error_description.

4. Poll the token endpoint

Poll POST /v1/oauth/token with grant_type=urn:openid:params:grant-type:ciba and the auth_req_id, authenticating the client the same way, no more often than interval seconds:

AnswerMeaning
authorization_pendingThe person hasn't decided
slow_downYou polled faster than interval; it's now 5 seconds longer
access_deniedThe person declined, or the policy denied it. error_description is the reason code: unrecognized, wrong_amount, not_now or off_task for a person's decline
expired_tokenNobody decided before expires_in
invalid_grantThe auth_req_id is unknown, belongs to another client, or was already used

Once approved, the answer has the tokens. The auth_req_id works once.

{
  "access_token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImludGVudC0xIn0…",
  "token_type": "Bearer",
  "expires_in": 14398,
  "scope": "openid",
  "id_token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9…",
  "authorization_details": [
    {
      "type": "provenance_action",
      "action_type": "pay_invoice",
      "description": "Pay invoice INV-1042 to Brindlecote Supplies for $2,400",
      "amount": 2400,
      "currency": "USD",
      "counterparty": "brindlecote.example",
      "receipt_id": "rcpt_3f9c2a71d84b4e06a1c5b7e2d9f04a63"
    }
  ]
}

With several details, each also carries its own intent_token, and access_token is the first one's.

Ping instead of polling

A ping client doesn't poll while the person decides. Register it with delivery_modes including ping and an https notification_endpoint (your backchannel_client_notification_endpoint), then send a client_notification_token with each request:

StepWhat happens
bc_authorize with client_notification_tokenThe request is in ping mode
The person decides (or the policy allows it at once)Provenance POSTs { "auth_req_id": "…" } to your endpoint once, with Authorization: Bearer <client_notification_token>
Your endpoint answers 2xxYou poll the token endpoint once and get the tokens or access_denied

Check the bearer before you trust a ping. If your endpoint is down, the ping isn't retried, and polling still works. An expiry isn't pinged.

5. Verify the access token

The access token is a Provenance intent token, ES256, signed by a key in /.well-known/jwks.json. Check the signature, then its claims:

ClaimCheck
action_hashThe SHA-256 of the detail's description
payload_hashThe SHA-256 of the detail in canonical JSON (keys sorted)
audYour client id
confirmed.viaapproval when a person approved
authorization_detailsThe detail as approved

To check revocation and the approval server side as well, send the token to POST /v1/mandate/assessments with the description as action_description and the detail as action_payload.

6. Read the id token

The id token describes the person who approved this request:

ClaimValue
issThe issuer from discovery
audYour client id
subA pairwise subject: stable for this person at your client, unrelated at any other
acrpasskey, biometric or session: how they approved
amr["hwk", "user"] for a passkey or biometric, ["user"] for a signed-in session
auth_timeWhen they approved

When the policy allowed the action without a person, the id token names the hinted person and carries no authentication claims. The next time you ask the same person, send sub as the login_hint or the id token as id_token_hint.

A complete client

Node (18 or later), with an ES256 key whose public half is registered on the client:

import { createPrivateKey, createSign, randomUUID } from "node:crypto";

const api = process.env.PROVENANCE_API;
const clientId = process.env.CIBA_CLIENT_ID;
const key = createPrivateKey(process.env.CIBA_PRIVATE_KEY_PEM);
const kid = process.env.CIBA_KEY_ID;
const b64u = (v) => (Buffer.isBuffer(v) ? v : Buffer.from(typeof v === "string" ? v : JSON.stringify(v))).toString("base64url");

function assertion(aud) {
  const now = Math.floor(Date.now() / 1000);
  const input = `${b64u({ alg: "ES256", kid, typ: "JWT" })}.${b64u({ iss: clientId, sub: clientId, aud, jti: randomUUID(), iat: now, exp: now + 120 })}`;
  const sig = createSign("SHA256").update(input).sign({ key, dsaEncoding: "ieee-p1363" });
  return `${input}.${b64u(sig)}`;
}

async function post(path, fields) {
  const body = new URLSearchParams({
    ...fields,
    client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
    client_assertion: assertion(`${api}${path}`),
  });
  const res = await fetch(`${api}${path}`, { method: "POST", body });
  return res.json();
}

const start = await post("/v1/oauth/bc_authorize", {
  scope: "openid",
  login_hint: "ana@acme.example",
  binding_message: "Code 7Q4-K2",
  authorization_details: JSON.stringify([
    { type: "provenance_action", action_type: "pay_invoice", description: "Pay invoice INV-1042 to Brindlecote Supplies for $2,400", amount: 2400, currency: "USD", counterparty: "brindlecote.example" },
  ]),
});
if (start.error) throw new Error(`${start.error}: ${start.error_description}`);

let interval = start.interval;
for (;;) {
  await new Promise((r) => setTimeout(r, interval * 1000));
  const t = await post("/v1/oauth/token", { grant_type: "urn:openid:params:grant-type:ciba", auth_req_id: start.auth_req_id });
  if (t.error === "authorization_pending") continue;
  if (t.error === "slow_down") { interval += 5; continue; }
  if (t.error) throw new Error(`${t.error}: ${t.error_description}`);
  console.log("approved", t.authorization_details[0].receipt_id);
  break;
}

Python, with httpx and cryptography:

import json, os, time, uuid, base64
import httpx
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature

api = os.environ["PROVENANCE_API"]
client_id = os.environ["CIBA_CLIENT_ID"]
kid = os.environ["CIBA_KEY_ID"]
key = serialization.load_pem_private_key(os.environ["CIBA_PRIVATE_KEY_PEM"].encode(), password=None)

def b64u(b: bytes) -> str:
    return base64.urlsafe_b64encode(b).rstrip(b"=").decode()

def assertion(aud: str) -> str:
    now = int(time.time())
    header = b64u(json.dumps({"alg": "ES256", "kid": kid, "typ": "JWT"}).encode())
    payload = b64u(json.dumps({"iss": client_id, "sub": client_id, "aud": aud, "jti": str(uuid.uuid4()), "iat": now, "exp": now + 120}).encode())
    r, s = decode_dss_signature(key.sign(f"{header}.{payload}".encode(), ec.ECDSA(hashes.SHA256())))
    return f"{header}.{payload}.{b64u(r.to_bytes(32, 'big') + s.to_bytes(32, 'big'))}"

def post(path: str, fields: dict) -> dict:
    data = {**fields, "client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", "client_assertion": assertion(api + path)}
    return httpx.post(api + path, data=data).json()

start = post("/v1/oauth/bc_authorize", {
    "scope": "openid",
    "login_hint": "ana@acme.example",
    "binding_message": "Code 7Q4-K2",
    "authorization_details": json.dumps([{"type": "provenance_action", "action_type": "pay_invoice", "description": "Pay invoice INV-1042 to Brindlecote Supplies for $2,400", "amount": 2400, "currency": "USD", "counterparty": "brindlecote.example"}]),
})
if "error" in start:
    raise SystemExit(f"{start['error']}: {start['error_description']}")

interval = start["interval"]
while True:
    time.sleep(interval)
    t = post("/v1/oauth/token", {"grant_type": "urn:openid:params:grant-type:ciba", "auth_req_id": start["auth_req_id"]})
    if t.get("error") == "authorization_pending":
        continue
    if t.get("error") == "slow_down":
        interval += 5
        continue
    if "error" in t:
        raise SystemExit(f"{t['error']}: {t['error_description']}")
    print("approved", t["authorization_details"][0]["receipt_id"])
    break

Errors you might see

The OAuth endpoints answer RFC 6749 errors, { "error", "error_description", "error_uri", "request_id" }, so existing CIBA libraries read them unchanged. invalid_client is a 401; the others are 400.

errorWhen
invalid_clientUnknown or disabled client, a wrong secret, or an assertion that fails: signature, aud, exp more than 5 minutes out, a reused jti, or a JWKS URL that couldn't be fetched
invalid_requestA missing scope/openid, no hint or more than one, user_code, a requested_expiry under 60
invalid_scopeA scope the client isn't allowed
unknown_user_idThe hint doesn't name a person on the account
invalid_authorization_detailsNot 1 to 5 valid provenance_action objects
invalid_binding_messageOver 64 characters
unauthorized_clientA detail type or delivery mode the client isn't allowed
access_deniedThe policy denied it (error_description is the reason)

Limits

  • 60 backchannel requests a minute per client.
  • Requests wait 10 minutes by default and 30 at most.
  • Each action is one metered decision, as a verify is.
  • Push delivery mode and user codes aren't offered, and a hint never reaches a person the account hasn't added.

See also