# Transaction tokens in a call chain: three local services, one token

> Three local services pass one transaction token along a call chain. I logged what payments and the ledger accepted, refused, and why, with real results.

- URL: https://iamops.dev/transaction-token-call-chain-lab/
- Language: en
- Author: Argo
- Published: 2026-11-30
- Category: Labs
- Depth: Practitioner
- Audience: Engineers and operators
- Time: 10 min
- Topics: transaction tokens, AI agents, delegation, Labs

## TL;DR

- The [ledger recorded alice](https://iamops.dev/transaction-token-call-chain-lab/#step-3-a-transaction-token-reaches-the-ledger) as the requester, because the token reached it through payments.
- Without a purpose claim, [payments refused](https://iamops.dev/transaction-token-call-chain-lab/#step-4-without-a-purpose-claim) the request, but the ledger accepted the same token when called directly.
- A changed amount was refused at [both services](https://iamops.dev/transaction-token-call-chain-lab/#step-5-a-changed-amount-is-refused), and a token for payments only was [refused by the ledger](https://iamops.dev/transaction-token-call-chain-lab/#step-6-a-token-for-payments-only).
- The [limits](https://iamops.dev/transaction-token-call-chain-lab/#what-this-does-not-cover) are one shared secret, no user sign-in, and claim names that are this lab's own.

**Audience: Practitioners.** Developers and identity engineers who want to see what each service in a call chain checks. Skip the setup if you only want the result.

A transaction token carries the requester, the purpose and the invoice through a chain of service calls. In this run the ledger recorded alice, because the token reached it through payments. The purpose check lived only in payments. When the token had no purpose, payments refused it, but the ledger accepted the same token when I called it directly. A changed amount was refused at both hops, and a token issued for payments only was refused by the ledger.

The transaction tokens explainer covers the idea. This lab builds a small version of the chain and sends real requests through it.

## Setup and start

You need Python 3 with no extra packages, plus curl, jq and openssl. The three services listen on 127.0.0.1, ports 4701 to 4703. Nothing needs an account or a real tenant, and nothing leaves your computer after the download.

The services are one Python file, [chain_service.py](https://iamops-dev.github.io/lab-files/transaction-token-call-chain-lab/chain_service.py). Each role runs as its own process, and all three read the same key file.

```bash
mkdir -p txn-lab && cd txn-lab
curl -s -O https://iamops-dev.github.io/lab-files/transaction-token-call-chain-lab/chain_service.py
mkdir -p run
openssl rand -hex 32 > key.hex && chmod 600 key.hex
export ISSUER=http://127.0.0.1:4701 PAYMENTS=http://127.0.0.1:4702 LEDGER=http://127.0.0.1:4703
python3 -I chain_service.py --role ledger --port 4703 --key-file key.hex --log run/ledger.log &
python3 -I chain_service.py --role payments --port 4702 --key-file key.hex --downstream "$LEDGER" --log run/payments.log &
python3 -I chain_service.py --role issuer --port 4701 --key-file key.hex --log run/issuer.log &
```

A health check confirms that each service answers before any token is sent.

```bash
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$PAYMENTS/healthz" | jq -c .
curl -s "$LEDGER/healthz" | jq -c .
cat run/*.out
```

![Terminal output: three health checks return ok for issuer, payments and ledger, then the three listening lines](https://iamops.dev/media/transaction-token-call-chain-lab/01-services.webp)

*Step 1. The three services answer their health check.*

## Step 2: A plain service token stops at the ledger

The agent asks the issuer for a service token. The token names one workload, agent-1, and no user. The agent sends it to payments with a request for invoice 1042.

```bash
PLAIN=$(curl -s -X POST "$ISSUER/token/service" -d 'sub=agent-1' | jq -r .token)
echo "$PLAIN" | jq -Rr 'split(".") | .[1] | gsub("-";"+") | gsub("_";"/") | . + "==" | @base64d | fromjson'
curl -s -w '\nHTTP %{http_code}\n' -X POST "$PAYMENTS/pay" -H "Authorization: Bearer $PLAIN" \
  -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
tail -n 1 run/payments.log | jq -c '{role, decision, status, actor, requester, own_checks, downstream_status}'
tail -n 1 run/ledger.log | jq -c '{role, decision, status, actor, requester, reason}'
```

![Terminal output: the service token claims with sub agent-1, then payments refuses with 403 no requester, and both logs show the refusal](https://iamops.dev/media/transaction-token-call-chain-lab/02-plain-token.webp)

*Step 2. A service token with no user. Payments passes its own checks, and the ledger refuses.*

Payments checks the signature, the issuer and the audience, then passes the call on. The ledger refuses it because nothing in the token names a requester. The payments log shows its own checks passed, and the ledger log shows the refusal.

## Step 3: A transaction token reaches the ledger

The issuer mints a transaction token for alice. The token names the requester, the acting workload, the purpose, the invoice and the amount. Payments checks the purpose and the request body, then passes the same token to the ledger, which records alice.

```bash
TXN=$(curl -s -X POST "$ISSUER/token/transaction" -d 'requester=alice' -d 'actor=agent-1' \
  -d 'purpose=pay_invoice' -d 'invoice=1042' -d 'amount=120.00' | jq -r .token)
echo "$TXN" | jq -Rr 'split(".") | .[1] | gsub("-";"+") | gsub("_";"/") | . + "==" | @base64d | fromjson'
curl -s -w '\nHTTP %{http_code}\n' -X POST "$PAYMENTS/pay" -H "Authorization: Bearer $TXN" \
  -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
tail -n 1 run/payments.log | jq -c '{role, decision, status, actor, requester, purpose, txn, own_checks, downstream_status}'
tail -n 1 run/ledger.log | jq -c '{role, decision, status, actor, requester, purpose, txn, aud: .claims.aud, result: .decision}'
```

![Terminal output: the transaction token claims with requester alice and purpose pay_invoice, payments returns paid with HTTP 200, and both logs show the same txn value](https://iamops.dev/media/transaction-token-call-chain-lab/03-transaction-token.webp)

*Step 3. One transaction token, two accepted hops. The same txn value appears in both logs.*

The same txn value appears in both logs. That is the token at each hop.

## Step 4: Without a purpose claim

This time the token has no purpose claim. Payments refuses it with insufficient_purpose. Then I sent the same token straight to the ledger, and the ledger recorded the entry. In this lab only payments checks the purpose, so a caller that reaches the ledger directly gets past that check.

```bash
TXN=$(curl -s -X POST "$ISSUER/token/transaction" -d 'requester=alice' -d 'actor=agent-1' \
  -d 'invoice=1042' -d 'amount=120.00' | jq -r .token)
curl -s -w '\nHTTP %{http_code}\n' -X POST "$PAYMENTS/pay" -H "Authorization: Bearer $TXN" \
  -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
curl -s -w '\nHTTP %{http_code}\n' -X POST "$LEDGER/entries" -H "Authorization: Bearer $TXN" \
  -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
tail -n 1 run/payments.log
tail -n 1 run/ledger.log
```

![Terminal output: payments refuses the token with insufficient_purpose and 403, the ledger records the entry with 201 for alice](https://iamops.dev/media/transaction-token-call-chain-lab/04-missing-purpose.webp)

*Step 4. Payments refuses the token without a purpose. The ledger, called directly, accepts it.*

## Step 5: A changed amount is refused

The token says 120.00. I changed the request body to 1200.00. Payments refused it, and the ledger refused it too when I called it directly. Both returned request_mismatch, so each service compares the body with the token.

```bash
curl -s -w '\nHTTP %{http_code}\n' -X POST "$PAYMENTS/pay" -H "Authorization: Bearer $TXN" \
  -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"1200.00"}'
curl -s -w '\nHTTP %{http_code}\n' -X POST "$LEDGER/entries" -H "Authorization: Bearer $TXN" \
  -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"1200.00"}'
```

![Terminal output: payments and the ledger each refuse the request with request_mismatch and HTTP 403 when the amount is 1200.00](https://iamops.dev/media/transaction-token-call-chain-lab/05-tampered-amount.webp)

*Step 5. The amount in the body differs from the token, so both services refuse it.*

## Step 6: A token for payments only

I issued a transaction token with the audience set to payments only, then sent it to the ledger. The ledger refused it with invalid_token, because the token audience is payments, not ledger.

```bash
TXN=$(curl -s -X POST "$ISSUER/token/transaction" -d 'requester=alice' -d 'actor=agent-1' \
  -d 'purpose=pay_invoice' -d 'invoice=1042' -d 'amount=120.00' -d 'aud=payments' | jq -r .token)
curl -s -w '\nHTTP %{http_code}\n' -X POST "$LEDGER/entries" -H "Authorization: Bearer $TXN" \
  -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
```

![Terminal output: the audience claim is payments only, and the ledger refuses the token with invalid_token and HTTP 401](https://iamops.dev/media/transaction-token-call-chain-lab/06-wrong-audience.webp)

*Step 6. The ledger refuses a token whose audience is payments.*

## Step 7: A token that expires

A token with a one-second lifetime was refused after two seconds with token expired.

```bash
TXN=$(curl -s -X POST "$ISSUER/token/transaction" -d 'requester=alice' -d 'actor=agent-1' \
  -d 'purpose=pay_invoice' -d 'invoice=1042' -d 'amount=120.00' -d 'ttl=1' | jq -r .token)
sleep 2
curl -s -w '\nHTTP %{http_code}\n' -X POST "$PAYMENTS/pay" -H "Authorization: Bearer $TXN" \
  -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
```

![Terminal output: the token lifetime is one second, and payments refuses the token after two seconds with invalid_token and token expired](https://iamops.dev/media/transaction-token-call-chain-lab/07-expired.webp)

*Step 7. A one-second token, presented two seconds later.*

## Step 8: What the logs count

Each service writes one log line per decision, with the claims it read. This run issued six tokens. Payments logged five requests, one accepted and four refused. The ledger logged five, two accepted and three refused. Some requests went straight to the ledger, so the ledger logged requests that payments never saw.

```bash
cat run/payments.log run/ledger.log | jq -sc 'group_by([.role, .decision]) | map({role: .[0].role, decision: .[0].decision, count: length})'
```

![Terminal output: JSON counts by service and decision, ledger accept 2 and reject 3, payments accept 1 and reject 4](https://iamops.dev/media/transaction-token-call-chain-lab/08-decisions.webp)

*Step 8. Accepted and refused requests, counted by service.*

## What this does not cover

- The issuer takes the requester name from the request form. No user signs in, so alice is a label. A real deployment checks the sign-in before it mints a token.
- One shared secret signs and checks every token, so any service that holds it can also mint one. Real deployments use asymmetric keys that the issuer publishes.
- The claim names (requester, actor, purpose, txn) are this lab's names. Compare them with the <abbr title="Internet Engineering Task Force">IETF</abbr> draft before you reuse them in a real system.
- Payments forwards the same token to the ledger. Exchanging the token at each hop is a different design, and this lab does not test it.
- No agent platform runs here. The lab tests the checks in the services, not an agent.

## Cleanup

Stop the services, delete the key and the copied service file, and check that no process and no listener is left.

```bash
pkill -f chain_service.py
rm -f key.hex chain_service.py run/*.log run/*.out run/pids && rm -rf __pycache__
pgrep -fl chain_service.py || echo "no chain_service.py process left"
lsof -nP -iTCP:4701-4703 -sTCP:LISTEN || echo "no listener on 4701-4703"
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:4701/healthz
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:4702/healthz
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:4703/healthz
find . -name key.hex -o -name '*.jwt' -o -name chain_service.py -o -name '*.log' | grep -v /raw/ || echo none
```

![Terminal output: cleanup removes the key and logs, then the checks report no process, no listener on ports 4701 to 4703, HTTP 000 three times, and none left](https://iamops.dev/media/transaction-token-call-chain-lab/09-cleanup.webp)

*Cleanup. No process and no listener is left, and no key or token file is left in the folder.*

The run was on 30 November 2026, on a Mac, with the services on localhost only. Timestamps and the txn values change on every run.

## Repeat this lab

You need Python 3 (no extra packages), curl, jq and openssl. Everything runs on your own computer on ports 4701 to 4703, with no account and no internet access after the download. Plan for about 10 minutes.

Every value in angle brackets is a placeholder for your own test environment. Nothing on this page is a real identifier or secret.

**Set your variables once** `env.sh` (bash)

```bash
export ISSUER=http://127.0.0.1:4701 PAYMENTS=http://127.0.0.1:4702 LEDGER=http://127.0.0.1:4703
```

### Step 1: Download the service and make a key

**Goal.** Create a work folder, download the one service file and make a fresh 32-byte key that only you can read.

**Prerequisites**

- Python 3, curl, jq and openssl

`setup.sh` (bash)

```bash
mkdir -p txn-lab && cd txn-lab
curl -s -O https://iamops-dev.github.io/lab-files/transaction-token-call-chain-lab/chain_service.py
mkdir -p run
openssl rand -hex 32 > key.hex && chmod 600 key.hex
```

**Expected output**

```text
(no output)
```

### Step 2: Start the ledger, payments and issuer

**Goal.** Start the three services on 127.0.0.1. Payments calls the ledger, so the ledger starts first.

**Prerequisites**

- The setup step has completed
- Ports 4701, 4702 and 4703 are free

`start.sh` (bash)

```bash
python3 -I chain_service.py --role ledger --port 4703 --key-file key.hex --log run/ledger.log &
python3 -I chain_service.py --role payments --port 4702 --key-file key.hex --downstream "$LEDGER" --log run/payments.log &
python3 -I chain_service.py --role issuer --port 4701 --key-file key.hex --log run/issuer.log &
sleep 1
```

**Expected output**

```text
ledger listening on 127.0.0.1:4703
payments listening on 127.0.0.1:4702
issuer listening on 127.0.0.1:4701
```

### Step 3: Check the three health endpoints

**Goal.** Confirm each service answers before you send any token.

**Prerequisites**

- The start step has completed

`health.sh` (bash)

```bash
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$PAYMENTS/healthz" | jq -c .
curl -s "$LEDGER/healthz" | jq -c .
```

**Expected output**

```text
{"role":"issuer","ok":true}
{"role":"payments","ok":true}
{"role":"ledger","ok":true}
```

### Step 4: A plain service token stops at the ledger

**Goal.** Send the agent's own token to payments. Payments passes its own checks, the ledger refuses because no user is in the token.

**Prerequisites**

- The health step has completed

`plain-token.sh` (bash)

```bash
PLAIN=$(curl -s -X POST "$ISSUER/token/service" -d 'sub=agent-1' | jq -r .token)
echo "$PLAIN" | jq -Rr 'split(".") | .[1] | gsub("-";"+") | gsub("_";"/") | . + "==" | @base64d | fromjson'
curl -s -w '\nHTTP %{http_code}\n' -X POST "$PAYMENTS/pay" -H "Authorization: Bearer $PLAIN" -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
tail -n 1 run/payments.log | jq -c '{role, decision, status, actor, requester, own_checks, downstream_status}'
tail -n 1 run/ledger.log | jq -c '{role, decision, status, actor, requester, reason}'
```

**Expected output**

```text
{
  "aud": [
    "payments",
    "ledger"
  ],
  "exp": 1796072679,
  "iat": 1796072379,
  "iss": "chain-lab-issuer",
  "sub": "agent-1"
}
{
  "error": "no_requester",
  "reason": "token has no requester claim, so no user is recorded"
}
HTTP 403
{"role":"payments","decision":"reject","status":403,"actor":"agent-1","requester":null,"own_checks":"pass","downstream_status":403}
{"role":"ledger","decision":"reject","status":403,"actor":"agent-1","requester":null,"reason":"token has no requester claim, so no user is recorded"}
```

### Step 5: A transaction token reaches the ledger through payments

**Goal.** Mint a token that names alice as requester and carries the purpose, then send it to payments. Payments passes the same token to the ledger.

**Prerequisites**

- The health step has completed

`transaction-token.sh` (bash)

```bash
TXN=$(curl -s -X POST "$ISSUER/token/transaction" -d 'requester=alice' -d 'actor=agent-1' -d 'purpose=pay_invoice' -d 'invoice=1042' -d 'amount=120.00' | jq -r .token)
echo "$TXN" | jq -Rr 'split(".") | .[1] | gsub("-";"+") | gsub("_";"/") | . + "==" | @base64d | fromjson'
curl -s -w '\nHTTP %{http_code}\n' -X POST "$PAYMENTS/pay" -H "Authorization: Bearer $TXN" -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
tail -n 1 run/payments.log | jq -c '{role, decision, status, actor, requester, purpose, txn, own_checks, downstream_status}'
tail -n 1 run/ledger.log | jq -c '{role, decision, status, actor, requester, purpose, txn, aud: .claims.aud, result: .decision}'
```

**Expected output**

```text
{
  "actor": "agent-1",
  "amount": "120.00",
  "aud": [
    "payments",
    "ledger"
  ],
  "exp": 1796072681,
  "iat": 1796072381,
  "invoice": "1042",
  "iss": "chain-lab-issuer",
  "purpose": "pay_invoice",
  "requester": "alice",
  "txn": "1c68d6b87787107f"
}
{
  "result": "paid",
  "actor": "agent-1",
  "ledger": {
    "result": "recorded",
    "requester": "alice",
    "invoice": "1042"
  }
}
HTTP 200
{"role":"payments","decision":"accept","status":200,"actor":"agent-1","requester":"alice","purpose":"pay_invoice","txn":"1c68d6b87787107f","own_checks":"pass","downstream_status":201}
{"role":"ledger","decision":"accept","status":201,"actor":"agent-1","requester":"alice","purpose":"pay_invoice","txn":"1c68d6b87787107f","aud":["payments","ledger"],"result":"accept"}
```

### Step 6: Without a purpose claim

**Goal.** Send the same kind of token without purpose. Payments refuses it. The ledger, called directly, accepts it.

**Prerequisites**

- The health step has completed

`missing-purpose.sh` (bash)

```bash
TXN=$(curl -s -X POST "$ISSUER/token/transaction" -d 'requester=alice' -d 'actor=agent-1' -d 'invoice=1042' -d 'amount=120.00' | jq -r .token)
curl -s -w '\nHTTP %{http_code}\n' -X POST "$PAYMENTS/pay" -H "Authorization: Bearer $TXN" -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
curl -s -w '\nHTTP %{http_code}\n' -X POST "$LEDGER/entries" -H "Authorization: Bearer $TXN" -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
```

**Expected output**

```text
{
  "error": "insufficient_purpose",
  "reason": "purpose claim missing"
}
HTTP 403
{
  "result": "recorded",
  "requester": "alice",
  "invoice": "1042"
}
HTTP 201
```

### Step 7: A changed amount is refused

**Goal.** Keep the token at 120.00 and send 1200.00 in the body. Both services refuse it.

**Prerequisites**

- The health step has completed

`tampered-amount.sh` (bash)

```bash
TXN=$(curl -s -X POST "$ISSUER/token/transaction" -d 'requester=alice' -d 'actor=agent-1' -d 'purpose=pay_invoice' -d 'invoice=1042' -d 'amount=120.00' | jq -r .token)
curl -s -w '\nHTTP %{http_code}\n' -X POST "$PAYMENTS/pay" -H "Authorization: Bearer $TXN" -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"1200.00"}'
curl -s -w '\nHTTP %{http_code}\n' -X POST "$LEDGER/entries" -H "Authorization: Bearer $TXN" -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"1200.00"}'
```

**Expected output**

```text
{
  "error": "request_mismatch",
  "reason": "invoice or amount differs from the token"
}
HTTP 403
{
  "error": "request_mismatch",
  "reason": "invoice or amount differs from the token"
}
HTTP 403
```

### Step 8: A token for payments only is refused by the ledger

**Goal.** Mint a token with the audience set to payments, then send it to the ledger.

**Prerequisites**

- The health step has completed

`wrong-audience.sh` (bash)

```bash
TXN=$(curl -s -X POST "$ISSUER/token/transaction" -d 'requester=alice' -d 'actor=agent-1' -d 'purpose=pay_invoice' -d 'invoice=1042' -d 'amount=120.00' -d 'aud=payments' | jq -r .token)
curl -s -w '\nHTTP %{http_code}\n' -X POST "$LEDGER/entries" -H "Authorization: Bearer $TXN" -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
```

**Expected output**

```text
{
  "error": "invalid_token",
  "reason": "token audience is payments, not ledger"
}
HTTP 401
```

### Step 9: A one-second token is refused after two seconds

**Goal.** Mint a token that lives one second, wait two seconds, then send it to payments.

**Prerequisites**

- The health step has completed

`expired.sh` (bash)

```bash
TXN=$(curl -s -X POST "$ISSUER/token/transaction" -d 'requester=alice' -d 'actor=agent-1' -d 'purpose=pay_invoice' -d 'invoice=1042' -d 'amount=120.00' -d 'ttl=1' | jq -r .token)
sleep 2
curl -s -w '\nHTTP %{http_code}\n' -X POST "$PAYMENTS/pay" -H "Authorization: Bearer $TXN" -H 'Content-Type: application/json' -d '{"invoice":"1042","amount":"120.00"}'
```

**Expected output**

```text
{
  "error": "invalid_token",
  "reason": "token expired"
}
HTTP 401
```

### Step 10: Clean up

**Goal.** Stop the three services, delete the key and the work folder, and check that nothing listens on the three ports.

**Prerequisites**

- The earlier steps have completed

`cleanup.sh` (bash)

```bash
pkill -f chain_service.py
cd .. && rm -rf txn-lab
lsof -nP -iTCP:4701-4703 -sTCP:LISTEN || echo "no listener on 4701-4703"
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:4701/healthz
```

**Expected output**

```text
no listener on 4701-4703
000
```


## Sources

- [SPIFFE standard roadmap, August 2026](https://spiffe.io/blog/2026-08-18-spiffe-standard-roadmap/)
- [IETF draft: OAuth transaction tokens](https://datatracker.ietf.org/doc/draft-ietf-oauth-transaction-tokens/11/)

Discuss: [X](https://x.com/iamopsdev) | [LinkedIn](https://www.linkedin.com/company/iamops-dev/)
