<!-- Generated by website/scripts/sync-docs.mjs from docs/api.md. Edit that file, not this one. -->

# API reference

> Every page of this site: https://dyokto.github.io/opa-authzen-plugin/llms.txt

The plugin serves these endpoints on OPA's own HTTP server (`:8181` by default). The [quick start](https://dyokto.github.io/opa-authzen-plugin/quickstart/) calls the evaluation endpoints against the policy in [example/](https://dyokto.github.io/opa-authzen-plugin/examples/).

## `POST /access/v1/evaluation`

Single access evaluation. Request body:

```json
{
  "subject":  {"type": "user", "id": "alice@example.com"},
  "action":   {"name": "can_read"},
  "resource": {"type": "account", "id": "123"},
  "context":  {"time": "2024-10-26T01:22-07:00"}
}
```

Response: `{"decision": true}`

## `POST /access/v1/evaluations`

Batch access evaluations with default value merging and evaluation semantics. See [example/](https://dyokto.github.io/opa-authzen-plugin/examples/) for detailed usage.

A request that carries one or more `evaluations` is answered with `{"evaluations": [...]}`, one Decision per request item in the same order. A request whose `evaluations` array is absent or empty is a single Access Evaluation (spec Section 7.1), and is answered with the singular `{"decision": ...}` — not a one-element batch envelope.

Send a batch evaluation request, for example to the server started in the [quick start](https://dyokto.github.io/opa-authzen-plugin/quickstart/):

```bash
curl -s -X POST http://localhost:8181/access/v1/evaluations \
  -H "Content-Type: application/json" \
  -d '{
    "subject": {"type": "user", "id": "alice", "properties": {"role": "admin"}},
    "action": {"name": "read"},
    "evaluations": [
      {"resource": {"type": "document", "id": "doc-1"}},
      {"resource": {"type": "document", "id": "doc-2"}},
      {"action": {"name": "delete"}, "resource": {"type": "document", "id": "doc-3"}}
    ]
  }'
```

The response should be:

```json
{"evaluations":[{"decision":true},{"decision":true},{"decision":true}]}
```

Top-level `subject`, `action`, `resource`, and `context` serve as defaults for each item in the `evaluations` array. Individual items can override any of these fields. See [Section 7](https://openid.net/specs/authorization-api-1_0.html#section-7) of the AuthZEN spec for details on evaluation semantics (`execute_all`, `deny_on_first_deny`, `permit_on_first_permit`).

Use evaluation semantics to short-circuit batch processing:

```bash
curl -s -X POST http://localhost:8181/access/v1/evaluations \
  -H "Content-Type: application/json" \
  -d '{
    "subject": {"type": "user", "id": "bob"},
    "action": {"name": "read"},
    "options": {"evaluations_semantic": "permit_on_first_permit"},
    "evaluations": [
      {"resource": {"type": "document", "id": "doc-1"}},
      {"resource": {"type": "document", "id": "doc-2"}}
    ]
  }'
```

## `POST /access/v1/search/subject`

Subject Search (spec Section 8.4). Requires `search.subject` to be configured. Request body:

```json
{
  "subject":  {"type": "user"},
  "action":   {"name": "can_read"},
  "resource": {"type": "account", "id": "123"},
  "page":     {"limit": 100}
}
```

Response:

```json
{
  "page": {"next_token": "", "count": 2, "total": 2},
  "results": [
    {"type": "user", "id": "alice@example.com"},
    {"type": "user", "id": "bob@example.com"}
  ]
}
```

## `POST /access/v1/search/resource`

Resource Search (spec Section 8.5). Requires `search.resource`. Same response shape as Subject Search; `results` are resource entities.

## `POST /access/v1/search/action`

Action Search (spec Section 8.6). Requires `search.action`. Request omits the `action` key. `results` are action entities of shape `{"name": "..."}`.

## `GET /.well-known/authzen-configuration`

PDP metadata discovery endpoint (Section 9).

```bash
curl -s http://localhost:8181/.well-known/authzen-configuration | jq .
```

Response, with no `search` rules configured:

```json
{
  "policy_decision_point": "http://localhost:8181",
  "access_evaluation_endpoint": "http://localhost:8181/access/v1/evaluation",
  "access_evaluations_endpoint": "http://localhost:8181/access/v1/evaluations"
}
```
