Skip to main content

Ask for a decision with AuthZEN

Use POST /access/v1/evaluation when a service needs a yes or no answer about a subject, an action and a resource, and has no token for that subject. The request and response follow the AuthZEN access evaluation shape.

Give the caller the authzen scope​

The caller is a client with the authzen scope on the built-in type urn:as:authzen. This grants it to the orders-api client from Check a token at your resource server with introspection. The call replaces that client's entry, so it lists both grants.

curl -fsS -X PATCH "$POLICYARC_URL/admin/api/policy-data/by-key?dataKey=pbac.operator.controls.client_entitlements" \
-H "X-Admin-API-Key: $POLICYARC_ADMIN_KEY" \
-H 'Content-Type: application/json' \
-d "$(jq -nc --arg path "client_id.$RS_CLIENT_ID" --argjson value '{"grant_types": ["client_credentials"], "granted_resources": [{"type": "urn:as:introspect", "scopes": ["introspection"]}, {"type": "urn:as:authzen", "scopes": ["authzen"]}]}' '{$path, $value}')"

Ask​

The block first waits a few seconds for the policy engine to load the grant.

sleep 5
AUTHZEN_TOKEN=$(curl -fsS -u "$RS_CLIENT_ID:$RS_CLIENT_SECRET" "$POLICYARC_URL/token" \
-d grant_type=client_credentials -d scope=authzen -d resource_types=urn:as:authzen |
jq -er .access_token)
export AUTHZEN_TOKEN

resp=$(curl -fsS "$POLICYARC_URL/access/v1/evaluation" \
-H "Authorization: Bearer $AUTHZEN_TOKEN" \
-H 'Content-Type: application/json' \
-d "$(jq -nc --arg client "$CLIENT_ID" '{
subject: {type: "user", id: "alice@example.com"},
action: {name: "orders:read"},
resource: {type: "urn:example:orders", id: "42"},
context: {client_id: $client, resource_type: "urn:example:orders"}
}')")
echo "$resp"
jq -e '.decision == true' <<<"$resp" >/dev/null || { echo 'Expected "decision": true' >&2; false; }

context.client_id names the registered client the decision is for: here the orders-agent client from Register a managed resource, which holds orders:read on urn:example:orders. Policy applies that client's entitlements, segments, controls and obligations, as it does at the gateway, and no token is issued.

The answer is {"decision": true}, or {"decision": false} with the reason in context.reason. The check expects true, because the client holds the scope. action, resource and context.client_id are required. subject is optional: a request that names no user is decided as a call by the client alone.

A request without context.client_id gets HTTP 400 {"error":"invalid_request","error_description":"context.client_id is required"}.

code=$(curl -sS -o /dev/null -w '%{http_code}' "$POLICYARC_URL/access/v1/evaluation" \
-H "Authorization: Bearer $AUTHZEN_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"action": {"name": "orders:read"}, "resource": {"type": "urn:example:orders", "id": "42"}}')
[ "$code" = 400 ] || { echo "Expected HTTP 400, got $code" >&2; false; }

Basic auth with the client's id and secret works too, in place of the bearer token. The admin key does not. A call with only X-Admin-API-Key gets HTTP 401 {"error":"invalid_client","error_description":"client_id or Bearer token is required"}.

Each decision writes an /access/v1/evaluation audit row with the client id and the decision.