{
  "id": "ciq-13",
  "title": "ContX IQ: How do I require step-up authentication based on the token issue time (iat claim)?",
  "description": "Enforce token freshness by checking the iat (issued at) claim. If the token was issued more than one hour ago, return an advice requesting a new token. Different from auth_time - this checks token age, not authentication age.",
  "category": "ContX IQ",
  "tags": [
    "ContX IQ Policy",
    "ContX IQ Query",
    "Step-Up Authentication",
    "iat Claim",
    "Token Freshness",
    "Security",
    "Advice"
  ],
  "api": "ContX IQ",
  "language": "Json",
  "lastUpdated": "2026-03-20",
  "openApiEndpoints": [
    "/capture/v1/nodes",
    "/capture/v1/relationships",
    "/configs/v1/authorization-policies",
    "/configs/v1/knowledge-queries",
    "/contx-iq/v1/execute"
  ],
  "relatedGuides": [
    "/guides/guide-contx-iq",
    "/guides/guide-sandbox"
  ],
  "commonErrors": [
    {
      "code": "401",
      "message": "UNAUTHENTICATED",
      "solution": "Check credentials: ServiceAccount Bearer token for config APIs, X-IK-ClientKey for execution"
    },
    {
      "code": "404",
      "message": "NOT_FOUND",
      "solution": "Verify the query/policy ID exists and belongs to your project"
    }
  ],
  "summary": "This example enforces token freshness using the iat (issued at) JWT claim:\n\nWhat is iat?\nThe iat claim indicates when the token was issued/created.\nUpdated on every token refresh (unlike auth_time which tracks actual authentication).\n\nDifference from auth_time (ciq-12):\n- iat: When was this specific token created?\n- auth_time: When did the user last enter their credentials?\n\nPolicy logic:\n- Calculate token age: now() - iat\n- If > 1 hour: Return advice \"Get a fresh token\"\n- If <= 1 hour: Allow the operation\n\nUse case: Ensure tokens are recent, preventing use of old/potentially compromised tokens.",
  "usecase": "Scenario: API requires tokens issued within the last hour for all operations.\n\nToken claims:\n- iat: 2024-01-15T09:00:00Z (when token was created)\n- Current time: 2024-01-15T10:30:00Z\n- Token age: 1.5 hours (exceeds 1 hour limit)\n\nRequest flow:\n1. User makes request with valid but old token\n2. Policy checks: iat > 1 hour ago?\n3. Response: {decision: false, advice: {action: \"refresh_token\", reason: \"token_too_old\"}}\n4. Application uses refresh token to get new access token (new iat)\n5. Same request now succeeds with fresh token\n\nCompare with ciq-12:\n- ciq-12 (auth_time): User must re-enter password\n- ciq-13 (iat): Application can silently refresh token\n\nUse iat for: General token freshness\nUse auth_time for: Sensitive operations requiring active user presence",
  "requirements": "Prerequisites:\n- ServiceAccount credentials: For creating policies and queries (Bearer token)\n- AppAgent credentials: For data ingestion and query execution (X-IK-ClientKey)\n- User access token: JWT with iat claim (standard JWT claim)\n- Token Introspect configuration: Extracts iat claim automatically\n\nJWT iat claim:\n- Standard JWT claim present in virtually all tokens\n- Updates every time a new token is issued (including refreshes)\n- Different from auth_time which only updates on actual authentication",
  "steps": "Step 1: Ingest Graph Data\n- Authentication: AppAgent credential (X-IK-ClientKey header)\n- Action: POST Person, PaymentMethod, Company nodes and relationships\n- Result: Graph ready for operations\n\nStep 2: Create Policy with iat Freshness Check\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST policy with conditions:\n  - Calculate token age from iat claim\n  - If token age > 3600 seconds (1 hour): Return refresh advice\n  - If token age <= 3600 seconds: Allow operation\n- Result: Policy ID returned\n\nStep 3: Create Query with Token Freshness Requirement\n- Authentication: ServiceAccount credential (Bearer token)\n- Action: POST query that will check token freshness before executing\n- Result: Query ID returned\n\nStep 4: Execute with Old Token\n- Authentication: AppAgent credential + User token (with old iat)\n- Action: POST to /contx-iq/v1/execute\n- Result if iat too old: {decision: false, advice: {refresh_token: true}}\n- Result if iat recent: Operation succeeds",
  "graph": {
    "caption": "The graph the example runs on: 11 nodes (2 Person, 2 PaymentMethod, 2 Contract, 2 Vehicle, 2 LicenseNumber, 1 Company) and 10 relationships (HAS, ACCEPTED, COVERS, OFFERS). 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": "bob",
        "type": "Person",
        "is_identity": true,
        "properties": [
          {
            "type": "email",
            "value": "bob@email.com"
          },
          {
            "type": "given_name",
            "value": "Bob"
          }
        ]
      },
      {
        "external_id": "cb123",
        "type": "PaymentMethod",
        "is_identity": false,
        "properties": [
          {
            "type": "payment_name",
            "value": "Credit Card"
          }
        ]
      },
      {
        "external_id": "kl123",
        "type": "PaymentMethod",
        "is_identity": false,
        "properties": [
          {
            "type": "payment_name",
            "value": "Klarna"
          }
        ]
      },
      {
        "external_id": "ct123",
        "type": "Contract",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Parking"
          },
          {
            "type": "status",
            "value": "Active"
          }
        ]
      },
      {
        "external_id": "ct234",
        "type": "Contract",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Parking"
          },
          {
            "type": "status",
            "value": "Active"
          }
        ]
      },
      {
        "external_id": "car1",
        "type": "Vehicle",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Car"
          },
          {
            "type": "is_active",
            "value": true
          },
          {
            "type": "vin",
            "value": "rtfhcnvjt471"
          }
        ]
      },
      {
        "external_id": "car2",
        "type": "Vehicle",
        "is_identity": false,
        "properties": [
          {
            "type": "category",
            "value": "Car"
          },
          {
            "type": "is_active",
            "value": true
          },
          {
            "type": "vin",
            "value": "kdcbfrt178"
          }
        ]
      },
      {
        "external_id": "license1",
        "type": "LicenseNumber",
        "is_identity": false,
        "properties": [
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "number",
            "value": "AX123456"
          }
        ]
      },
      {
        "external_id": "license2",
        "type": "LicenseNumber",
        "is_identity": false,
        "properties": [
          {
            "type": "status",
            "value": "Active"
          },
          {
            "type": "number",
            "value": "OL123456"
          }
        ]
      },
      {
        "external_id": "companyParking",
        "type": "Company",
        "is_identity": false,
        "properties": [
          {
            "type": "name",
            "value": "City Parking Inc"
          }
        ]
      }
    ],
    "relationships": [
      {
        "source": "bob",
        "target": "kl123",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "alice",
        "target": "cb123",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "alice",
        "target": "ct123",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "bob",
        "target": "ct234",
        "type": "ACCEPTED",
        "properties": []
      },
      {
        "source": "ct123",
        "target": "car1",
        "type": "COVERS",
        "properties": []
      },
      {
        "source": "ct234",
        "target": "car2",
        "type": "COVERS",
        "properties": []
      },
      {
        "source": "car1",
        "target": "license1",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "car2",
        "target": "license2",
        "type": "HAS",
        "properties": []
      },
      {
        "source": "companyParking",
        "target": "ct234",
        "type": "OFFERS",
        "properties": []
      },
      {
        "source": "companyParking",
        "target": "ct123",
        "type": "OFFERS",
        "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": "bob",
            "type": "Person",
            "is_identity": true,
            "properties": [
              {
                "type": "email",
                "value": "bob@email.com"
              },
              {
                "type": "given_name",
                "value": "Bob"
              }
            ]
          },
          {
            "external_id": "cb123",
            "type": "PaymentMethod",
            "properties": [
              {
                "type": "payment_name",
                "value": "Credit Card"
              }
            ]
          },
          {
            "external_id": "kl123",
            "type": "PaymentMethod",
            "properties": [
              {
                "type": "payment_name",
                "value": "Klarna"
              }
            ]
          },
          {
            "external_id": "ct123",
            "type": "Contract",
            "properties": [
              {
                "type": "category",
                "value": "Parking"
              },
              {
                "type": "status",
                "value": "Active"
              }
            ]
          },
          {
            "external_id": "ct234",
            "type": "Contract",
            "properties": [
              {
                "type": "category",
                "value": "Parking"
              },
              {
                "type": "status",
                "value": "Active"
              }
            ]
          },
          {
            "external_id": "car1",
            "type": "Vehicle",
            "properties": [
              {
                "type": "category",
                "value": "Car"
              },
              {
                "type": "is_active",
                "value": true
              },
              {
                "type": "vin",
                "value": "rtfhcnvjt471"
              }
            ]
          },
          {
            "external_id": "car2",
            "type": "Vehicle",
            "properties": [
              {
                "type": "category",
                "value": "Car"
              },
              {
                "type": "is_active",
                "value": true
              },
              {
                "type": "vin",
                "value": "kdcbfrt178"
              }
            ]
          },
          {
            "external_id": "license1",
            "type": "LicenseNumber",
            "properties": [
              {
                "type": "status",
                "value": "Active"
              },
              {
                "type": "number",
                "value": "AX123456",
                "metadata": {
                  "assurance_level": 3,
                  "source": "BRREG"
                }
              }
            ]
          },
          {
            "external_id": "license2",
            "type": "LicenseNumber",
            "properties": [
              {
                "type": "status",
                "value": "Active"
              },
              {
                "type": "number",
                "value": "OL123456",
                "metadata": {
                  "assurance_level": 3,
                  "source": "BRREG"
                }
              }
            ]
          },
          {
            "external_id": "companyParking",
            "type": "Company",
            "properties": [
              {
                "type": "name",
                "value": "City Parking Inc"
              }
            ]
          }
        ]
      }
    },
    {
      "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": "bob",
              "type": "Person"
            },
            "target": {
              "external_id": "kl123",
              "type": "PaymentMethod"
            },
            "type": "HAS"
          },
          {
            "source": {
              "external_id": "alice",
              "type": "Person"
            },
            "target": {
              "external_id": "cb123",
              "type": "PaymentMethod"
            },
            "type": "HAS"
          },
          {
            "source": {
              "external_id": "alice",
              "type": "Person"
            },
            "target": {
              "external_id": "ct123",
              "type": "Contract"
            },
            "type": "ACCEPTED"
          },
          {
            "source": {
              "external_id": "bob",
              "type": "Person"
            },
            "target": {
              "external_id": "ct234",
              "type": "Contract"
            },
            "type": "ACCEPTED"
          },
          {
            "source": {
              "external_id": "ct123",
              "type": "Contract"
            },
            "target": {
              "external_id": "car1",
              "type": "Vehicle"
            },
            "type": "COVERS"
          },
          {
            "source": {
              "external_id": "ct234",
              "type": "Contract"
            },
            "target": {
              "external_id": "car2",
              "type": "Vehicle"
            },
            "type": "COVERS"
          },
          {
            "source": {
              "external_id": "car1",
              "type": "Vehicle"
            },
            "target": {
              "external_id": "license1",
              "type": "LicenseNumber"
            },
            "type": "HAS"
          },
          {
            "source": {
              "external_id": "car2",
              "type": "Vehicle"
            },
            "target": {
              "external_id": "license2",
              "type": "LicenseNumber"
            },
            "type": "HAS"
          },
          {
            "source": {
              "external_id": "companyParking",
              "type": "Company"
            },
            "target": {
              "external_id": "ct234",
              "type": "Contract"
            },
            "type": "OFFERS"
          },
          {
            "source": {
              "external_id": "companyParking",
              "type": "Company"
            },
            "target": {
              "external_id": "ct123",
              "type": "Contract"
            },
            "type": "OFFERS"
          }
        ]
      }
    },
    {
      "step": "Step 2",
      "description": "Create a CIQ Policy which designates an advice step up if the access token iat claim is more than an hour ago. ",
      "filename": "policy.json",
      "language": "Json",
      "ingest": {
        "meta": {
          "policy_version": "1.0-ciq"
        },
        "subject": {
          "type": "Person"
        },
        "condition": {
          "cypher": "MATCH (company:Company)-[:OFFERS]->(contract:Contract)<-[:ACCEPTED]-(subject:Person)-[:HAS]->(payment:PaymentMethod), (contract)-[:COVERS]->(vehicle:Vehicle)-[:HAS]->(ln:LicenseNumber)",
          "filter": [
            {
              "attribute": "subject.external_id",
              "operator": "=",
              "value": "$token.sub"
            }
          ],
          "token_filter": {
            "operator": ">=",
            "attribute": "$token.iat",
            "value": "$one_hour_ago",
            "advice": {
              "error": "insufficient_user_authentication",
              "error_description": "More recent authentication is required, token > 1 hour ago"
            }
          }
        },
        "allowed_reads": {
          "nodes": [
            "company.*",
            "subject.*",
            "payment.*"
          ]
        }
      }
    },
    {
      "description": "Request to create the CIQ 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\":\"1.0-ciq\"},\"subject\":{\"type\":\"Person\"},\"condition\":{\"cypher\":\"MATCH (company:Company)-[:OFFERS]->(contract:Contract)<-[:ACCEPTED]-(subject:Person)-[:HAS]->(payment:PaymentMethod), (contract)-[:COVERS]->(vehicle:Vehicle)-[:HAS]->(ln:LicenseNumber)\",\"filter\":[{\"attribute\":\"subject.external_id\",\"operator\":\"=\",\"value\":\"$token.sub\"}],\"token_filter\":{\"operator\":\">=\",\"attribute\":\"$token.iat\",\"value\":\"$one_hour_ago\",\"advice\":{\"error\":\"insufficient_user_authentication\",\"error_description\":\"More recent authentication is required, token > 1 hour ago\"}}},\"allowed_reads\":{\"nodes\":[\"company.*\",\"subject.*\",\"payment.*\"]}}",
        "status": "ACTIVE",
        "tags": []
      }
    },
    {
      "description": "Request to read the CIQ Policy configuration using REST.",
      "filename": "policy_request.json",
      "language": "Json",
      "ingest": {
        "id": "your_policy_configuration_gid"
      }
    },
    {
      "step": "Step 3",
      "description": "Create a CIQ Query in the context of the policy to configure the step up advice. ",
      "filename": "knowledge_query.json",
      "language": "Json",
      "ingest": {
        "nodes": [
          "company.external_id",
          "payment.external_id"
        ]
      }
    },
    {
      "description": "Request to create a CIQ Query configuration using REST.",
      "filename": "POST https://eu.api.indykite.com/configs/v1/knowledge-queries",
      "language": "Json",
      "ingest": {
        "project_id": "your_project_gid",
        "description": "description of knowledge query",
        "display_name": "knowledge query name",
        "name": "knowledge-query-name",
        "policy_id": "your_policy_gid",
        "query": "{\"nodes\":[\"company.external_id\",\"payment.external_id\"]}",
        "status": "ACTIVE"
      }
    },
    {
      "description": "Read the CIQ Query Configuration.",
      "filename": "GET https://eu.api.indykite.com/configs/v1/knowledge-queries/{id}",
      "language": "Json",
      "ingest": {
        "id": "your_knowledge_query_configuration_gid"
      }
    },
    {
      "step": "Step 4",
      "description": "Run a CIQ Execution to trigger the step up advice. ",
      "filename": "POST https://eu.api.indykite.com/contx-iq/v1/execute",
      "language": "Json",
      "ingest": {
        "id": "knowledge_query_gid",
        "input_params": {
          "one_hour_ago": 1795610122
        },
        "page_token": 1
      }
    },
    {
      "description": "CIQ Execution response if the iat is too old.",
      "filename": "response.json",
      "language": "Json",
      "ingest": {
        "message": "Unauthorized: invalid token. see response Www-Authenticate headers"
      }
    },
    {
      "description": "CIQ Execution response if the iat is less than an hour ago.",
      "filename": "response.json",
      "language": "Json",
      "ingest": {
        "data": [
          {
            "nodes": {
              "company.external_id": "companyParking",
              "payment.external_id": "cb123"
            }
          }
        ]
      }
    }
  ],
  "links": {
    "html": "/resources/ciq-13",
    "markdown": "/resources/ciq-13.md",
    "openApi": "https://openapi.indykite.com/"
  }
}