TL;DR
- The ledger recorded alice as the requester, because the token reached it through payments.
- Without a purpose claim, payments refused the request, but the ledger accepted the same token when called directly.
- A changed amount was refused at both services, and a token for payments only was refused by the ledger.
- The limits are one shared secret, no user sign-in, and claim names that are this lab's own.
Repeat this lab
I wrote this lab so you can run it yourself. Each step has the commands to copy and the output I got, and you can tick it as done. Your ticks stay in this browser only.
Copies a ready-made prompt for Claude Code, Cursor, Codex or any coding agent. For test environments only.
Show prompt
I want to run a hands-on lab from iamops.dev, and I would like your help to do it safely. Lab: Transaction tokens in a call chain: three local services, one token Read the whole lab here (Markdown): https://iamops.dev/transaction-token-call-chain-lab.md What the lab needs before the first step: - Python 3, curl, jq and openssl How I want you to work: 1. Read the lab from start to finish first (each step lists its own prerequisites). Then check that the prerequisites are in place and that the tool versions match what the lab expects. Tell me what is missing before you run anything. 2. Run one step at a time. Before each command, show it to me and say in a sentence what it does. 3. Ask me before anything that costs money, creates cloud resources, touches a real tenant or account, or deletes anything. Wait for my answer. 4. Use the placeholders from the lab. Never paste real secrets, tokens or production identities into a command, a file or this chat. If a value is needed, tell me where to set it myself. 5. After each step, compare the output with the expected output in the lab. If it does not match, stop and tell me what differs. Do not carry on or invent a fix without asking me. 6. At the end, report what passed, what failed and which cleanup you did. Then offer to tick the steps off for me. The lab page keeps ticks only in my browser, so if you cannot do that, list the steps I should tick. This lab is for test environments only. Do not run it against production, or against a tenant or account that holds real data or real users. You may answer in my language.
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. Each role runs as its own process, and all three read the same key file.
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.
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$PAYMENTS/healthz" | jq -c .
curl -s "$LEDGER/healthz" | jq -c .
cat run/*.out
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.
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}'
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.
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}'
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.
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
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.
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"}'
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.
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"}'
Step 7: A token that expires#
A token with a one-second lifetime was refused after two seconds with token expired.
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"}'
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.
cat run/payments.log run/ledger.log | jq -sc 'group_by([.role, .decision]) | map({role: .[0].role, decision: .[0].decision, count: length})'
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 IETF 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.
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
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
export ISSUER=http://127.0.0.1:4701 PAYMENTS=http://127.0.0.1:4702 LEDGER=http://127.0.0.1:4703 0 of 10 steps done
Step 1Download 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
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
(no output) Step 2Start 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
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
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 3Check the three health endpoints
Goal. Confirm each service answers before you send any token.
Prerequisites
- The start step has completed
curl -s "$ISSUER/healthz" | jq -c .
curl -s "$PAYMENTS/healthz" | jq -c .
curl -s "$LEDGER/healthz" | jq -c . Expected output
{"role":"issuer","ok":true}
{"role":"payments","ok":true}
{"role":"ledger","ok":true} Step 4A 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=$(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
{
"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 5A 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
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
{
"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 6Without 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
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
{
"error": "insufficient_purpose",
"reason": "purpose claim missing"
}
HTTP 403
{
"result": "recorded",
"requester": "alice",
"invoice": "1042"
}
HTTP 201 Step 7A 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
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
{
"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 8A 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
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
{
"error": "invalid_token",
"reason": "token audience is payments, not ledger"
}
HTTP 401 Step 9A 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
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
{
"error": "invalid_token",
"reason": "token expired"
}
HTTP 401 Step 10Clean 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
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
no listener on 4701-4703
000 Sources#
This post as Markdown · RSS · JSON feed
New posts by email
One email a week with new posts and labs. Unsubscribe anytime.
Your address is stored with Kit, which sends the emails. Details