Mandate · Guide
Use a policy webhook
A policy webhook asks your own service for a decision. Use one when the decision depends on something only your systems know, such as a risk engine or an internal limit. A rule that requires the webhook sends the action's facts to your service and waits up to 3 seconds for its decision. No answer denies the action.
The service is an ordinary webhook endpoint subscribed to mandate.policy.decision_requested. Each request is signed with the endpoint's secret, which is shown once, when you create the endpoint.
Before you begin: you need an HTTPS service that answers JSON, and an account API key. Creating an endpoint is open on every plan; saving a rule that uses one needs Pro or above.
1. Create the webhook endpoint
POST / takes an HTTPS URL and the event types it hears. Subscribe it to mandate.policy.decision_requested. The response carries the endpoint's id and its signing secret, once:
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x
curl -s -X POST "$PROVENANCE_API/v1/webhook_endpoints" \
-H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
-d '{ "url": "https://risk.example.com/provenance/decide", "event_types": ["mandate.policy.decision_requested"] }' \
| tee endpoint.json
{
"id": "we_01M7VG323DVNN693QRQ99HGAJ1",
"object": "webhook_endpoint",
"url": "https://risk.example.com/provenance/decide",
"event_types": ["mandate.policy.decision_requested"],
"status": "active",
"secret": "whsec_vWHapZL77CG5JffPNqDi5fCEEBafrY372r1Je8"
}
Store the secret in your service now. An API key can never read it back. An endpoint subscribed to * doesn't hear decision requests: it must name the event.
2. Verify each request
Provenance posts an event: { "id": "evt_…", "object": "event", "type": "mandate.policy.decision_requested", "data": { "rule_id": "…", "facts": { … } } }, with a Provenance-Signature header of the form t=<unix seconds>,v1=<hex>. Compute HMAC-SHA256 over <t>.<raw body> with the secret and compare it with each v1 value in constant time, exactly as for webhooks. Reject a request whose t is more than 5 minutes old.
Answer with JSON:
{ "decision": "deny", "reason": "over_daily_limit" }
The request is sent only while a rule is deciding. It isn't listed in your events and isn't retried.
3. Use it in a rule
Name the endpoint by its id:
{
"rules": [
{ "id": "ask-risk-engine", "when": [{ "fact": "transaction_amount", "op": "gt", "value": 25000 }], "require": { "webhook": "we_01M7VG323DVNN693QRQ99HGAJ1" } }
]
}
Saving the rule checks that the endpoint is yours, active and subscribed. A deny fails the verify with policy_webhook_denied, and require_approval asks a person. A timeout, a disabled or deleted endpoint, or any other answer fails it with policy_webhook_unavailable.
4. Rotate the secret
POST / issues a new secret and returns it, once. With previous_secret_expires_in (up to 86400 seconds) the old secret keeps signing beside it:
export ENDPOINT_ID=$(jq -r .id endpoint.json)
curl -s -X POST "$PROVENANCE_API/v1/webhook_endpoints/$ENDPOINT_ID/rotate_secret" \
-H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
-d '{ "previous_secret_expires_in": 86400 }'
{
"id": "we_01M7VG323DVNN693QRQ99HGAJ1",
"object": "webhook_endpoint",
"secret": "whsec_pT3kQ8vN2mW7sYd4cFjLh6gAe1rR5xB9nKz0Lq",
"previous_secret_expires_at": "2026-11-21T09:14:02.511Z"
}
Until previous_secret_expires_at every request carries two v1 values, one per secret, so your service keeps verifying while you deploy the new one. Without previous_secret_expires_in the old secret stops at once, which is what you want after a leak.
Errors you might see
| Symptom or code | Cause | Fix |
|---|---|---|
policy_ on require. | The id isn't an endpoint of yours, or it is disabled or not subscribed to mandate. | Create the endpoint, or add the event to its event_. |
idempotency_ | A retried create or rotation with the same Idempotency-Key | The first call succeeded; rotate again for a secret you can read. |
policy_ | Your service didn't answer within 3 seconds, answered something else, or the endpoint is disabled or gone | Check its logs, the URL and the endpoint. |