{
  "id": "authz-1",
  "title": "KBAC: Can this person act on that resource? Relationship-based authorization with the AuthZEN API",
  "description": "Create a Knowledge-Based Access Control (KBAC) policy and execute authZEN-compliant authorization queries. This example demonstrates evaluation (can X do Y to Z?) and search operations (who can? what can? which resources?).",
  "category": "KBAC",
  "tags": [
    "KBAC Policy",
    "authZEN",
    "Authorization",
    "Evaluation",
    "Action Search",
    "Resource Search",
    "Subject Search",
    "Access Control"
  ],
  "api": "KBAC",
  "language": "Python",
  "lastUpdated": "2026-07-14",
  "openApiEndpoints": [
    "/capture/v1/nodes",
    "/capture/v1/relationships",
    "/configs/v1/authorization-policies",
    "/access/v1/evaluation",
    "/access/v1/search/action",
    "/access/v1/search/resource",
    "/access/v1/search/subject"
  ],
  "relatedGuides": [
    "/guides/guide-authzen",
    "/guides/guide-dynamic-authz",
    "/guides/guide-sandbox"
  ],
  "commonErrors": [
    {
      "code": "401",
      "message": "UNAUTHENTICATED",
      "solution": "Check X-IK-ClientKey header contains valid AppAgent credentials"
    },
    {
      "code": "404",
      "message": "NOT_FOUND",
      "solution": "Verify the policy exists and the subject/resource nodes exist in the IKG"
    }
  ],
  "summary": "This example demonstrates KBAC (Knowledge-Based Access Control) using the authZEN standard API:\n\nPolicy logic: A Person can perform CAN_DRIVE on a Car if they have a DRIVES relationship to that Car in the graph.\n\nauthZEN operations demonstrated:\n1. Evaluation: \"Can knightrider drive kitt?\" -> true; \"Can knightrider drive cadillacv16?\" -> false\n2. Action Search: \"What actions can knightrider perform on kitt?\" -> [\"CAN_DRIVE\"]\n3. Resource Search: \"Which cars can knightrider drive?\" -> [\"kitt\"]\n4. Subject Search: \"Who can drive kitt?\" -> [\"knightrider\"]\n\nauthZEN is an OpenID standard for authorization APIs (https://openid.net/specs/authorization-api-1_0-03.html).\n\nPolicy version note: the policy in this example uses \"policy_version\": \"2.0-kbac\". The same policy JSON is also accepted with \"policy_version\": \"3.0-kbac\" (identical schema, raw-Cypher semantics; do not reference $subject_id or external properties). Only 3.0-kbac additionally accepts USE graph.byName() routing and CALL { } subqueries for composite / data-residency IKGs - see resources authz-7 and authz-8.",
  "usecase": "Scenario: A car-sharing application needs to verify driving permissions.\n\nGraph structure (the shared AuthZEN dataset):\n- Person(knightrider) -[DRIVES]-> Car(kitt)\n- Person(satchmo) -[DRIVES]-> Car(cadillacv16)\n- Person(alice) -[DRIVES]-> Car(cadillacv16)\n- Person(karel) -[HAS]-> Ticket(listek) -[FOR]-> Bus(harmonika)\n\nAuthorization questions the app can ask:\n1. \"Can knightrider drive kitt?\" -> true (DRIVES relationship exists)\n2. \"Can knightrider drive cadillacv16?\" -> false (no DRIVES relationship)\n3. \"What can knightrider do with kitt?\" -> [\"CAN_DRIVE\"]\n4. \"Which cars can knightrider drive?\" -> [\"kitt\"]\n5. \"Who can drive kitt?\" -> [\"knightrider\"]\n\nUse this pattern for: vehicle access, device permissions, resource sharing, any permission that follows from a relationship in the graph.",
  "requirements": "Prerequisites:\n- ServiceAccount credentials: For creating policies (Bearer token)\n- AppAgent credentials: For data ingestion and authorization queries (X-IK-ClientKey)\n\nRequired API access:\n- POST /capture/v1/nodes/ and /capture/v1/relationships/ (graph data)\n- POST /configs/v1/authorization-policies (create policy)\n- POST /access/v1/evaluation (single authorization check)\n- POST /access/v1/search/action (what actions are permitted?)\n- POST /access/v1/search/resource (which resources can be accessed?)\n- POST /access/v1/search/subject (who can access this resource?)",
  "steps": "Step 1: Ingest Authorization Graph Data\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST Person (alice, knightrider, satchmo, karel), Car (kitt, cadillacv16), Bus, Ticket and Laptop nodes, then the DRIVES, OWNS, HAS and FOR relationships\n- Result: Graph ready for authorization queries\n\nStep 2: Create KBAC Policy\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST a 2.0-kbac policy: subject type Person, action CAN_DRIVE, resource type Car, cypher MATCH (subject:Person)-[:DRIVES]->(resource:Car)\n- Result: Policy ID returned\n\nStep 3: Run authZEN Evaluation\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST to /access/v1/evaluation with subject, action, resource\n- Input: subject Person knightrider, action CAN_DRIVE, resource Car kitt -> {\"decision\": true}; resource Car cadillacv16 -> {\"decision\": false}\n\nStep 4: Run authZEN Searches\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action Search (subject knightrider, resource kitt): {\"results\": [{\"name\": \"CAN_DRIVE\"}]}\n- Resource Search (subject knightrider, action CAN_DRIVE, resource type Car): {\"results\": [{\"type\": \"Car\", \"id\": \"kitt\"}]}\n- Subject Search (subject type Person, action CAN_DRIVE, resource kitt): {\"results\": [{\"type\": \"Person\", \"id\": \"knightrider\"}]}\n\nStep 5: Cleanup\n- Action: DELETE policy configuration",
  "graph": {
    "caption": "The graph the example runs on: 9 nodes (4 Person, 2 Car, 1 Bus, 1 Ticket, 1 Laptop) and 8 relationships (DRIVES, HAS, FOR, OWNS). Hover a node for its properties, click it to highlight its neighbourhood.",
    "nodes": [
      {
        "external_id": "alice",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "alice@email.com"
          },
          {
            "type": "given_name",
            "value": "Alice"
          },
          {
            "type": "last_name",
            "value": "Smith"
          }
        ]
      },
      {
        "external_id": "knightrider",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "knightrider@demo.com"
          },
          {
            "type": "name",
            "value": "Michael Knight"
          }
        ]
      },
      {
        "external_id": "satchmo",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "satchmo@demo.com"
          },
          {
            "type": "name",
            "value": "Louis Armstrong"
          }
        ]
      },
      {
        "external_id": "karel",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "karel@demo.com"
          },
          {
            "type": "name",
            "value": "Karel Plihal"
          }
        ]
      },
      {
        "external_id": "kitt",
        "type": "Car",
        "is_identity": false,
        "properties": [
          {
            "type": "manufacturer",
            "value": "pontiac"
          },
          {
            "type": "model",
            "value": "Firebird"
          }
        ]
      },
      {
        "external_id": "cadillacv16",
        "type": "Car",
        "is_identity": false,
        "properties": [
          {
            "type": "manufacturer",
            "value": "Cadillac"
          },
          {
            "type": "model",
            "value": "V-16"
          }
        ]
      },
      {
        "external_id": "harmonika",
        "type": "Bus",
        "is_identity": false,
        "properties": [
          {
            "type": "manufacturer",
            "value": "Ikarus"
          },
          {
            "type": "model",
            "value": "280"
          }
        ]
      },
      {
        "external_id": "listek",
        "type": "Ticket",
        "is_identity": false,
        "properties": []
      },
      {
        "external_id": "airbook-xyz",
        "type": "Laptop",
        "is_identity": false,
        "properties": []
      }
    ],
    "relationships": [
      {
        "source": "knightrider",
        "target": "kitt",
        "type": "DRIVES",
        "properties": []
      },
      {
        "source": "satchmo",
        "target": "cadillacv16",
        "type": "DRIVES",
        "properties": []
      },
      {
        "source": "karel",
        "target": "listek",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "listek",
        "target": "harmonika",
        "type": "FOR",
        "properties": []
      },
      {
        "source": "karel",
        "target": "airbook-xyz",
        "type": "OWNS",
        "properties": []
      },
      {
        "source": "alice",
        "target": "airbook-xyz",
        "type": "OWNS",
        "properties": []
      },
      {
        "source": "knightrider",
        "target": "kitt",
        "type": "OWNS",
        "properties": []
      },
      {
        "source": "alice",
        "target": "cadillacv16",
        "type": "DRIVES",
        "properties": []
      }
    ]
  },
  "code": [
    {
      "step": "Step 1",
      "description": "Capture the nodes needed for this use case.",
      "filename": "POST https://eu.api.indykite.com/capture/v1/nodes/",
      "language": "Json",
      "ingest": {
        "nodes": [
          {
            "external_id": "alice",
            "is_identity": true,
            "type": "Person",
            "properties": [
              {
                "type": "email",
                "value": "alice@email.com"
              },
              {
                "type": "given_name",
                "value": "Alice"
              },
              {
                "type": "last_name",
                "value": "Smith"
              }
            ]
          },
          {
            "external_id": "knightrider",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "knightrider@demo.com"
              },
              {
                "type": "name",
                "value": "Michael Knight"
              }
            ]
          },
          {
            "external_id": "satchmo",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "satchmo@demo.com"
              },
              {
                "type": "name",
                "value": "Louis Armstrong"
              }
            ]
          },
          {
            "external_id": "karel",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "karel@demo.com"
              },
              {
                "type": "name",
                "value": "Karel Plihal"
              }
            ]
          },
          {
            "external_id": "kitt",
            "type": "Car",
            "is_identity": false,
            "properties": [
              {
                "type": "manufacturer",
                "value": "pontiac"
              },
              {
                "type": "model",
                "value": "Firebird"
              }
            ]
          },
          {
            "external_id": "cadillacv16",
            "type": "Car",
            "is_identity": false,
            "properties": [
              {
                "type": "manufacturer",
                "value": "Cadillac"
              },
              {
                "type": "model",
                "value": "V-16"
              }
            ]
          },
          {
            "external_id": "harmonika",
            "type": "Bus",
            "is_identity": false,
            "properties": [
              {
                "type": "manufacturer",
                "value": "Ikarus"
              },
              {
                "type": "model",
                "value": "280"
              }
            ]
          },
          {
            "external_id": "listek",
            "type": "Ticket",
            "is_identity": false
          },
          {
            "external_id": "airbook-xyz",
            "type": "Laptop",
            "is_identity": false
          }
        ]
      }
    },
    {
      "description": "Capture the relationships needed for this use case.",
      "filename": "POST https://eu.api.indykite.com/capture/v1/relationships/",
      "language": "Json",
      "ingest": {
        "relationships": [
          {
            "source": {
              "external_id": "knightrider",
              "type": "Person"
            },
            "target": {
              "external_id": "kitt",
              "type": "Car"
            },
            "type": "DRIVES"
          },
          {
            "source": {
              "external_id": "satchmo",
              "type": "Person"
            },
            "target": {
              "external_id": "cadillacv16",
              "type": "Car"
            },
            "type": "DRIVES"
          },
          {
            "source": {
              "external_id": "karel",
              "type": "Person"
            },
            "target": {
              "external_id": "listek",
              "type": "Ticket"
            },
            "type": "HAS"
          },
          {
            "source": {
              "external_id": "listek",
              "type": "Ticket"
            },
            "target": {
              "external_id": "harmonika",
              "type": "Bus"
            },
            "type": "FOR"
          },
          {
            "source": {
              "external_id": "karel",
              "type": "Person"
            },
            "target": {
              "external_id": "airbook-xyz",
              "type": "Laptop"
            },
            "type": "OWNS"
          },
          {
            "source": {
              "external_id": "alice",
              "type": "Person"
            },
            "target": {
              "external_id": "airbook-xyz",
              "type": "Laptop"
            },
            "type": "OWNS"
          },
          {
            "source": {
              "external_id": "knightrider",
              "type": "Person"
            },
            "target": {
              "external_id": "kitt",
              "type": "Car"
            },
            "type": "OWNS"
          },
          {
            "source": {
              "external_id": "alice",
              "type": "Person"
            },
            "target": {
              "external_id": "cadillacv16",
              "type": "Car"
            },
            "type": "DRIVES"
          }
        ]
      }
    },
    {
      "step": "Step 2",
      "description": "KBAC Policy which rules that a Person node can drive a car if the Person node has a relation DRIVES with a Car node.",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "2.0-kbac"
        },
        "subject": {
          "type": "Person"
        },
        "actions": [
          "CAN_DRIVE"
        ],
        "resource": {
          "type": "Car"
        },
        "condition": {
          "cypher": "MATCH (subject:Person)-[:DRIVES]->(resource:Car)"
        }
      }
    },
    {
      "description": "Request to create the KBAC Policy configuration using REST.",
      "filename": "POST https://eu.api.indykite.com/configs/v1/authorization-policies",
      "language": "Json",
      "ingest": {
        "project_id": "your_project_gid",
        "description": "description of policy",
        "display_name": "policy name",
        "name": "policy-name",
        "policy": "{\"meta\":{\"policy_version\":\"2.0-kbac\"},\"subject\":{\"type\":\"Person\"},\"actions\":[\"CAN_DRIVE\"],\"resource\":{\"type\":\"Car\"},\"condition\":{\"cypher\":\"MATCH (subject:Person)-[:DRIVES]->(resource:Car)\"}}",
        "status": "ACTIVE",
        "tags": []
      }
    },
    {
      "description": "Request to create the KBAC Policy configuration using Python.",
      "filename": "policy_request.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\npayload = \"{\"description\": \"\",\n  \"display_name\": \"\",\n  \"name\": \"\",\n  \"policy\": \"\",\n  \"project_id\": \"\",\n  \"status\": \"ACTIVE\",\n  \"tags\": [\n    \"\"\n  ]}\"\nheaders = {\n    'Content-Type': \"application/json\",\n    'Authorization': \"YOUR_SECRET_TOKEN\"\n}\n\nconn.request(\"POST\", \"/configs/v1/authorization-policies\", payload, headers)\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "description": "Request to read the KBAC Policy configuration using REST.",
      "filename": "GET https://eu.api.indykite.com/configs/v1/authorization-policies/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    },
    {
      "description": "Request to read the KBAC Policy configuration using Python.",
      "filename": "policy_request.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\nheaders = { 'Authorization': \"YOUR_SECRET_TOKEN\" }\nconn.request(\"GET\", \"/configs/v1/authorization-policies/{{id}}\", headers=headers)\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "step": "Step 3",
      "description": "Request to run a KBAC authZEN Evaluation - authorized.",
      "filename": "POST https://eu.api.indykite.com/access/v1/evaluation",
      "language": "Json",
      "ingest": {
        "subject": {
          "type": "Person",
          "id": "knightrider"
        },
        "resource": {
          "type": "Car",
          "id": "kitt"
        },
        "action": {
          "name": "CAN_DRIVE"
        }
      }
    },
    {
      "description": "Response to the KBAC authZEN Evaluation - authorized.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "decision": true
      }
    },
    {
      "description": "Request to run a KBAC authZEN Evaluation - authorized.",
      "filename": "evaluation.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\npayload = \"{\n  \t\"subject\": {\"type\": \"Person\",\n        \"id\": \"knightrider\"}, \n    \"resource\": {\"type\": \"Car\",\n        \"id\": \"kitt\"},\n    \"action\": {\"name\": \"CAN_DRIVE\"}\n}\"\n\nheaders = {\n    'Content-Type': \"application/json\",\n    'X-IK-ClientKey': \"\"\n}\n\nconn.request(\"POST\", \"/access/v1/evaluation\", payload, headers)\n\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "description": "Request to run a KBAC authZEN Evaluation - not authorized.",
      "filename": "POST https://eu.api.indykite.com/access/v1/evaluation",
      "language": "Json",
      "ingest": {
        "subject": {
          "type": "Person",
          "id": "knightrider"
        },
        "resource": {
          "type": "Car",
          "id": "cadillacv16"
        },
        "action": {
          "name": "CAN_DRIVE"
        }
      }
    },
    {
      "description": "Response to the KBAC authZEN Evaluation - not authorized.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "decision": false
      }
    },
    {
      "step": "Step 4",
      "description": "Request to run a KBAC authZEN Action Search.",
      "filename": "POST https://eu.api.indykite.com/access/v1/search/action",
      "language": "Json",
      "ingest": {
        "subject": {
          "type": "Person",
          "id": "knightrider"
        },
        "resource": {
          "type": "Car",
          "id": "kitt"
        }
      }
    },
    {
      "description": "Response to the KBAC authZEN Action Search.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "results": [
          {
            "name": "CAN_DRIVE"
          }
        ]
      }
    },
    {
      "description": "Request to run a KBAC authZEN Action Search using Python.",
      "filename": "action.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\npayload = \"{\n    \"subject\": {\"type\": \"Person\",\n        \"id\": \"knightrider\"}, \n    \"resource\": {\"type\": \"Car\",\n        \"id\": \"kitt\"}\n}\"\n\nheaders = {\n    'Content-Type': \"application/json\",\n    'X-IK-ClientKey': \"\"\n}\n\nconn.request(\"POST\", \"/access/v1/search/action\", payload, headers)\n\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "description": "Request to run a KBAC authZEN Resource Search.",
      "filename": "POST https://eu.api.indykite.com/access/v1/search/resource",
      "language": "Json",
      "ingest": {
        "subject": {
          "type": "Person",
          "id": "knightrider"
        },
        "resource": {
          "type": "Car"
        },
        "action": {
          "name": "CAN_DRIVE"
        }
      }
    },
    {
      "description": "Response to the KBAC authZEN Resource Search.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "results": [
          {
            "type": "Car",
            "id": "kitt"
          }
        ]
      }
    },
    {
      "description": "Request to run a KBAC authZEN Resource Search using Python.",
      "filename": "resource.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\npayload = \"{\n    \"subject\": {\"type\": \"Person\",\n        \"id\": \"knightrider\"},\n    \"resource\": {\"type\": \"Car\"},\n    \"action\": {\"name\": \"CAN_DRIVE\"}\n}\"\n\nheaders = {\n    'Content-Type': \"application/json\",\n    'X-IK-ClientKey': \"\"\n}\n\nconn.request(\"POST\", \"/access/v1/search/resource\", payload, headers)\n\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "description": "Request to run a KBAC authZEN Subject Search.",
      "filename": "POST https://eu.api.indykite.com/access/v1/search/subject",
      "language": "Json",
      "ingest": {
        "subject": {
          "type": "Person"
        },
        "resource": {
          "type": "Car",
          "id": "kitt"
        },
        "action": {
          "name": "CAN_DRIVE"
        }
      }
    },
    {
      "description": "Response to the KBAC authZEN Subject Search.",
      "filename": "Response 200",
      "language": "Json",
      "ingest": {
        "results": [
          {
            "type": "Person",
            "id": "knightrider"
          }
        ]
      }
    },
    {
      "description": "Request to run a KBAC authZEN Subject Search using Python.",
      "filename": "subject.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\npayload = \"{\n    \"subject\": {\"type\": \"Person\"},\n    \"resource\": {\"type\": \"Car\",\n        \"id\": \"kitt\"},\n    \"action\": {\"name\": \"CAN_DRIVE\"}\n}\"\n\nheaders = {\n    'Content-Type': \"application/json\",\n    'X-IK-ClientKey': \"\"\n}\n\nconn.request(\"POST\", \"/access/v1/search/subject\", payload, headers)\n\nres = conn.getresponse()\ndata = res.read()\n"
    },
    {
      "step": "Step 5",
      "description": "Delete the KBAC Policy.",
      "filename": "DELETE https://eu.api.indykite.com/configs/v1/authorization-policies/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    },
    {
      "description": "Request to delete the KBAC Policy.",
      "filename": "del.py",
      "language": "Python",
      "code": "\nimport http.client\n\nconn = http.client.HTTPSConnection(\"eu.api.indykite.com\")\n\nheaders = { 'Authorization': \"Bearer ...\", 'Content-Type': \"application/json\" }\n\nconn.request(\"DELETE\", \"/configs/v1/authorization-policies/{id}\", headers=headers)\n\nres = conn.getresponse()\ndata = res.read()\n"
    }
  ],
  "links": {
    "html": "/resources/authz-1",
    "markdown": "/resources/authz-1.md",
    "openApi": "https://openapi.indykite.com/"
  }
}