# Veripass Policy Evaluation

> Evaluates access policies against Veripass Identity Contract.

Source: https://docs.sommatic.ai/en/nodes/veripass.evaluate/

- Slug: `veripass.evaluate`
- Family: Identity
- Version: 1.0.0
- Status: Available
- Execution: async

Evaluates access policies against Veripass Identity Contract.

## Configuration

- `connection_id` (string, required): Credential for Veripass policy evaluation. Accepts credentials of type `api-key` (Veripass API key).
- `policy_set` (string, optional): Policy Set ID or Name
- `resource` (string, optional): Resource identifier
- `action` (string, required): Action (read, write, etc.)
- `context` (object, optional): Additional context (user_id, IP, etc.)

## Output ports

- `allow` (default): Access granted
- `deny`: Access denied
- `challenge`: MFA or step-up required
- `error`: Evaluation error

## Input contract

- `connection_id` (string, required)
- `policy_set` (string, optional)
- `resource` (string, optional)
- `action` (string, required)
- `context` (object, optional)

## Output contract

- `decision` (string, optional): Allowed values: `allow`, `deny`, `challenge`.
- `reason` (string, optional)
- `obligations` (array, optional)

## In expressions

What a later node can read from this node's output with `$("Veripass Policy Evaluation").item.json.<path>` (write your node's label instead of `Veripass Policy Evaluation`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `allow`, from the output shown in Ports.

- `$("Veripass Policy Evaluation").item.json.decision` (string) = `"allow"`
- `$("Veripass Policy Evaluation").item.json.reason` (string) = `"Role approver may approve invoices"`
- `$("Veripass Policy Evaluation").item.json.obligations` (array) = `[…] (0)`


## How it works

Asks Veripass for a policy decision on an action over a resource and routes to `allow`, `challenge` or `deny` according to the `decision` in the response.

1. Resolves the config; leaves through `error` when `connection_id` or `action` is empty.
2. Resolves the credential on the server: its configuration gives the Veripass base URL (`url` or `baseUrl`) and optional extra `headers`; its secret gives the authentication.
3. Sends `POST <base URL>/api/identity/contract/evaluate` with the body `{ policy_set, resource, action, context }` (`context` defaults to `{}`).
4. Reads `decision`, `reason` and `obligations` from the response body.
5. Routes `allow` to `allow` and `challenge` to `challenge`. Any other value, including a missing one, goes to `deny` with `decision: "deny"` and `reason` defaulting to `Policy denied`.
6. A network error or a non-2xx answer leaves through `error` with the message and the response body.

## In a workflow

### Node

```json
{
  "node_id": "node-authorize-approval",
  "label": "Authorize invoice approval",
  "operator_slug": "veripass.evaluate",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "policy_set": "finance-approvals",
    "resource": "invoice:{{ $json.invoice_id }}",
    "action": "approve",
    "context": "{{ $json.request_context }}"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "allow",
  "data": {
    "decision": "allow",
    "reason": "Role approver may approve invoices",
    "obligations": []
  }
}
```

## Output ports (behaviour in the code)

### `allow`

Veripass answered `decision: "allow"`.

```json
{
  "decision": "allow",
  "reason": "Role approver may approve invoices",
  "obligations": []
}
```

### `challenge`

Veripass answered `decision: "challenge"` (for example step-up authentication).

```json
{
  "decision": "challenge",
  "reason": "Step-up authentication required",
  "obligations": [
    "mfa"
  ]
}
```

### `deny`

Veripass answered `deny`, any other value, or no `decision` at all.

```json
{
  "decision": "deny",
  "reason": "Policy denied"
}
```

### `error`

Missing `connection_id` or `action`, the credential cannot be resolved, or the HTTP call failed.

```json
{
  "error": "Request failed with status code 401",
  "response": {
    "message": "Unauthorized"
  }
}
```

## Behaviour in the code

- `connection_id`: The credential configuration must include the Veripass base URL as `url` (or `baseUrl`); `headers` there are added to the request. Authentication comes from the secret: an object with `token` sends `Authorization: Bearer <token>`, an object with `apiKey` sends `x-api-key`. A plain string secret adds no authentication header.
- `context`: Sent as-is. Use a pure expression such as `{{ $json.request_context }}` to pass an object; mixed text arrives as a string.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `connection_id is required` | `error` | No Veripass credential is selected. |
| `action is required` | `error` | `action` is empty or its expression resolved to nothing. |
| `Request failed with status code <status>` | `error` | Veripass rejected the call: 401/403 usually means the credential secret does not carry a usable `token` or `apiKey`; 404 means the base URL is wrong. `response` holds the body Veripass returned. |
| `Failed to resolve connection <connection_id>: <detail>` | `error` | The credential id does not exist or is not available to this workflow. |

## Notes and limits

- Unknown or missing decisions route to `deny`, so the node fails closed.
- The returned envelopes carry no `ok` field, and no request timeout is set on the call.
- Leaving through `error` does not fail the run: the engine follows the edges wired to `error`, and if there are none the branch simply ends.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "veripass.evaluate",
  "name": "Veripass Policy Evaluation",
  "category": "identity",
  "version": "1.0.0",
  "description": "Evaluates access policies against Veripass Identity Contract.",
  "capabilities": [
    "authz",
    "policy",
    "veripass",
    "identity"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "Veripass Credential",
        "description": "Credential for Veripass policy evaluation. Accepts credentials of type `api-key` (Veripass API key).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "api-key"
          ],
          "types": [
            "veripass",
            "http"
          ]
        }
      },
      "policy_set": {
        "type": "string",
        "description": "Policy Set ID or Name"
      },
      "resource": {
        "type": "string",
        "description": "Resource identifier"
      },
      "action": {
        "type": "string",
        "description": "Action (read, write, etc.)"
      },
      "context": {
        "type": "object",
        "description": "Additional context (user_id, IP, etc.)"
      }
    },
    "required": [
      "connection_id",
      "action"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "policy_set": {
        "type": "string"
      },
      "resource": {
        "type": "string"
      },
      "action": {
        "type": "string"
      },
      "context": {
        "type": "object"
      }
    },
    "required": [
      "connection_id",
      "action"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "decision": {
        "type": "string",
        "enum": [
          "allow",
          "deny",
          "challenge"
        ]
      },
      "reason": {
        "type": "string"
      },
      "obligations": {
        "type": "array"
      }
    }
  },
  "ports": [
    {
      "port_id": "allow",
      "label": "Allow",
      "description": "Access granted",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "deny",
      "label": "Deny",
      "description": "Access denied",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "challenge",
      "label": "Challenge",
      "description": "MFA or step-up required",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Evaluation error",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "identity-worker",
    "standard"
  ],
  "tags": [
    "veripass",
    "security",
    "policy"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_veripass",
    "profile": {
      "name": "Veripass",
      "verified": true,
      "url": "https://me.veripass.com/veripass",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string",
      "title": "Veripass Credential",
      "description": "Credential for Veripass policy evaluation. Accepts credentials of type `api-key` (Veripass API key).",
      "ui_widget": "connection_picker",
      "ui_options": {
        "credential_types": [
          "api-key"
        ],
        "types": [
          "veripass",
          "http"
        ]
      }
    },
    "policy_set": {
      "type": "string",
      "description": "Policy Set ID or Name"
    },
    "resource": {
      "type": "string",
      "description": "Resource identifier"
    },
    "action": {
      "type": "string",
      "description": "Action (read, write, etc.)"
    },
    "context": {
      "type": "object",
      "description": "Additional context (user_id, IP, etc.)"
    }
  },
  "required": [
    "connection_id",
    "action"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string"
    },
    "policy_set": {
      "type": "string"
    },
    "resource": {
      "type": "string"
    },
    "action": {
      "type": "string"
    },
    "context": {
      "type": "object"
    }
  },
  "required": [
    "connection_id",
    "action"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "decision": {
      "type": "string",
      "enum": [
        "allow",
        "deny",
        "challenge"
      ]
    },
    "reason": {
      "type": "string"
    },
    "obligations": {
      "type": "array"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "allow",
    "label": "Allow",
    "description": "Access granted",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "deny",
    "label": "Deny",
    "description": "Access denied",
    "is_default": false,
    "supports_condition": true
  },
  {
    "port_id": "challenge",
    "label": "Challenge",
    "description": "MFA or step-up required",
    "is_default": false,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Evaluation error",
    "is_default": false,
    "supports_condition": false
  }
]
```
